Skip to content

[containerapp] Fix compose create not expanding ${VAR:-default} for unset environment variables - #9965

Draft
Aditya Pujara (a0x1ab) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-containerapp-environment-variables
Draft

[containerapp] Fix compose create not expanding ${VAR:-default} for unset environment variables#9965
Aditya Pujara (a0x1ab) with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-containerapp-environment-variables

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

az containerapp compose create was passing literal strings like ${VAR_C:-bar} as environment variable values instead of expanding them to their defaults (bar) when the variable was unset in the local shell.

Changes

azext_containerapp/_compose_utils.py

  • Added _expand_env_var_substitution(value): explicit Docker Compose variable substitution expansion covering all three syntax forms:
    • ${VAR:-default} — use default when unset or empty
    • ${VAR-default} — use default only when unset
    • ${VAR} — substitute value (empty string when unset)
  • Added resolve_environment_from_service(service): overrides the core azure-cli function, applying explicit expansion as a second pass after pycomposefile processing

azext_containerapp/custom.py

  • Redirected resolve_environment_from_service import from azure.cli.command_modules.containerapp._compose_utils to the local module, so the extension's expansion logic is always applied

Tests

  • test_containerapp_compose_unit.py (new): 17 unit tests for _expand_env_var_substitution and resolve_environment_from_service covering set/unset/empty var combinations, the primary bug scenario, and non-string passthrough
  • test_containerapp_compose_environment.py: added scenario test test_containerapp_compose_create_with_unset_env_defaults for E2E validation

Example

# docker-compose.yml
services:
  app:
    environment:
      VAR_C: ${VAR_C:-bar}
# VAR_C not set in shell
az containerapp compose create --compose-file-path docker-compose.yml ...
# Before: "value": "${VAR_C:-bar}"
# After:  "value": "bar"

Related command

az containerapp compose create

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (azdev required; see .azure-pipelines/templates/azdev_setup.yml for the install command until azdev==0.2.11b1 is on PyPI)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

@azure-client-tools-bot-prd

azure-client-tools-bot-prd Bot commented Jun 22, 2026

Copy link
Copy Markdown
️✔️Azure CLI Extensions Breaking Change Test
️✔️Non Breaking Changes

@azure-client-tools-bot-prd

Copy link
Copy Markdown

Hi Copilot,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan

Copy link
Copy Markdown
Collaborator

containerapp

…ironment variables

- Add _expand_env_var_substitution() to _compose_utils.py to handle Docker
  Compose variable substitution syntax (${VAR:-default}, ${VAR-default}, ${VAR})
- Add resolve_environment_from_service() to _compose_utils.py that applies
  explicit expansion after pycomposefile processing, ensuring unset variables
  with defaults are resolved to their default values rather than being passed
  as literal placeholder strings
- Update custom.py to import resolve_environment_from_service from the local
  _compose_utils module instead of the core azure-cli module
- Add unit tests (test_containerapp_compose_unit.py) covering the expansion logic
- Add scenario test for the unset env var default expansion case
Copilot AI changed the title [WIP] Fix containerapp compose create to read unset environment variables [containerapp] Fix compose create not expanding ${VAR:-default} for unset environment variables Jun 22, 2026
@a0x1ab Aditya Pujara (a0x1ab) added azure-client-tools-agent Pull request commented on or reviewed by Azure Client Tools Agent and removed azure-client-tools-agent Pull request commented on or reviewed by Azure Client Tools Agent labels Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot ContainerApp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants