This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathkeyvault.tf
49 lines (38 loc) · 1.58 KB
/
keyvault.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
47
48
49
resource "azurerm_key_vault" "deployment" {
name = "${local.prefix}-loadgen-kv"
location = azurerm_resource_group.deployment.location
resource_group_name = azurerm_resource_group.deployment.name
enabled_for_disk_encryption = true
tenant_id = data.azurerm_client_config.current.tenant_id
soft_delete_retention_days = 7
purge_protection_enabled = false
sku_name = "standard"
tags = local.default_tags
}
# Give KV secret permissions to the service principal that runs the Terraform apply itself
resource "azurerm_key_vault_access_policy" "devops_pipeline" {
key_vault_id = azurerm_key_vault.deployment.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
secret_permissions = [
"Get", "List", "Delete", "Purge", "Set", "Backup", "Restore", "Recover"
]
}
resource "azurerm_key_vault_access_policy" "function_msi" {
key_vault_id = azurerm_key_vault.deployment.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = azurerm_user_assigned_identity.functions.principal_id
secret_permissions = [
"Get", "List"
]
}
# Set each Function host key as a KV secret named "FUNCTIONKEY-MY-FUNCTION-NAME"
resource "azurerm_key_vault_secret" "functionkeys" {
depends_on = [
azurerm_key_vault_access_policy.devops_pipeline
]
for_each = module.regional_functions
name = "FUNCTIONKEY-${upper(each.value.function_name)}"
value = each.value.function_host_key
key_vault_id = azurerm_key_vault.deployment.id
}