commit 01b3303a38efe64ab66bcab185cfa0dff333b49a Author: Noah Spannbauer Date: Sun Feb 23 12:42:24 2025 -0600 first commit diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/modules/container_app/client_config.tf b/modules/container_app/client_config.tf new file mode 100644 index 0000000..38ee13c --- /dev/null +++ b/modules/container_app/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_api.tf b/modules/container_app/container_app_api.tf new file mode 100644 index 0000000..4fd9b11 --- /dev/null +++ b/modules/container_app/container_app_api.tf @@ -0,0 +1,85 @@ +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 = azurerm_storage_account.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 new file mode 100644 index 0000000..0ceda7a --- /dev/null +++ b/modules/container_app/container_app_app.tf @@ -0,0 +1,55 @@ +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/container_app_environment.tf b/modules/container_app/container_app_environment.tf new file mode 100644 index 0000000..81ace78 --- /dev/null +++ b/modules/container_app/container_app_environment.tf @@ -0,0 +1,14 @@ +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 +} + +resource "azurerm_container_app_environment" "container_app_environment" { + name = var.container_app_environment_name + location = data.azurerm_resource_group.resource_group.location + resource_group_name = data.azurerm_resource_group.resource_group.name + log_analytics_workspace_id = azurerm_log_analytics_workspace.log_analytics_workspace.id +} \ No newline at end of file diff --git a/modules/container_app/dns.tf b/modules/container_app/dns.tf new file mode 100644 index 0000000..a79fd2d --- /dev/null +++ b/modules/container_app/dns.tf @@ -0,0 +1,19 @@ +data "azurerm_dns_zone" "dns_zone" { + name = var.domain_name +} + +data "azurerm_resource_group" "dns_zone_resource_group" { + name = var.dns_zone_resource_group +} + +resource "azurerm_dns_txt_record" "dns_txt_record" { + count = var.custom_domain_count + name = "asuid.${var.app_subdomain_name}" + resource_group_name = data.azurerm_resource_group.dns_zone_resource_group.name + zone_name = data.azurerm_dns_zone.dns_zone.name + ttl = 14400 + + record { + value = azurerm_container_app.container_app_app.custom_domain_verification_id + } +} \ No newline at end of file diff --git a/modules/container_app/resource_group.tf b/modules/container_app/resource_group.tf new file mode 100644 index 0000000..f68b1dd --- /dev/null +++ b/modules/container_app/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/storage_account.tf b/modules/container_app/storage_account.tf new file mode 100644 index 0000000..a6fa042 --- /dev/null +++ b/modules/container_app/storage_account.tf @@ -0,0 +1,13 @@ +resource "azurerm_storage_account" "storage_account" { + name = var.storage_account_name + resource_group_name = data.azurerm_resource_group.resource_group.name + location = data.azurerm_resource_group.resource_group.location + account_tier = "Standard" + account_replication_type = "LRS" +} + +resource "azurerm_storage_table" "storage_table" { + count = length(var.storage_tables) + name = var.storage_tables[count.index] + storage_account_name = azurerm_storage_account.storage_account.name +} \ No newline at end of file diff --git a/modules/container_app/variables.tf b/modules/container_app/variables.tf new file mode 100644 index 0000000..3594105 --- /dev/null +++ b/modules/container_app/variables.tf @@ -0,0 +1,81 @@ +variable "app_subdomain_name" { + type = string +} + +variable "client_id" { + 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" { + type = string +} + +variable "custom_domain_count" { + type = string +} + +variable "docker_io_password" { + sensitive = true + type = string +} + +variable "docker_io_username" { + type = string +} + +variable "domain_name" { + type = string +} + +variable "dns_zone_resource_group" { + type = string +} + +variable "log_analytics_workspace_name" { + type = string +} + +variable "resource_group_name" { + type = string +} + +variable "storage_account_name" { + type = string +} + +variable "storage_tables" { + type = list(string) +} + +variable "tenant_id" { + type = string +} \ No newline at end of file