Skip to content

Add What-If support for deployment stacks - #327

Draft
Anthony Martin (anthony-c-martin) with Copilot wants to merge 9 commits into
mainfrom
copilot/feature-support-azure-deployment-stack-whatif
Draft

Anthony Martin (anthony-c-martin) with Copilot wants to merge 9 commits into
mainfrom
copilot/feature-support-azure-deployment-stack-whatif

Conversation

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown

Deployment stacks did not support the whatIf operation, unlike regular deployments. Users had no way to preview stack changes before applying them, or to conditionally gate a create operation on whether changes were actually detected.

SDK upgrade

  • Bump @azure/arm-resourcesdeploymentstacks to ^2.0.0, which introduces the deploymentStacksWhatIfResultsAt{ResourceGroup,Subscription,ManagementGroup} operation groups needed for stack what-if. Existing stack operations continue to use the same (now-deprecated but still functional) method names, so no other call sites needed changes.

Config & inputs

  • Added whatIf as a valid operation value for deploymentStack config (previously only create, validate, delete).

What-if execution

  • Added stackWhatIf in stacks.ts, which computes the deployment stack ARM resource ID from the configured scope/name, creates a transient DeploymentStacksWhatIfResult resource (with a minimal 1-day retention interval) to trigger the computation, then fetches the result with full property-level changes.

Presentation & output

  • Added formatting logic for DeploymentStacksWhatIfChange results (change legend, stack-level changes, per-resource changes, property diffs, summary), modeled after the Azure CLI's stack what-if formatter.
  • Wired the whatIf operation into handler.ts, logging the formatted result and diagnostics.
  • Added a hasChanges action output, set for both deployment and deployment stack whatIf operations, so subsequent workflow steps can conditionally decide whether to run create:
- id: whatif
  uses: azure/bicep-deploy@v2
  with:
    type: deploymentStack
    operation: whatIf
    ...

- if: steps.whatif.outputs.hasChanges == 'true'
  uses: azure/bicep-deploy@v2
  with:
    type: deploymentStack
    operation: create
    ...

Docs

  • Updated action.yml and README to document the new whatIf operation for deployment stacks and the hasChanges output.

Copilot AI and others added 2 commits September 8, 2026 15:19
Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for Azure deployment stack what-if feature Add What-If support for deployment stacks with hasChanges output Sep 8, 2026
Comment thread packages/bicep-deploy-common/src/stacks.ts
Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
Comment thread packages/bicep-deploy-common/src/stackWhatIf.ts Outdated
Comment thread action.yml Outdated
Comment thread packages/bicep-deploy-common/test/stackWhatIf.test.ts Outdated
@anthony-c-martin

Copy link
Copy Markdown
Member

Copilot please address my comments

Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
Comment thread packages/bicep-deploy-common/test/stackWhatIfReference.ts Outdated
Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
Comment thread packages/bicep-deploy-common/src/handler.ts Outdated
Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
@anthony-c-martin Anthony Martin (anthony-c-martin) changed the title Add What-If support for deployment stacks with hasChanges output Add What-If support for deployment stacks Sep 8, 2026
Comment thread packages/bicep-deploy-common/src/logging.ts
Comment on lines +105 to +132
insert(
index: number,
value: string = "",
color?: Color,
noIndent: boolean = false,
): this {
if (color && this.colorMode !== "off") {
this.contents.splice(
index,
0,
getColorString(this.colorMode, Color.Reset),
);
}

this.contents.splice(index, 0, value);

if (color && this.colorMode !== "off") {
this.contents.splice(index, 0, getColorString(this.colorMode, color));
}

if (!noIndent && this.shouldIndent(index, true)) {
this.contents.splice(index, 0, this.indents.join(""));
}

return this;
}

insertLine(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the need to add all these extra methods? Aren't there existing ones we can use?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot pls address

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed insert/insertLine/getCurrentIndex in d997c64. The only caller (stackWhatIf.ts's conditional stack-changes title) now builds that section into a temporary ColorStringBuilder, then appends the title + built content to the main builder with the existing appendLine/append methods only if something was actually produced — no more inserting at a previously-recorded position.

…s array

Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@users.noreply.github.com>
… a section sub-builder instead

Co-authored-by: anthony-c-martin <38542602+anthony-c-martin@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.

[feature] support azure deployment stack whatif

2 participants