Skip to content

Commit 3e7edb8

Browse files
committed
Allow secrets to be stored in container app jobs
1 parent 3fb70f7 commit 3e7edb8

2 files changed

Lines changed: 25 additions & 0 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

0 commit comments

Comments
 (0)