22locals {
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 } "
65 acr_name = " ${ var . prefix } aciacr${ var . suffix } "
76 aci_group_name = " ${ var . prefix } -aci-planner-${ var . suffix } "
87}
@@ -38,48 +37,10 @@ resource "azurerm_storage_container" "example" {
3837 container_access_type = " private"
3938}
4039
41- # Create Key Vault
42- resource "azurerm_key_vault" "example" {
43- name = local. key_vault_name
44- resource_group_name = azurerm_resource_group. example . name
45- location = azurerm_resource_group. example . location
46- tenant_id = data. azurerm_client_config . current . tenant_id
47- sku_name = " standard"
48- enable_rbac_authorization = true
49- purge_protection_enabled = false
50- soft_delete_retention_days = 7
51- tags = var. tags
52-
53- lifecycle {
54- ignore_changes = [
55- tags
56- ]
57- }
58- }
59-
60- data "azurerm_client_config" "current" {}
61-
62- # Store the storage connection string in Key Vault
63- resource "azurerm_key_vault_secret" "storage_conn" {
64- name = " storage-conn"
65- 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 } "
66- key_vault_id = azurerm_key_vault. example . id
67- }
68-
69- # Create Container Registry
70- resource "azurerm_container_registry" "example" {
40+ # Reference the pre-created ACR (created by deploy.sh before terraform apply)
41+ data "azurerm_container_registry" "example" {
7142 name = local. acr_name
7243 resource_group_name = azurerm_resource_group. example . name
73- location = azurerm_resource_group. example . location
74- sku = var. acr_sku
75- admin_enabled = true
76- tags = var. tags
77-
78- lifecycle {
79- ignore_changes = [
80- tags
81- ]
82- }
8344}
8445
8546# Create Container Instance
@@ -93,14 +54,14 @@ resource "azurerm_container_group" "example" {
9354 tags = var. tags
9455
9556 image_registry_credential {
96- server = azurerm_container_registry. example . login_server
97- username = azurerm_container_registry. example . admin_username
98- password = azurerm_container_registry. example . admin_password
57+ server = data . azurerm_container_registry . example . login_server
58+ username = data . azurerm_container_registry . example . admin_username
59+ password = data . azurerm_container_registry . example . admin_password
9960 }
10061
10162 container {
10263 name = local. aci_group_name
103- image = " ${ azurerm_container_registry . example . login_server } /${ var . image_name } :${ var . image_tag } "
64+ image = " ${ data . azurerm_container_registry . example . login_server } /${ var . image_name } :${ var . image_tag } "
10465 cpu = var. cpu_cores
10566 memory = var. memory_in_gb
10667
@@ -115,7 +76,7 @@ resource "azurerm_container_group" "example" {
11576 }
11677
11778 secure_environment_variables = {
118- AZURE_STORAGE_CONNECTION_STRING = azurerm_key_vault_secret.storage_conn.value
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 } "
11980 }
12081 }
12182
0 commit comments