Skip to content

Commit dc1a2be

Browse files
Create Key Vault resource instead of referencing existing
Replaces the data source for an existing Key Vault with a resource block to create a new Key Vault. Updates the role assignment to reference the newly created Key Vault resource. This change allows the infrastructure to provision and manage the Key Vault directly.
1 parent 430f317 commit dc1a2be

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

gh-runners/vmss.tf

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,24 @@ data "azurerm_resource_group" "rg" {
66
name = var.resource_group_name
77
}
88

9-
# Reference existing Key Vault
10-
data "azurerm_key_vault" "vmss" {
11-
name = var.keyvault_name
12-
resource_group_name = data.azurerm_resource_group.rg.name
9+
# Create Key Vault
10+
resource "azurerm_key_vault" "vmss" {
11+
name = var.keyvault_name
12+
resource_group_name = data.azurerm_resource_group.rg.name
13+
location = data.azurerm_resource_group.rg.location
14+
tenant_id = data.azurerm_client_config.current.tenant_id
15+
sku_name = "standard"
16+
soft_delete_retention_days = 7
17+
purge_protection_enabled = false
18+
enable_rbac_authorization = true
19+
20+
lifecycle {
21+
ignore_changes = [
22+
contact,
23+
network_acls,
24+
tags
25+
]
26+
}
1327
}
1428

1529
# Reference existing custom image
@@ -109,7 +123,7 @@ resource "azurerm_virtual_machine_scale_set_extension" "vmss" {
109123

110124
# Grant VMSS managed identity access to Key Vault secrets
111125
resource "azurerm_role_assignment" "vmss_kv_secrets_user" {
112-
scope = data.azurerm_key_vault.vmss.id
126+
scope = azurerm_key_vault.vmss.id
113127
role_definition_name = "Key Vault Secrets User"
114128
principal_id = azurerm_windows_virtual_machine_scale_set.vmss.identity[0].principal_id
115129

0 commit comments

Comments
 (0)