Azure / Azure/azure-powershell
New-AzResourceGroupDeployment should not execute whatif when ConfirmPreference== ConfirmImpact.None
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
## 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
```powershell
$ConfirmPreference = "None"
New-AzResourceGroupDeployment [...]
```
The bug is in `ShouldProcessGivenCurrentConfirmFlagAndPreference`
```csharp
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
```csharp
return this.ConfirmImpact >= confirmPreference;
```
should be
```csharp
return confirmPreference != ConfirmImpact.None && this.ConfirmImpact >= confirmPreference;
```
## Module versions
5.4.0
## workaround
```powershell
if($ConfirmPreference -eq "None") {
New-AzResourceGroupDeployment [...] -Confirm:$false
} else {
New-AzResourceGroupDeployment [...]
}
```
Contributor guide
Assessment
This issue has not been assessed yet.