Skip to content

Commit 389771d

Browse files
authored
add kv to terraform sample of aci sample app (#70)
* add kv to terraform sample of aci sample app * uncomment * remove funclocal * refactor
1 parent 834326f commit 389771d

5 files changed

Lines changed: 37 additions & 11 deletions

File tree

run-samples.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ set -euo pipefail
1111
# - LocalStack CLI
1212
# - Terraform CLI
1313
# - azlocal & terraform-local (pip install azlocal terraform-local)
14-
# - funclocal (pip install funclocal)
14+
# - Azure Functions Core Tools (func)
1515
# - Azure Functions Core Tools (func)
1616
# - jq & zip (sudo apt-get install jq zip)
1717
# - MSSQL Tools (sqlcmd)
@@ -96,7 +96,6 @@ fi
9696
command -v localstack >/dev/null 2>&1 || { echo >&2 "localstack CLI is required but not installed. Aborting."; exit 1; }
9797
command -v az >/dev/null 2>&1 || { echo >&2 "az CLI is required but not installed. Aborting."; exit 1; }
9898
command -v azlocal >/dev/null 2>&1 || { echo >&2 "azlocal is required but not installed. Run 'pip install azlocal'. Aborting."; exit 1; }
99-
command -v funclocal >/dev/null 2>&1 || { echo >&2 "funclocal is required but not installed. Run 'pip install azlocal'. Aborting."; exit 1; }
10099
#command -v tflocal >/dev/null 2>&1 || { echo >&2 "tflocal is required but not installed. Run 'pip install terraform-local'. Aborting."; exit 1; }
101100
command -v terraform >/dev/null 2>&1 || { echo >&2 "terraform CLI is required but not installed. Aborting."; exit 1; }
102101
command -v func >/dev/null 2>&1 || { echo >&2 "Azure Functions Core Tools (func) is required but not installed. Aborting."; exit 1; }

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fi
119119
# Get the output values
120120
RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name)
121121
STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name)
122+
KEY_VAULT_NAME=$(terraform output -raw key_vault_name)
122123
ACR_NAME=$(terraform output -raw acr_name)
123124
ACI_GROUP_NAME=$(terraform output -raw aci_group_name)
124125
FQDN=$(terraform output -raw fqdn)
@@ -129,6 +130,7 @@ echo "Deployment Complete!"
129130
echo "============================================================"
130131
echo "Resource Group: $RESOURCE_GROUP_NAME"
131132
echo "Storage Account: $STORAGE_ACCOUNT_NAME"
133+
echo "Key Vault: $KEY_VAULT_NAME"
132134
echo "ACR: $ACR_NAME"
133135
echo "ACI Container: $ACI_GROUP_NAME"
134136
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
}

samples/function-app-storage-http/dotnet/scripts/deploy.sh

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,7 @@ ENVIRONMENT=$(az account show --query environmentName --output tsv)
2424
# Change the current directory to the script's directory
2525
cd "$CURRENT_DIR" || exit
2626

27-
# Choose the appropriate CLI based on the environment
28-
if [[ $ENVIRONMENT == "LocalStack" ]]; then
29-
echo "Using funclocal for LocalStack emulator environment."
30-
FUNC="funclocal"
31-
else
32-
echo "Using standard func for AzureCloud environment."
33-
FUNC="func"
34-
fi
27+
FUNC="func"
3528

3629
# Create a resource group
3730
echo "Checking if resource group [$RESOURCE_GROUP_NAME] exists in the subscription [$SUBSCRIPTION_NAME]..."

0 commit comments

Comments
 (0)