Skip to main content

The container_apps module

Per slot: a Container Apps environment on its own infrastructure subnet, the Pathways app with TCP ingress for MLLP (one main port and up to five additional ports, with the address guard on ingress_allowed_cidrs), startup, liveness and readiness probes on the engine's probe listener, and a Container Apps job that runs pathways migrate. The app and the job read the database URL and each master key from Key Vault through secretRef, as the managed identity you pass.

Use it on its own with source = "github.com/cosyte/terraform-azurerm-pathways//modules/container_apps".

This page is generated from the code in modules/container_apps/ by scripts/docs.sh, and CI fails when it no longer matches. Change modules/container_apps/variables.tf or its outputs.tf, then run scripts/docs.sh.

Requirements​

NameVersion
terraform>= 1.9.0
azapi>= 2.0.0, < 3.0.0
azurerm>= 4.42.0, < 5.0.0

Resources​

  • azapi_resource.app
  • azurerm_container_app_environment.this
  • azurerm_container_app_job.migrate
  • data.azurerm_resource_group.this

Inputs​

28 inputs, 9 of them required. The required ones come first, then the rest by name.

database_url_secret_id​

Required.

The versionless id of the Key Vault secret that holds the engine's database URL. The app and the migrate job read it as PATHWAYS_DATABASE_URL.

Type:

string

identity_client_id​

Required.

The client id of the identity in identity_id. The app and the migrate job get it as AZURE_CLIENT_ID, so Azure's default chain signs in as that user-assigned identity: for the database with Microsoft Entra ID, and for Blob Storage.

Type:

string

identity_id​

Required.

The resource id of the user-assigned managed identity the apps and the jobs run as. It must hold Key Vault Secrets User on the vault before a revision starts, and AcrPull on container_registry_server when that is set.

Type:

string

key_vault_uri​

Required.

The URI of the Key Vault the secrets are read from, ending in a slash, such as https://kv-example.vault.azure.net/. Each secret named in encryption_key_secrets is read from <key_vault_uri>secrets/<name>.

Type:

string

The plan refuses a value that breaks this rule, with this message:

  • key_vault_uri must end in a slash, as a Key Vault's vault_uri does.

location​

Required.

The Azure region, such as eastus2.

Type:

string

log_analytics_workspace_id​

Required.

The Log Analytics workspace every environment sends its logs to.

Type:

string

name​

Required.

Short name the environment, app and job names are built from (cae-<name>-<slot>, <name>-<slot>, <name>-<slot>-migrate): 3 to 16 lowercase letters, digits and hyphens, starting with a letter.

Type:

string

The plan refuses a value that breaks this rule, with this message:

  • name must be 3 to 16 lowercase letters, digits and single hyphens, starting with a letter and not ending with a hyphen.

resource_group_name​

Required.

The existing resource group the environments, apps and jobs are created in.

Type:

string

slots​

Required.

The deployment slots, keyed by a slot name of 1 to 5 lowercase letters or digits (such as blue and green). Each slot gets its own Container Apps environment, app and migrate job, on its own infrastructure subnet, so the two slots can expose the same MLLP ports at once: TCP ports are unique across one environment. Each subnet must be delegated to Microsoft.App/environments and be at least a /27. The image must be pinned by digest (registry/repository:tag@sha256:...).

Type:

map(object({
image = string
infrastructure_subnet_id = string
}))

The plan refuses a value that breaks one of these rules, with its message:

  • slots must name one slot, or two for blue and green.
  • Each slot name must be 1 to 5 lowercase letters or digits, starting with a letter.
  • Each slot's image must be pinned by digest: registry/repository:tag@sha256:<64 hex digits>.
  • Each slot needs its own infrastructure subnet: one subnet holds one Container Apps environment.

app_start_args​

Optional.

Arguments for the engine container. Null keeps the image's own command, pathways start -C /project, which applies the expand steps of a schema change itself; pass ["start", "-C", "/project", "--no-migrate"] to leave every schema change to the migrate job.

Type:

list(string)

Default: null

container_registry_server​

Optional.

A private registry the images are pulled from with the managed identity at identity_id, such as an Azure Container Registry login server. Grant that identity AcrPull. Null pulls anonymously, as from ghcr.io.

Type:

string

Default: null

cpu​

Optional.

vCPU for the engine container. memory must be twice this many Gi.

Type:

number

Default: 1

database_auth​

Optional.

How Pathways signs in to the database, given to the app and the migrate job as PATHWAYS_DATABASE_AUTH: password, with the login the database URL holds, or entra, with a Microsoft Entra ID token for the user the URL names. pathways.yaml reads it with auth: { env: PATHWAYS_DATABASE_AUTH, default: password } in its storage.postgres block.

Type:

string

Default: "password"

The plan refuses a value that breaks this rule, with this message:

  • database_auth must be password or entra, the two ways Pathways signs in to PostgreSQL.

drain_seconds​

Optional.

The termination grace period: how long the engine gets to stop after SIGTERM before it is killed. On SIGTERM it turns /readyz to draining, closes its sources and gives each hook up to its timeout. 0 to 600, default 30, the platform's own default. Container Apps documents no maximum for this field, and its lifecycle page still says a container is killed 30 seconds after SIGTERM, so a value above 30 is not confirmed to be honored: test it in your environment before you rely on it.

Type:

number

Default: 30

The plan refuses a value that breaks this rule, with this message:

  • drain_seconds must be a whole number of seconds from 0 to 600. 600 is this module's own bound: Container Apps documents none, and does not confirm a grace period above 30 seconds.

encryption_key_secrets​

Optional.

The master keys, by environment variable name (such as PATHWAYS_KEY_2026_11) to the name of a secret you put in the Key Vault at key_vault_uri. The module never generates or reads a key: create each secret before the app's revision starts.

Type:

map(string)

Default: {}

The plan refuses a value that breaks one of these rules, with its message:

  • Each key of encryption_key_secrets must be an environment variable name in capitals, digits and underscores.
  • Each value of encryption_key_secrets must be a Key Vault secret name: 1 to 127 letters, digits and hyphens.
  • The secret name database-url belongs to the module.

environment_variables​

Optional.

Plain environment variables for the engine and the migrate job, such as the settings pathways.yaml reads with env. Never a secret: use encryption_key_secrets or a Key Vault secret.

Type:

map(string)

Default: {}

The plan refuses a value that breaks one of these rules, with its message:

  • Each environment variable name must be letters, digits and underscores, not starting with a digit.
  • AZURE_CLIENT_ID and PATHWAYS_DATABASE_AUTH are set by the module, from identity_client_id and database_auth; do not pass them as plain variables.
  • PATHWAYS_DATABASE_URL is set by the module from Key Vault; do not pass it as a plain variable.

http_port​

Optional.

The port the engine's HTTP source listens on, for an app whose only intake is HTTP. The app then gets HTTP ingress in place of TCP: Container Apps ends TLS on port 443 of the app's address and passes plain HTTP to this port inside the environment, and plain HTTP from outside is refused (allowInsecure is false). ingress_allowed_cidrs guards it as it guards MLLP. Null, the default, for MLLP over TCP ingress (mllp_ports).

Type:

number

Default: null

The plan refuses a value that breaks one of these rules, with its message:

  • http_port must be a whole number from 1 to 65535, and not the reserved port 36985.
  • http_port must not be probes_port: the probe listener is never exposed.

ingress_allowed_cidrs​

Optional.

The address ranges allowed to reach the MLLP ports; every other address is denied. Each entry is a plain CIDR range: no spaces, a prefix length with no leading zero. Empty allows every address that can route to the environment, which is private to its virtual network, and is refused when internal_load_balancer_enabled is false. Unless unsafe_allow_mllp_from_any_address is true, it refuses an IPv4 range shorter than /8, an IPv6 range shorter than /32, an IPv4-mapped IPv6 range (::ffff:0:0/96) wider than an IPv4 /8 or holding the whole mapped range, and a list whose IPv4 ranges add up to every IPv4 address. Every other range is trusted as written.

Type:

list(string)

Default: []

The plan refuses a value that breaks one of these rules, with its message:

  • Each entry of ingress_allowed_cidrs must be a plain CIDR range, such as 10.20.0.0/16 or 2001:db8::/48: no spaces, and a prefix length with no leading zero.
  • ingress_allowed_cidrs must not hold a range wider than an IPv4 /8 or an IPv6 /32, nor an IPv4-mapped IPv6 range wider than an IPv4 /8 (0.0.0.0/0, ::/0, 0.0.0.0/1 and ::ffff:0:0/96 are all refused): MLLP has no authentication and carries PHI. Name your senders' ranges, or set unsafe_allow_mllp_from_any_address = true if you mean it.
  • The ranges in ingress_allowed_cidrs add up to every IPv4 address: MLLP has no authentication and carries PHI. Name your senders' ranges, or set unsafe_allow_mllp_from_any_address = true if you mean it.

internal_load_balancer_enabled​

Optional.

Give each environment a private address in its virtual network and no public address. Turn it off only when senders reach the engine over the internet, and then name them in ingress_allowed_cidrs: a public environment with no allowed ranges is refused.

Type:

bool

Default: true

The plan refuses a value that breaks this rule, with this message:

  • internal_load_balancer_enabled = false gives the environment a public address, and MLLP has no authentication and carries PHI: name the senders' address ranges in ingress_allowed_cidrs.

memory​

Optional.

Memory for the engine container, such as 2Gi.

Type:

string

Default: "2Gi"

metrics_collector​

Optional.

A metrics collector to run beside the engine in each replica of each slot's app, which reads the engine's /metrics over the replica's loopback: its image, pinned by digest; its configuration (passed as PATHWAYS_COLLECTOR_CONFIG and read with --config=env:PATHWAYS_COLLECTOR_CONFIG, as an OpenTelemetry collector takes it); and the versionless ids of two Key Vault secrets, the health endpoint's bearer token, which the app gives the engine and the collector as PATHWAYS_HEALTH_TOKEN, and the Application Insights connection string, which it gives the collector as APPLICATIONINSIGHTS_CONNECTION_STRING. The collector takes 0.25 vCPU and 0.5Gi beside the engine's cpu and memory. The migrate job does not get it. Null, the default, runs the engine alone.

Type:

object({
image = string
config = string
health_token_secret_id = string
connection_string_secret_id = string
})

Default: null

The plan refuses a value that breaks one of these rules, with its message:

  • metrics_collector.image must be pinned by digest: registry/repository:tag@sha256:<64 hex digits>.
  • With metrics_collector the engine reads PATHWAYS_HEALTH_TOKEN from its Key Vault secret: leave it out of environment_variables and encryption_key_secrets.
  • With metrics_collector, cpu must be 3.75 or less: the collector takes 0.25 vCPU, and an app on the Consumption profile gets 4 vCPU at most.

migrate_args​

Optional.

Arguments for the migrate job's container.

Type:

list(string)

Default: ["migrate", "-C", "/project"]

migrate_timeout_seconds​

Optional.

How long one run of the migrate job may take.

Type:

number

Default: 1800

The plan refuses a value that breaks this rule, with this message:

  • migrate_timeout_seconds must be a whole number of at least 60.

mllp_ports​

Optional.

The TCP ports the engine's MLLP sources listen on, each exposed on the same port number. The first is the app's main ingress port, the rest are additional port mappings: six at most (one plus five), never 80 or 443, never the reserved port 36985, never the probe port. Every exposed port, main or additional, is unique across the environment, and each slot has an environment of its own. Empty only with http_port set: the app takes either MLLP over TCP ingress or HTTP, not both.

Type:

list(number)

Default: []

The plan refuses a value that breaks one of these rules, with its message:

  • mllp_ports must hold at most 6 ports: Container Apps exposes one main port and at most five additional TCP ports.
  • Set mllp_ports or http_port, one of the two: the app's ingress is either TCP for MLLP or HTTP, not both and not neither.
  • Each MLLP port must be a whole number from 1 to 65535.
  • mllp_ports must not repeat a port: an exposed TCP port, main or additional, is unique across the environment.
  • Port 36985 is reserved by Container Apps and cannot be exposed.
  • Ports 80 and 443 belong to the environment's HTTP ingress and cannot be exposed as TCP ports.
  • mllp_ports must not include probes_port: the probe listener is never exposed.

probes_port​

Optional.

The port of the engine's probe listener (the probes block of pathways.yaml, with host 0.0.0.0), which answers /livez and /readyz.

Type:

number

Default: 9091

The plan refuses a value that breaks this rule, with this message:

  • probes_port must be a whole number from 1 to 65535, and not the reserved port 36985.

standby_replica​

Optional.

Run a second replica of the app as the engine's warm standby. Both replicas start with --standby: the first to ask takes the engine lease and runs every channel, the other holds no lease, opens no listener and answers /readyz 503 standby, so the ingress sends it nothing, and takes over within about 20 seconds once the engine holding the lease stops. Only one engine works at a time: the lease, not the replica count, decides. Off by default: one replica.

Type:

bool

Default: false

tags​

Optional.

Tags added to every resource that takes them.

Type:

map(string)

Default: {}

unsafe_allow_mllp_from_any_address​

Optional.

Allow ranges in ingress_allowed_cidrs that cover every address or most of it: a /0 (0.0.0.0/0, ::/0), an IPv4 range shorter than /8, an IPv6 range shorter than /32, a wide IPv4-mapped IPv6 range, or a list adding up to every IPv4 address. MLLP has no authentication of its own and carries PHI: with a public environment this opens the engine's intake to the whole internet. Leave it false.

Type:

bool

Default: false

Outputs​

4 outputs, by name.

database_auth​

How the app and the migrate job sign in to the database, as PATHWAYS_DATABASE_AUTH gives it: password or entra.

http_port​

The port the engine's HTTP source listens on behind HTTP ingress, or null for MLLP over TCP ingress.

mllp_ports​

The MLLP ports each slot exposes.

slots​

Per slot: the environment's id, static IP address (where senders connect for MLLP) and default domain, the app's id, name and address (fqdn, where senders connect for HTTP over TLS), and the migrate job's name.