Skip to content
AI-200 Learn

Environment variables

Quote API project environment variables: app settings, deploy-script variables, GitHub secrets, and how they map to Container Apps env vars and secrets.

What this covers

This is the reference for every environment variable the Quote API sample uses. Some configure the FastAPI app itself, some drive the deploy.sh / deploy.ps1 scripts, and two are GitHub Actions secrets. The page also shows how those values reach a running container in Azure Container Apps, as plain env vars or as secret references, because getting configuration into a container safely is a core exam skill.

Exam weight: Develop containerized solutions on Azure (20–25%)

Skills measured

  • "Deploy applications to Azure Container Apps, including environment configuration and revision management"
  • "Build and run images by using Azure Container Registry Tasks"

Key concepts

Local .env file

Copy the template and edit the values:

Azure CLI / Bash
cp .env.example .env

The app loads .env locally. In Azure the same names are set on the container instead, so the code never changes.

Application

VariableDefaultDescription
APP_NAMEQuote APIApplication name
APP_VERSION1.0.0Version string
ENVIRONMENTdevelopmentEnvironment label (development, production)
LOG_LEVELINFOLog level (DEBUG, INFO, WARNING, ERROR)
HOST0.0.0.0Server bind address
PORT8000Server port

Azure deploy (deploy.sh / deploy.ps1)

VariableDefaultDescription
RESOURCE_GROUPquote-api-rgAzure resource group
LOCATIONeastusAzure region
ACR_NAMEquoteapiacrContainer registry name (must be globally unique)
CONTAINERAPPS_ENVquote-api-envContainer Apps environment
CONTAINER_APPquote-apiContainer App name
IMAGE_NAMEquote-apiDocker image name

GitHub Actions (repository secrets)

VariableDescription
AZURE_CREDENTIALSService principal JSON for azure/login@v2
AZURE_RESOURCE_GROUPResource group used in the workflow

Plain values vs secrets in Container Apps

  • Plain env vars (--env-vars KEY=value) are stored in the revision template and anyone with read access can see them.
  • Secrets live at the app level (--secrets name=value, or a Key Vault reference with keyvaultref:<uri>,identityref:<id>). Env vars point at them with secretref:<name>.
  • Changing an env var creates a new revision. Changing only a secret does not. Restart the revision, or deploy a new one, so the containers pick up the new secret value.

How it works

Diagram source: flowchart LR Env[.env / shell vars] --> Script[deploy.sh / deploy.ps1] Script --> ACR[az acr build] Script --> ACA[az containerapp create] GH[GitHub secrets] --> WF[Actions workflow] WF --> ACA ACA --> Rev[Revision template env vars] Rev --> App[FastAPI on PORT 8000]

The deploy script reads RESOURCE_GROUP, ACR_NAME and the other deploy variables from your shell, falling back to the defaults. The app variables (ENVIRONMENT, LOG_LEVEL) are passed to the container as env vars on the revision. PORT must equal the ingress --target-port.

Hands-on

Azure portal

  1. Open the container app and select Application > Containers, then Edit and deploy.
  2. Select the container, then Environment variables, and add ENVIRONMENT=production and LOG_LEVEL=INFO.
  3. For a secret, add it first under Settings > Secrets, then add an env var with the source Reference a secret.
  4. Select Create. A new revision is deployed with the values.

Azure CLI

Override a deploy variable when the default ACR name is taken:

Azure CLI / Bash
ACR_NAME=myuniqueacr123 ./deploy.sh

Set app env vars and a secret-backed variable on the running app:

Azure CLI / Bash
az containerapp secret set -n quote-api -g quote-api-rg \
  --secrets "api-key=<value>"

az containerapp update -n quote-api -g quote-api-rg \
  --set-env-vars ENVIRONMENT=production LOG_LEVEL=INFO API_KEY=secretref:api-key

Check what the current revision received:

Azure CLI / Bash
az containerapp show -n quote-api -g quote-api-rg \
  --query "properties.template.containers[0].env" -o table

Python

How the app reads its settings, with the same defaults as the table:

Python
import os

APP_NAME = os.getenv("APP_NAME", "Quote API")
ENVIRONMENT = os.getenv("ENVIRONMENT", "development")
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO")
HOST = os.getenv("HOST", "0.0.0.0")
PORT = int(os.getenv("PORT", "8000"))

Exam traps

ValuePut it in
Log level, environment labelPlain env var
API key, connection stringContainer Apps secret or Key Vault reference, exposed with secretref:
Deploy-time names (RG, ACR)Shell / pipeline variables, not the image
Azure login for CIGitHub secret AZURE_CREDENTIALS (or OIDC federated credentials)

Quick review

  • Bind HOST=0.0.0.0 so Azure can reach the process.
  • PORT=8000 must match the Container Apps --target-port.
  • Override ACR_NAME when the default name is already taken (ACR names are globally unique).
  • --set-env-vars creates a new revision. secret set alone doesn't.
  • Use secretref:<name> to expose a secret as an env var.
  • AZURE_CREDENTIALS holds the service principal JSON for azure/login@v2.

Practice

Official references