-
Notifications
You must be signed in to change notification settings - Fork 3
/
key_vault_secrets.tf
46 lines (37 loc) · 1.2 KB
/
key_vault_secrets.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
variable "ssh_public_keys" {
description = "List of usernames and public ssh keys. Will be loaded into key vault as secrets to be used by the VM modules."
type = list(object({
username = string
ssh_public_key_file = string
}))
default = []
}
locals {
ssh_public_keys = {
for object in var.ssh_public_keys :
object.username => file(object.ssh_public_key_file)
}
}
resource "random_pet" "example" {}
resource "azurerm_key_vault_secret" "example" {
key_vault_id = azurerm_key_vault.hub.id
depends_on = [azurerm_key_vault_access_policy.service_principal]
name = "pet-example"
content_type = "pet-example"
value = random_pet.example.id
}
resource "azurerm_key_vault_secret" "ssh_pub_key" {
key_vault_id = azurerm_key_vault.hub.id
depends_on = [azurerm_key_vault_access_policy.service_principal]
for_each = local.ssh_public_keys
name = "ssh-pub-key-${each.key}"
value = each.value
content_type = "ssh-pub-key"
}
resource "null_resource" "ssh_pub_key_secrets_available" {
# Any changes to these key vault secrets will trigger a sleep
triggers = local.ssh_public_keys
provisioner "local-exec" {
command = "sleep 10"
}
}