Skip to content

New-AzResourceGroupDeployment should not execute whatif when ConfirmPreference== ConfirmImpact.None #14083

@henriblMSFT

Description

@henriblMSFT

Description

Setting ConfirmImpact.None has the same behavior as setting ConfirmImpact.Low when executing the New-AzResourceGroupDeployment and executes the WhatIf behavior

Steps to reproduce

$ConfirmPreference = "None"
New-AzResourceGroupDeployment [...]

The bug is in ShouldProcessGivenCurrentConfirmFlagAndPreference

        private bool ShouldProcessGivenCurrentConfirmFlagAndPreference()
        {
            if (this.MyInvocation.BoundParameters.GetOrNull("Confirm") is SwitchParameter confirmFlag)
            {
                return confirmFlag.IsPresent;
            }

            if (this.SessionState == null)
            {
                return false;
            }

            var confirmPreference = (ConfirmImpact)this.SessionState.PSVariable.GetValue("ConfirmPreference");

            return this.ConfirmImpact >= confirmPreference;
        }

specifically

 return this.ConfirmImpact >= confirmPreference;

should be

return confirmPreference != ConfirmImpact.None && this.ConfirmImpact >= confirmPreference;

Module versions

5.4.0

workaround

if($ConfirmPreference -eq "None") {
  New-AzResourceGroupDeployment [...] -Confirm:$false
} else {
  New-AzResourceGroupDeployment [...]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    ARMService AttentionThis issue is responsible by Azure service team.customer-reportedneeds-team-attentionThis issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions