Skip to content

fix: add conditional output handling for optional Bicep module references#43

Open
justinyoo wants to merge 1 commit intoAzure-Samples:mainfrom
justinyoo:hotfix/conditional-outputs
Open

fix: add conditional output handling for optional Bicep module references#43
justinyoo wants to merge 1 commit intoAzure-Samples:mainfrom
justinyoo:hotfix/conditional-outputs

Conversation

@justinyoo
Copy link
Copy Markdown

@justinyoo justinyoo commented Mar 17, 2026

Purpose

  • Fix Bicep deployment errors when optional module references (e.g., Application Insights, ACR connection, Bing search connections, storage connection) are conditionally deployed but their outputs are still unconditionally referenced.
  • Use the Bicep non-null assertion operator (!) on conditional module outputs to satisfy the compiler when accessing .outputs on modules guarded by if conditions.
  • Guard output expressions with !empty() checks and empty-string fallbacks so that outputs resolve safely when upstream AI services or project parameters are not provided.
  • Wrap ACR role assignments in a concat() pattern to conditionally include the AI project service principal only when AI services are configured.

Files changed

  • infra/core/ai/ai-project.bicep – non-null assertions on applicationInsights module outputs
  • infra/core/host/acr.bicep – conditional role assignments and connection output
  • infra/core/search/bing_custom_grounding.bicep – conditional connection outputs
  • infra/core/search/bing_grounding.bicep – conditional connection outputs
  • infra/core/storage/storage.bicep – conditional connection output

Does this introduce a breaking change?

  • Yes
  • No

Pull Request Type

What kind of change does this Pull Request introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Documentation content changes
  • Other... Please describe:

How to Test

  • Get the code
git clone https://github.com/justinyoo/azd-ai-starter-basic.git
cd azd-ai-starter-basic
git checkout hotfix/conditional-outputs
  • Test the code
azd up

What to Check

Verify that the following are valid

  • Deployment succeeds when all optional parameters are provided (full deployment)
  • Deployment succeeds when AI services account name and project name are omitted (partial deployment)
  • No Bicep compiler warnings or errors on the changed files

Other Information

…nces

Use the non-null assertion operator (!) for conditional module outputs
and guard output expressions with empty-string fallbacks when upstream
AI services or project parameters are not provided.

Files changed:
- infra/core/ai/ai-project.bicep
- infra/core/host/acr.bicep
- infra/core/search/bing_custom_grounding.bicep
- infra/core/search/bing_grounding.bicep
- infra/core/storage/storage.bicep

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant