From 821f8e9eb843f8253f4160007c63248b7778c27f Mon Sep 17 00:00:00 2001 From: Noah Spannbauer Date: Sun, 17 Aug 2025 20:17:58 -0500 Subject: [PATCH] updating modules --- modules/container_app/container_app.tf | 71 ++++++++++++ modules/container_app/container_app_api.tf | 85 -------------- modules/container_app/container_app_app.tf | 55 --------- modules/container_app/variables.tf | 107 ++++++++++++------ .../client_config.tf | 2 + .../container_app_environment.tf | 4 +- .../resource_group.tf | 3 + .../container_app_environment/variables.tf | 20 ++++ modules/{container_app => dns}/dns.tf | 0 modules/dns/resource_group.tf | 3 + modules/dns/variables.tf | 19 ++++ 11 files changed, 191 insertions(+), 178 deletions(-) create mode 100644 modules/container_app/container_app.tf delete mode 100644 modules/container_app/container_app_api.tf delete mode 100644 modules/container_app/container_app_app.tf create mode 100644 modules/container_app_environment/client_config.tf rename modules/{container_app => container_app_environment}/container_app_environment.tf (84%) create mode 100644 modules/container_app_environment/resource_group.tf create mode 100644 modules/container_app_environment/variables.tf rename modules/{container_app => dns}/dns.tf (100%) create mode 100644 modules/dns/resource_group.tf create mode 100644 modules/dns/variables.tf diff --git a/modules/container_app/container_app.tf b/modules/container_app/container_app.tf new file mode 100644 index 0000000..3bb011d --- /dev/null +++ b/modules/container_app/container_app.tf @@ -0,0 +1,71 @@ +resource "azurerm_container_app" "container_app_app" { + name = var.container_app_name + container_app_environment_id = var.container_app_environment_id + resource_group_name = data.azurerm_resource_group.resource_group.name + revision_mode = "Single" + + registry { + server = var.registry_server_name + username = var.registry_username + password_secret_name = var.registry_password_secret_name + } + + template { + min_replicas = var.template_min_replicas + max_replicas = var.template_max_replicas + + dynamic "init_container" { + for_each = var.init_containers + content { + name = init_container.value["name"] + image = container.value["image"] + cpu = init_container.value["cpu"] + memory = init_container.value["memory"] + } + } + + dynamic "container" { + for_each = var.containers + content { + name = container.value["name"] + image = container.value["image"] + cpu = container.value["cpu"] + memory = container.value["memory"] + } + } + } + + ingress { + allow_insecure_connections = var.ingress_allow_insecure_connections + external_enabled = var.ingress_external_enabled + target_port = var.ingress_target_port + transport = var.ingress_transport + + traffic_weight { + latest_revision = true + percentage = var.traffic_weight_percentage + } + } + + dynamic "secret" { + for_each = var.secrets + content { + name = secret.value["name"] + value = secret.value["value"] + } + } + + lifecycle { + ignore_changes = [ template[0].container[0].image ] + } +} + +resource "azurerm_container_app_custom_domain" "custom_domain" { + count = var.custom_domain_count + name = trimsuffix(trimprefix(azurerm_dns_txt_record.dns_txt_record[0].fqdn, "asuid."), ".") + container_app_id = azurerm_container_app.container_app_app.id + + lifecycle { + ignore_changes = [ certificate_binding_type, container_app_environment_certificate_id ] + } +} \ No newline at end of file diff --git a/modules/container_app/container_app_api.tf b/modules/container_app/container_app_api.tf deleted file mode 100644 index 4eb24d0..0000000 --- a/modules/container_app/container_app_api.tf +++ /dev/null @@ -1,85 +0,0 @@ -resource "azurerm_container_app" "container_app_api" { - name = var.container_app_api_name - container_app_environment_id = azurerm_container_app_environment.container_app_environment.id - resource_group_name = data.azurerm_resource_group.resource_group.name - revision_mode = "Single" - - registry { - server = "index.docker.io" - username = var.docker_io_username - password_secret_name = "docker-io-password" - } - - template { - min_replicas = 0 - max_replicas = 2 - - container { - name = var.container_app_api_container_name - image = var.container_app_api_container_image - cpu = 0.25 - memory = "0.5Gi" - - env { - name = "AZURE_STORAGE_CONNECTION_STRING" - secret_name = "azure-storage-connection-string" - } - - env { - name = "CLIENT_ID" - secret_name = "client-id" - } - - env { - name = "CLIENT_SECRET" - secret_name = "client-secret" - } - - env { - name = "TENANT_ID" - secret_name = "tenant-id" - } - } - } - - ingress { - allow_insecure_connections = false - external_enabled = true - target_port = 3000 - transport = "auto" - - traffic_weight { - latest_revision = true - percentage = 100 - } - } - - secret { - name = "docker-io-password" - value = var.docker_io_password - } - - secret { - name = "azure-storage-connection-string" - value = var.storage_account_primary_connection_string - } - - secret { - name = "client-id" - value = var.client_id - } - - secret { - name = "client-secret" - value = var.client_secret - } - - secret { - name = "tenant-id" - value = var.tenant_id - } - - lifecycle { - ignore_changes = [ template[0].container[0].image ] - } -} \ No newline at end of file diff --git a/modules/container_app/container_app_app.tf b/modules/container_app/container_app_app.tf deleted file mode 100644 index 0ceda7a..0000000 --- a/modules/container_app/container_app_app.tf +++ /dev/null @@ -1,55 +0,0 @@ -resource "azurerm_container_app" "container_app_app" { - name = var.container_app_app_name - container_app_environment_id = azurerm_container_app_environment.container_app_environment.id - resource_group_name = data.azurerm_resource_group.resource_group.name - revision_mode = "Single" - - registry { - server = "index.docker.io" - username = var.docker_io_username - password_secret_name = "docker-io-password" - } - - template { - min_replicas = 0 - max_replicas = 2 - - container { - name = var.container_app_app_container_name - image = var.container_app_app_container_image - cpu = 0.25 - memory = "0.5Gi" - } - } - - ingress { - allow_insecure_connections = false - external_enabled = true - target_port = 8080 - transport = "auto" - - traffic_weight { - latest_revision = true - percentage = 100 - } - } - - secret { - name = "docker-io-password" - value = var.docker_io_password - } - - lifecycle { - ignore_changes = [ template[0].container[0].image ] - } -} - -resource "azurerm_container_app_custom_domain" "custom_domain" { - count = var.custom_domain_count - name = trimsuffix(trimprefix(azurerm_dns_txt_record.dns_txt_record[0].fqdn, "asuid."), ".") - container_app_id = azurerm_container_app.container_app_app.id - - lifecycle { - ignore_changes = [ certificate_binding_type, container_app_environment_certificate_id ] - } -} \ No newline at end of file diff --git a/modules/container_app/variables.tf b/modules/container_app/variables.tf index 78e8740..bd4c9bb 100644 --- a/modules/container_app/variables.tf +++ b/modules/container_app/variables.tf @@ -2,40 +2,21 @@ variable "app_subdomain_name" { type = string } -variable "client_id" { +variable "containers" { + type = list(object({ + name = string + image = string + cpu = string + memory = string + })) + default = [] +} + +variable "container_app_name" { type = string } -variable "client_secret" { - sensitive = true - type = string -} - -variable "container_app_app_name" { - type = string -} - -variable "container_app_app_container_image" { - type = string -} - -variable "container_app_app_container_name" { - type = string -} - -variable "container_app_api_name" { - type = string -} - -variable "container_app_api_container_image" { - type = string -} - -variable "container_app_api_container_name" { - type = string -} - -variable "container_app_environment_name" { +variable "container_app_environment_id" { type = string } @@ -43,12 +24,22 @@ variable "custom_domain_count" { type = string } -variable "docker_io_password" { +variable "init_containers" { + default = [] + type = list(object({ + name = string + image = string + cpu = string + memory = string + })) +} + +variable "registry_password" { sensitive = true type = string } -variable "docker_io_username" { +variable "registry_username" { type = string } @@ -60,7 +51,32 @@ variable "dns_zone_resource_group" { type = string } -variable "log_analytics_workspace_name" { +variable "ingress_external_enabled" { + default = false + type = bool +} + +variable "ingress_allow_insecure_connections" { + default = false + type = bool +} + +variable "ingress_target_port" { + type = number +} + +variable "ingress_transport" { + default = "auto" + type = string +} + +variable "registry_password_secret_name" { + default = "docker-io-password" + type = string +} + +variable "registry_server_name" { + default = "index.docker.io" type = string } @@ -68,10 +84,29 @@ variable "resource_group_name" { type = string } +variable "secrets" { + default = [] + type = list(object({ + name = string + value = string + })) +} + variable "storage_account_primary_connection_string" { type = string } -variable "tenant_id" { - type = string +variable "traffic_weight_percentage" { + default = 100 + type = number +} + +variable "template_min_replicas" { + default = 0 + type = number +} + +variable "template_max_replicas" { + default = 1 + type = number } \ No newline at end of file diff --git a/modules/container_app_environment/client_config.tf b/modules/container_app_environment/client_config.tf new file mode 100644 index 0000000..38ee13c --- /dev/null +++ b/modules/container_app_environment/client_config.tf @@ -0,0 +1,2 @@ +data "azurerm_client_config" "current" { +} \ No newline at end of file diff --git a/modules/container_app/container_app_environment.tf b/modules/container_app_environment/container_app_environment.tf similarity index 84% rename from modules/container_app/container_app_environment.tf rename to modules/container_app_environment/container_app_environment.tf index 81ace78..0e48bd2 100644 --- a/modules/container_app/container_app_environment.tf +++ b/modules/container_app_environment/container_app_environment.tf @@ -2,8 +2,8 @@ resource "azurerm_log_analytics_workspace" "log_analytics_workspace" { name = var.log_analytics_workspace_name location = data.azurerm_resource_group.resource_group.location resource_group_name = data.azurerm_resource_group.resource_group.name - sku = "PerGB2018" - retention_in_days = 30 + sku = var.log_analytics_workspace_sku + retention_in_days = var.log_analytics_workspace_retention_in_days } resource "azurerm_container_app_environment" "container_app_environment" { diff --git a/modules/container_app_environment/resource_group.tf b/modules/container_app_environment/resource_group.tf new file mode 100644 index 0000000..f68b1dd --- /dev/null +++ b/modules/container_app_environment/resource_group.tf @@ -0,0 +1,3 @@ +data "azurerm_resource_group" "resource_group" { + name = var.resource_group_name +} \ No newline at end of file diff --git a/modules/container_app_environment/variables.tf b/modules/container_app_environment/variables.tf new file mode 100644 index 0000000..773c71e --- /dev/null +++ b/modules/container_app_environment/variables.tf @@ -0,0 +1,20 @@ +variable "container_app_environment_name" { + type = string +} + +variable "log_analytics_workspace_name" { + type = string +} + +variable "log_analytics_workspace_retention_in_days" { + default = 30 +} + +variable "log_analytics_workspace_sku" { + default = "PerGB2018" + type = string +} + +variable "resource_group_name" { + type = string +} \ No newline at end of file diff --git a/modules/container_app/dns.tf b/modules/dns/dns.tf similarity index 100% rename from modules/container_app/dns.tf rename to modules/dns/dns.tf diff --git a/modules/dns/resource_group.tf b/modules/dns/resource_group.tf new file mode 100644 index 0000000..f68b1dd --- /dev/null +++ b/modules/dns/resource_group.tf @@ -0,0 +1,3 @@ +data "azurerm_resource_group" "resource_group" { + name = var.resource_group_name +} \ No newline at end of file diff --git a/modules/dns/variables.tf b/modules/dns/variables.tf new file mode 100644 index 0000000..4c6da95 --- /dev/null +++ b/modules/dns/variables.tf @@ -0,0 +1,19 @@ +variable "app_subdomain_name" { + +} + +variable "custom_domain_count" { + +} + +variable "dns_zone_resource_group" { + +} + +variable "domain_name" { + +} + +variable "resource_group_name" { + type = string +} \ No newline at end of file