Skip to content

Commit 40b6ba5

Browse files
committed
add kv to terraform sample of aci sample app
1 parent 8bd4d97 commit 40b6ba5

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

samples/aci-blob-storage/python/terraform/deploy.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fi
128128
# Get the output values
129129
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
130130
STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name)
131+
KEY_VAULT_NAME=$(terraform output -raw key_vault_name)
131132
ACR_NAME=$(terraform output -raw acr_name)
132133
ACI_GROUP_NAME=$(terraform output -raw aci_group_name)
133134
FQDN=$(terraform output -raw fqdn)
@@ -138,6 +139,7 @@ echo "Deployment Complete!"
138139
echo "============================================================"
139140
echo "Resource Group: $RESOURCE_GROUP_NAME"
140141
echo "Storage Account: $STORAGE_ACCOUNT_NAME"
142+
echo "Key Vault: $KEY_VAULT_NAME"
141143
echo "ACR: $ACR_NAME"
142144
echo "ACI Container: $ACI_GROUP_NAME"
143145
echo "FQDN: $FQDN"

samples/aci-blob-storage/python/terraform/main.tf

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
locals {
33
resource_group_name = "${var.prefix}-aci-rg"
44
storage_account_name = "${var.prefix}acistorage${var.suffix}"
5+
key_vault_name = "${var.prefix}acikv${var.suffix}"
56
acr_name = "${var.prefix}aciacr${var.suffix}"
67
aci_group_name = "${var.prefix}-aci-planner-${var.suffix}"
78
}
89

10+
# Get the current client configuration (for tenant_id)
11+
data "azurerm_client_config" "current" {}
12+
913
# Create a resource group
1014
resource "azurerm_resource_group" "example" {
1115
name = local.resource_group_name
@@ -37,6 +41,30 @@ resource "azurerm_storage_container" "example" {
3741
container_access_type = "private"
3842
}
3943

44+
# Create Key Vault
45+
resource "azurerm_key_vault" "example" {
46+
name = local.key_vault_name
47+
resource_group_name = azurerm_resource_group.example.name
48+
location = azurerm_resource_group.example.location
49+
tenant_id = data.azurerm_client_config.current.tenant_id
50+
sku_name = "standard"
51+
enable_rbac_authorization = true
52+
tags = var.tags
53+
54+
lifecycle {
55+
ignore_changes = [
56+
tags
57+
]
58+
}
59+
}
60+
61+
# Store the storage connection string in Key Vault
62+
resource "azurerm_key_vault_secret" "storage_conn" {
63+
name = "storage-conn"
64+
value = "DefaultEndpointsProtocol=http;AccountName=${azurerm_storage_account.example.name};AccountKey=${azurerm_storage_account.example.primary_access_key};BlobEndpoint=${azurerm_storage_account.example.primary_blob_endpoint}"
65+
key_vault_id = azurerm_key_vault.example.id
66+
}
67+
4068
# Reference the pre-created ACR (created by deploy.sh before terraform apply)
4169
data "azurerm_container_registry" "example" {
4270
name = local.acr_name
@@ -76,7 +104,7 @@ resource "azurerm_container_group" "example" {
76104
}
77105

78106
secure_environment_variables = {
79-
AZURE_STORAGE_CONNECTION_STRING = "DefaultEndpointsProtocol=http;AccountName=${azurerm_storage_account.example.name};AccountKey=${azurerm_storage_account.example.primary_access_key};BlobEndpoint=${azurerm_storage_account.example.primary_blob_endpoint}"
107+
AZURE_STORAGE_CONNECTION_STRING = azurerm_key_vault_secret.storage_conn.value
80108
}
81109
}
82110

samples/aci-blob-storage/python/terraform/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ output "storage_account_name" {
66
value = azurerm_storage_account.example.name
77
}
88

9+
output "key_vault_name" {
10+
value = azurerm_key_vault.example.name
11+
}
12+
913
output "acr_name" {
1014
value = data.azurerm_container_registry.example.name
1115
}

0 commit comments

Comments
 (0)