File tree Expand file tree Collapse file tree
infrastructure/modules/container-app Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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+ }
Original file line number Diff line number Diff line change @@ -52,7 +52,13 @@ variable "docker_image" {
5252}
5353
5454variable "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}
You can’t perform that action at this time.
0 commit comments