|
| 1 | +# Deployment Stacks WhatIf Bug Bash Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | +We've implemented `-WhatIf` support for all Deployment Stack cmdlets with Azure CLI-style formatted output. This bug bash will validate the functionality works correctly across different scenarios. |
| 5 | + |
| 6 | +## Prerequisites |
| 7 | + |
| 8 | +1. **Azure Subscription** with access to create resources |
| 9 | +2. **PowerShell 7+** installed (`pwsh --version`) |
| 10 | +3. **Az.Accounts module** (for authentication) |
| 11 | +4. **Resource Group** for testing (or permissions to create one) |
| 12 | + |
| 13 | +## Setup Instructions |
| 14 | + |
| 15 | +### 1. Get the Code |
| 16 | +```powershell |
| 17 | +# Clone the branch (if you haven't already) |
| 18 | +git clone https://github.com/anamikapan11/azure-powershell |
| 19 | +cd azure-powershell |
| 20 | +git checkout anapandey/pwcmdlet |
| 21 | +
|
| 22 | +# OR if you already have it cloned |
| 23 | +git fetch origin |
| 24 | +git checkout anapandey/pwcmdlet |
| 25 | +git pull origin anapandey/pwcmdlet |
| 26 | +``` |
| 27 | + |
| 28 | +### 2. Build the Module |
| 29 | +```powershell |
| 30 | +# Build just the Resources module (takes 5-10 minutes) |
| 31 | +dotnet msbuild build.proj /p:Scope=Resources |
| 32 | +``` |
| 33 | + |
| 34 | +**Note**: This will take 5-10 minutes. Do not cancel the build. |
| 35 | + |
| 36 | +### 3. Load the Built Module |
| 37 | +```powershell |
| 38 | +# Remove any existing Az.Resources module |
| 39 | +Remove-Module Az.Resources, Az.Accounts -Force -ErrorAction SilentlyContinue |
| 40 | +
|
| 41 | +# Import the debug version you just built |
| 42 | +Import-Module ./artifacts/Debug/Az.Accounts/Az.Accounts.psd1 -Force |
| 43 | +Import-Module ./artifacts/Debug/Az.Resources/Az.Resources.psd1 -Force |
| 44 | +
|
| 45 | +# Verify the cmdlets are available |
| 46 | +Get-Command -Module Az.Resources -Name "*DeploymentStack*" |
| 47 | +``` |
| 48 | + |
| 49 | +### 4. Authenticate to Azure |
| 50 | +```powershell |
| 51 | +# Login to your Azure subscription |
| 52 | +Connect-AzAccount |
| 53 | +
|
| 54 | +# Set the subscription you want to use for testing |
| 55 | +Set-AzContext -SubscriptionId "<your-subscription-id>" |
| 56 | +``` |
| 57 | + |
| 58 | +### 5. Create Test Resources |
| 59 | +```powershell |
| 60 | +# Create a resource group for testing (if you don't have one) |
| 61 | +New-AzResourceGroup -Name "bugbash-deploystack-rg" -Location "eastus" |
| 62 | +``` |
| 63 | + |
| 64 | +## Test Scenarios |
| 65 | + |
| 66 | +### Scenario 1: Basic WhatIf - Empty Template |
| 67 | + |
| 68 | +**Purpose**: Verify WhatIf shows stack property changes (DenySettings, ActionOnUnmanage) |
| 69 | + |
| 70 | +**Template** (`empty-template.json`): |
| 71 | +```json |
| 72 | +{ |
| 73 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", |
| 74 | + "contentVersion": "1.0.0.0", |
| 75 | + "resources": [] |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +**Test Command**: |
| 80 | +```powershell |
| 81 | +New-AzResourceGroupDeploymentStack ` |
| 82 | + -Name "test-stack-empty" ` |
| 83 | + -ResourceGroupName "bugbash-deploystack-rg" ` |
| 84 | + -TemplateFile ./empty-template.json ` |
| 85 | + -ActionOnUnmanage DetachAll ` |
| 86 | + -DenySettingsMode None ` |
| 87 | + -WhatIf ` |
| 88 | + -Verbose |
| 89 | +``` |
| 90 | + |
| 91 | +**Expected Output**: |
| 92 | +- ? Legend showing symbols (+ Create, ~ Modify, - Delete, v Detach, = NoChange) |
| 93 | +- ? "Changes to Stack" section showing DenySettings changes |
| 94 | +- ? No errors or exceptions |
| 95 | +- ? No actual resources created |
| 96 | + |
| 97 | +### Scenario 2: WhatIf with Resources |
| 98 | + |
| 99 | +**Purpose**: Verify WhatIf shows managed resource changes |
| 100 | + |
| 101 | +**Template** (`template-with-resources.json`): |
| 102 | +```json |
| 103 | +{ |
| 104 | + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", |
| 105 | + "contentVersion": "1.0.0.0", |
| 106 | + "parameters": { |
| 107 | + "storageAccountName": { |
| 108 | + "type": "string", |
| 109 | + "defaultValue": "[concat('storage', uniqueString(resourceGroup().id))]" |
| 110 | + } |
| 111 | + }, |
| 112 | + "resources": [ |
| 113 | + { |
| 114 | + "type": "Microsoft.Storage/storageAccounts", |
| 115 | + "apiVersion": "2021-04-01", |
| 116 | + "name": "[parameters('storageAccountName')]", |
| 117 | + "location": "[resourceGroup().location]", |
| 118 | + "sku": { |
| 119 | + "name": "Standard_LRS" |
| 120 | + }, |
| 121 | + "kind": "StorageV2" |
| 122 | + } |
| 123 | + ] |
| 124 | +} |
| 125 | +``` |
| 126 | + |
| 127 | +**Test Command**: |
| 128 | +```powershell |
| 129 | +New-AzResourceGroupDeploymentStack ` |
| 130 | + -Name "test-stack-storage" ` |
| 131 | + -ResourceGroupName "bugbash-deploystack-rg" ` |
| 132 | + -TemplateFile ./template-with-resources.json ` |
| 133 | + -ActionOnUnmanage DetachAll ` |
| 134 | + -DenySettingsMode None ` |
| 135 | + -WhatIf ` |
| 136 | + -Verbose |
| 137 | +``` |
| 138 | + |
| 139 | +**Expected Output**: |
| 140 | +- ? Legend showing symbols |
| 141 | +- ? "Changes to Stack" section |
| 142 | +- ? "Changes to Managed Resources" section showing storage account creation |
| 143 | +- ? Management Status changes (null ? "Managed") |
| 144 | +- ? No actual resources created |
| 145 | + |
| 146 | +### Scenario 3: Set-AzResourceGroupDeploymentStack with WhatIf |
| 147 | + |
| 148 | +**Purpose**: Verify WhatIf works for updating existing stacks |
| 149 | + |
| 150 | +**Pre-requisite**: Create a stack first (without -WhatIf): |
| 151 | +```powershell |
| 152 | +New-AzResourceGroupDeploymentStack ` |
| 153 | + -Name "test-stack-update" ` |
| 154 | + -ResourceGroupName "bugbash-deploystack-rg" ` |
| 155 | + -TemplateFile ./empty-template.json ` |
| 156 | + -ActionOnUnmanage DetachAll ` |
| 157 | + -DenySettingsMode None |
| 158 | +``` |
| 159 | + |
| 160 | +**Test Command**: |
| 161 | +```powershell |
| 162 | +Set-AzResourceGroupDeploymentStack ` |
| 163 | + -Name "test-stack-update" ` |
| 164 | + -ResourceGroupName "bugbash-deploystack-rg" ` |
| 165 | + -TemplateFile ./empty-template.json ` |
| 166 | + -ActionOnUnmanage DeleteAll ` |
| 167 | + -DenySettingsMode DenyDelete ` |
| 168 | + -WhatIf ` |
| 169 | + -Verbose |
| 170 | +``` |
| 171 | + |
| 172 | +**Expected Output**: |
| 173 | +- ? Shows changes to ActionOnUnmanage (DetachAll ? DeleteAll) |
| 174 | +- ? Shows changes to DenySettingsMode (None ? DenyDelete) |
| 175 | +- ? No actual stack update performed |
| 176 | + |
| 177 | +### Scenario 4: Subscription-Level WhatIf |
| 178 | + |
| 179 | +**Purpose**: Verify WhatIf works at subscription scope |
| 180 | + |
| 181 | +**Template** (`sub-template.json`): |
| 182 | +```json |
| 183 | +{ |
| 184 | + "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", |
| 185 | + "contentVersion": "1.0.0.0", |
| 186 | + "resources": [ |
| 187 | + { |
| 188 | + "type": "Microsoft.Resources/resourceGroups", |
| 189 | + "apiVersion": "2021-04-01", |
| 190 | + "name": "test-rg-from-stack", |
| 191 | + "location": "eastus", |
| 192 | + "properties": {} |
| 193 | + } |
| 194 | + ] |
| 195 | +} |
| 196 | +``` |
| 197 | + |
| 198 | +**Test Command**: |
| 199 | +```powershell |
| 200 | +New-AzSubscriptionDeploymentStack ` |
| 201 | + -Name "test-stack-sub" ` |
| 202 | + -Location "eastus" ` |
| 203 | + -TemplateFile ./sub-template.json ` |
| 204 | + -ActionOnUnmanage DetachAll ` |
| 205 | + -DenySettingsMode None ` |
| 206 | + -WhatIf ` |
| 207 | + -Verbose |
| 208 | +``` |
| 209 | + |
| 210 | +**Expected Output**: |
| 211 | +- ? Formatted output with legend |
| 212 | +- ? Shows resource group creation |
| 213 | +- ? No actual resources created |
| 214 | + |
| 215 | +### Scenario 5: Remove with WhatIf |
| 216 | + |
| 217 | +**Purpose**: Verify WhatIf works for deletion |
| 218 | + |
| 219 | +**Pre-requisite**: Ensure stack exists from previous tests |
| 220 | + |
| 221 | +**Test Command**: |
| 222 | +```powershell |
| 223 | +Remove-AzResourceGroupDeploymentStack ` |
| 224 | + -Name "test-stack-update" ` |
| 225 | + -ResourceGroupName "bugbash-deploystack-rg" ` |
| 226 | + -ActionOnUnmanage DetachAll ` |
| 227 | + -WhatIf ` |
| 228 | + -Verbose |
| 229 | +``` |
| 230 | + |
| 231 | +**Expected Output**: |
| 232 | +- ? "What if: Performing the operation..." message |
| 233 | +- ? No actual deletion performed |
| 234 | + |
| 235 | +### Scenario 6: WhatIf with DenySettings Changes |
| 236 | + |
| 237 | +**Purpose**: Verify WhatIf shows DenySettings configuration changes |
| 238 | + |
| 239 | +**Test Command**: |
| 240 | +```powershell |
| 241 | +New-AzResourceGroupDeploymentStack ` |
| 242 | + -Name "test-stack-denysettings" ` |
| 243 | + -ResourceGroupName "bugbash-deploystack-rg" ` |
| 244 | + -TemplateFile ./empty-template.json ` |
| 245 | + -ActionOnUnmanage DetachAll ` |
| 246 | + -DenySettingsMode DenyWriteAndDelete ` |
| 247 | + -DenySettingsApplyToChildScopes ` |
| 248 | + -DenySettingsExcludedPrincipal @("00000000-0000-0000-0000-000000000000") ` |
| 249 | + -WhatIf ` |
| 250 | + -Verbose |
| 251 | +``` |
| 252 | + |
| 253 | +**Expected Output**: |
| 254 | +- ? Shows DenySettings.Mode creation |
| 255 | +- ? Shows DenySettings.ApplyToChildScopes |
| 256 | +- ? Shows ExcludedPrincipals array |
| 257 | + |
| 258 | +## What to Test |
| 259 | + |
| 260 | +### Functional Testing |
| 261 | +1. **All cmdlets work with -WhatIf**: |
| 262 | + - `New-AzResourceGroupDeploymentStack -WhatIf` |
| 263 | + - `Set-AzResourceGroupDeploymentStack -WhatIf` |
| 264 | + - `New-AzSubscriptionDeploymentStack -WhatIf` |
| 265 | + - `Set-AzSubscriptionDeploymentStack -WhatIf` |
| 266 | + - `New-AzManagementGroupDeploymentStack -WhatIf` (if you have MG access) |
| 267 | + - `Remove-AzResourceGroupDeploymentStack -WhatIf` |
| 268 | + |
| 269 | +2. **No actual changes occur** when using -WhatIf |
| 270 | + |
| 271 | +3. **Formatted output displays correctly**: |
| 272 | + - Legend with symbols |
| 273 | + - Stack changes section |
| 274 | + - Resource changes section (when applicable) |
| 275 | + - Proper color coding (if your terminal supports it) |
| 276 | + |
| 277 | +4. **Error handling**: |
| 278 | + - Graceful handling if What-If API is unavailable in your region |
| 279 | + - Clear error messages |
| 280 | + |
| 281 | +### Edge Cases to Test |
| 282 | +1. **Without -WhatIf**: Verify cmdlets still work normally (actually create/update stacks) |
| 283 | +2. **Invalid parameters**: Verify proper error messages |
| 284 | +3. **Non-existent resource group**: Verify appropriate error |
| 285 | +4. **Different ActionOnUnmanage values**: DetachAll, DeleteResources, DeleteAll |
| 286 | +5. **Different DenySettingsMode values**: None, DenyDelete, DenyWriteAndDelete |
| 287 | + |
| 288 | +## Reporting Issues |
| 289 | + |
| 290 | +When reporting issues, please include: |
| 291 | + |
| 292 | +1. **Command executed** (exact command with all parameters) |
| 293 | +2. **Expected behavior** (what you expected to see) |
| 294 | +3. **Actual behavior** (what actually happened) |
| 295 | +4. **Full output** (including verbose messages) |
| 296 | +5. **Error messages** (full stack trace if applicable) |
| 297 | +6. **Environment info**: |
| 298 | + - PowerShell version: `$PSVersionTable` |
| 299 | + - Azure region: `(Get-AzContext).Subscription.Name` |
| 300 | + - Module version: `(Get-Module Az.Resources).Version` |
| 301 | + |
| 302 | +## Success Criteria |
| 303 | + |
| 304 | +For bug bash to be successful, all scenarios should: |
| 305 | +- ? Execute without errors |
| 306 | +- ? Display formatted output with legend and symbols |
| 307 | +- ? NOT create/modify/delete actual resources when -WhatIf is used |
| 308 | +- ? Show appropriate changes in the output |
| 309 | +- ? Work consistently across different scopes (ResourceGroup, Subscription, ManagementGroup) |
| 310 | + |
| 311 | +## Cleanup |
| 312 | + |
| 313 | +After testing, clean up your resources: |
| 314 | +```powershell |
| 315 | +# Remove test stacks |
| 316 | +Remove-AzResourceGroupDeploymentStack -Name "test-stack-update" -ResourceGroupName "bugbash-deploystack-rg" -ActionOnUnmanage DeleteAll -Force |
| 317 | +
|
| 318 | +# Remove resource group (if you created it for testing) |
| 319 | +Remove-AzResourceGroup -Name "bugbash-deploystack-rg" -Force |
| 320 | +``` |
| 321 | + |
| 322 | +## Questions or Issues? |
| 323 | + |
| 324 | +Contact: [Your contact info] |
| 325 | +Branch: `anapandey/pwcmdlet` |
| 326 | +Commit: `f034eee9941` |
0 commit comments