Skip to content

Commit d04f2c6

Browse files
authored
Feat/dtoss 10700 use a docker image for the postgres database for the review apps (#224)
* Allow secrets to be stored in container app jobs * Allow secrets to be stored in container app and change ingress to allow tcp ports
1 parent cf3f226 commit d04f2c6

5 files changed

Lines changed: 78 additions & 4 deletions

File tree

infrastructure/modules/container-app-job/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ resource "azurerm_container_app_job" "this" {
7171
}
7272
}
7373

74+
dynamic "secret" {
75+
for_each = var.secret_variables
76+
content {
77+
name = replace(lower(secret.key), "_", "-")
78+
value = secret.value
79+
}
80+
}
81+
7482
# Define the container template for the job.
7583
template {
7684

@@ -92,6 +100,7 @@ resource "azurerm_container_app_job" "this" {
92100
value = env.value
93101
}
94102
}
103+
95104
dynamic "env" {
96105
for_each = var.fetch_secrets_from_app_key_vault ? data.azurerm_key_vault_secrets.app[0].secrets : []
97106
content {
@@ -102,6 +111,16 @@ resource "azurerm_container_app_job" "this" {
102111
secret_name = lower(env.value.name)
103112
}
104113
}
114+
115+
dynamic "env" {
116+
for_each = var.secret_variables
117+
content {
118+
# Env vars are uppercase and underscore separated
119+
name = upper(replace(env.key, "-", "_"))
120+
# app container secrets are lowercase and hyphen separated
121+
secret_name = replace(lower(env.key), "_", "-")
122+
}
123+
}
105124
}
106125
}
107126

infrastructure/modules/container-app-job/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ variable "environment_variables" {
7676
default = {}
7777
}
7878

79+
variable "secret_variables" {
80+
description = "Secret environment variables to pass to the container app."
81+
type = map(string)
82+
default = {}
83+
}
84+
7985
variable "job_parallelism" {
8086
description = "The number of replicas that can run in parallel."
8187
type = number

infrastructure/modules/container-app/main.tf

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ resource "azurerm_container_app" "main" {
6161
}
6262
}
6363

64+
dynamic "secret" {
65+
for_each = var.secret_variables
66+
content {
67+
name = replace(lower(secret.key), "_", "-")
68+
value = secret.value
69+
}
70+
}
71+
6472
template {
6573
container {
6674
name = var.name
@@ -76,6 +84,15 @@ resource "azurerm_container_app" "main" {
7684
}
7785
}
7886

87+
dynamic "env" {
88+
for_each = var.secret_variables
89+
content {
90+
# Env vars are uppercase and underscore separated
91+
name = upper(replace(env.key, "-", "_"))
92+
secret_name = replace(lower(env.key), "_", "-")
93+
}
94+
}
95+
7996
dynamic "env" {
8097
for_each = var.fetch_secrets_from_app_key_vault ? data.azurerm_key_vault_secrets.app[0].secrets : []
8198
content {
@@ -104,8 +121,24 @@ resource "azurerm_container_app" "main" {
104121

105122
content {
106123
external_enabled = true
107-
target_port = var.http_port
124+
target_port = var.port
125+
allow_insecure_connections = false
126+
traffic_weight {
127+
percentage = 100
128+
latest_revision = true
129+
}
130+
}
131+
}
132+
133+
dynamic "ingress" {
134+
for_each = var.is_tcp_app ? [1] : []
135+
136+
content {
137+
external_enabled = true
138+
target_port = var.port
139+
exposed_port = var.port
108140
allow_insecure_connections = false
141+
transport = "tcp"
109142
traffic_weight {
110143
percentage = 100
111144
latest_revision = true

infrastructure/modules/container-app/output.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ output "url" {
77
description = "URL of the container app. Only available if is_web_app is true."
88
value = var.is_web_app ? "https://${azurerm_container_app.main.ingress[0].fqdn}" : ""
99
}
10+
11+
output "container_app_fqdn" {
12+
value = azurerm_container_app.main.latest_revision_fqdn
13+
}

infrastructure/modules/container-app/variables.tf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,13 @@ variable "docker_image" {
5252
}
5353

5454
variable "environment_variables" {
55-
description = "Environment variables to pass to the container app. Only non-secret variables. Secrets must be stored in key vault 'app_key_vault_id'"
55+
description = "Environment variables to pass to the container app. Only non-secret variables. Secrets can be stored in key vault 'app_key_vault_id'"
56+
type = map(string)
57+
default = {}
58+
}
59+
60+
variable "secret_variables" {
61+
description = "Secret environment variables to pass to the container app."
5662
type = map(string)
5763
default = {}
5864
}
@@ -69,8 +75,14 @@ variable "is_web_app" {
6975
default = false
7076
}
7177

72-
variable "http_port" {
73-
description = "HTTP port for the web app. Default is 8080."
78+
variable "is_tcp_app" {
79+
description = "Is this a TCP app? If true, ingress is enabled."
80+
type = bool
81+
default = false
82+
}
83+
84+
variable "port" {
85+
description = "Port for the ingress. Default is 8080."
7486
type = number
7587
default = 8080
7688
}

0 commit comments

Comments
 (0)