Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
761 changes: 761 additions & 0 deletions DEPLOYMENT_STACKS_WHATIF_MODELS_GUIDE.md

Large diffs are not rendered by default.

326 changes: 326 additions & 0 deletions bugbash-templates/BUGBASH_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
# Deployment Stacks WhatIf Bug Bash Guide

## Overview
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.

## Prerequisites

1. **Azure Subscription** with access to create resources
2. **PowerShell 7+** installed (`pwsh --version`)
3. **Az.Accounts module** (for authentication)
4. **Resource Group** for testing (or permissions to create one)

## Setup Instructions

### 1. Get the Code
```powershell
# Clone the branch (if you haven't already)
git clone https://github.com/anamikapan11/azure-powershell
cd azure-powershell
git checkout anapandey/pwcmdlet

# OR if you already have it cloned
git fetch origin
git checkout anapandey/pwcmdlet
git pull origin anapandey/pwcmdlet
```

### 2. Build the Module
```powershell
# Build just the Resources module (takes 5-10 minutes)
dotnet msbuild build.proj /p:Scope=Resources
```

**Note**: This will take 5-10 minutes. Do not cancel the build.

### 3. Load the Built Module
```powershell
# Remove any existing Az.Resources module
Remove-Module Az.Resources, Az.Accounts -Force -ErrorAction SilentlyContinue

# Import the debug version you just built
Import-Module ./artifacts/Debug/Az.Accounts/Az.Accounts.psd1 -Force
Import-Module ./artifacts/Debug/Az.Resources/Az.Resources.psd1 -Force

# Verify the cmdlets are available
Get-Command -Module Az.Resources -Name "*DeploymentStack*"
```

### 4. Authenticate to Azure
```powershell
# Login to your Azure subscription
Connect-AzAccount

# Set the subscription you want to use for testing
Set-AzContext -SubscriptionId "<your-subscription-id>"
```

### 5. Create Test Resources
```powershell
# Create a resource group for testing (if you don't have one)
New-AzResourceGroup -Name "bugbash-deploystack-rg" -Location "eastus"
```

## Test Scenarios

### Scenario 1: Basic WhatIf - Empty Template

**Purpose**: Verify WhatIf shows stack property changes (DenySettings, ActionOnUnmanage)

**Template** (`empty-template.json`):
```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": []
}
```

**Test Command**:
```powershell
New-AzResourceGroupDeploymentStack `
-Name "test-stack-empty" `
-ResourceGroupName "bugbash-deploystack-rg" `
-TemplateFile ./empty-template.json `
-ActionOnUnmanage DetachAll `
-DenySettingsMode None `
-WhatIf `
-Verbose
```

**Expected Output**:
- ? Legend showing symbols (+ Create, ~ Modify, - Delete, v Detach, = NoChange)
- ? "Changes to Stack" section showing DenySettings changes
- ? No errors or exceptions
- ? No actual resources created

### Scenario 2: WhatIf with Resources

**Purpose**: Verify WhatIf shows managed resource changes

**Template** (`template-with-resources.json`):
```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountName": {
"type": "string",
"defaultValue": "[concat('storage', uniqueString(resourceGroup().id))]"
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2021-04-01",
"name": "[parameters('storageAccountName')]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2"
}
]
}
```

**Test Command**:
```powershell
New-AzResourceGroupDeploymentStack `
-Name "test-stack-storage" `
-ResourceGroupName "bugbash-deploystack-rg" `
-TemplateFile ./template-with-resources.json `
-ActionOnUnmanage DetachAll `
-DenySettingsMode None `
-WhatIf `
-Verbose
```

**Expected Output**:
- ? Legend showing symbols
- ? "Changes to Stack" section
- ? "Changes to Managed Resources" section showing storage account creation
- ? Management Status changes (null ? "Managed")
- ? No actual resources created

### Scenario 3: Set-AzResourceGroupDeploymentStack with WhatIf

**Purpose**: Verify WhatIf works for updating existing stacks

**Pre-requisite**: Create a stack first (without -WhatIf):
```powershell
New-AzResourceGroupDeploymentStack `
-Name "test-stack-update" `
-ResourceGroupName "bugbash-deploystack-rg" `
-TemplateFile ./empty-template.json `
-ActionOnUnmanage DetachAll `
-DenySettingsMode None
```

**Test Command**:
```powershell
Set-AzResourceGroupDeploymentStack `
-Name "test-stack-update" `
-ResourceGroupName "bugbash-deploystack-rg" `
-TemplateFile ./empty-template.json `
-ActionOnUnmanage DeleteAll `
-DenySettingsMode DenyDelete `
-WhatIf `
-Verbose
```

**Expected Output**:
- ? Shows changes to ActionOnUnmanage (DetachAll ? DeleteAll)
- ? Shows changes to DenySettingsMode (None ? DenyDelete)
- ? No actual stack update performed

### Scenario 4: Subscription-Level WhatIf

**Purpose**: Verify WhatIf works at subscription scope

**Template** (`sub-template.json`):
```json
{
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2021-04-01",
"name": "test-rg-from-stack",
"location": "eastus",
"properties": {}
}
]
}
```

**Test Command**:
```powershell
New-AzSubscriptionDeploymentStack `
-Name "test-stack-sub" `
-Location "eastus" `
-TemplateFile ./sub-template.json `
-ActionOnUnmanage DetachAll `
-DenySettingsMode None `
-WhatIf `
-Verbose
```

**Expected Output**:
- ? Formatted output with legend
- ? Shows resource group creation
- ? No actual resources created

### Scenario 5: Remove with WhatIf

**Purpose**: Verify WhatIf works for deletion

**Pre-requisite**: Ensure stack exists from previous tests

**Test Command**:
```powershell
Remove-AzResourceGroupDeploymentStack `
-Name "test-stack-update" `
-ResourceGroupName "bugbash-deploystack-rg" `
-ActionOnUnmanage DetachAll `
-WhatIf `
-Verbose
```

**Expected Output**:
- ? "What if: Performing the operation..." message
- ? No actual deletion performed

### Scenario 6: WhatIf with DenySettings Changes

**Purpose**: Verify WhatIf shows DenySettings configuration changes

**Test Command**:
```powershell
New-AzResourceGroupDeploymentStack `
-Name "test-stack-denysettings" `
-ResourceGroupName "bugbash-deploystack-rg" `
-TemplateFile ./empty-template.json `
-ActionOnUnmanage DetachAll `
-DenySettingsMode DenyWriteAndDelete `
-DenySettingsApplyToChildScopes `
-DenySettingsExcludedPrincipal @("00000000-0000-0000-0000-000000000000") `
-WhatIf `
-Verbose
```

**Expected Output**:
- ? Shows DenySettings.Mode creation
- ? Shows DenySettings.ApplyToChildScopes
- ? Shows ExcludedPrincipals array

## What to Test

### Functional Testing
1. **All cmdlets work with -WhatIf**:
- `New-AzResourceGroupDeploymentStack -WhatIf`
- `Set-AzResourceGroupDeploymentStack -WhatIf`
- `New-AzSubscriptionDeploymentStack -WhatIf`
- `Set-AzSubscriptionDeploymentStack -WhatIf`
- `New-AzManagementGroupDeploymentStack -WhatIf` (if you have MG access)
- `Remove-AzResourceGroupDeploymentStack -WhatIf`

2. **No actual changes occur** when using -WhatIf

3. **Formatted output displays correctly**:
- Legend with symbols
- Stack changes section
- Resource changes section (when applicable)
- Proper color coding (if your terminal supports it)

4. **Error handling**:
- Graceful handling if What-If API is unavailable in your region
- Clear error messages

### Edge Cases to Test
1. **Without -WhatIf**: Verify cmdlets still work normally (actually create/update stacks)
2. **Invalid parameters**: Verify proper error messages
3. **Non-existent resource group**: Verify appropriate error
4. **Different ActionOnUnmanage values**: DetachAll, DeleteResources, DeleteAll
5. **Different DenySettingsMode values**: None, DenyDelete, DenyWriteAndDelete

## Reporting Issues

When reporting issues, please include:

1. **Command executed** (exact command with all parameters)
2. **Expected behavior** (what you expected to see)
3. **Actual behavior** (what actually happened)
4. **Full output** (including verbose messages)
5. **Error messages** (full stack trace if applicable)
6. **Environment info**:
- PowerShell version: `$PSVersionTable`
- Azure region: `(Get-AzContext).Subscription.Name`
- Module version: `(Get-Module Az.Resources).Version`

## Success Criteria

For bug bash to be successful, all scenarios should:
- ? Execute without errors
- ? Display formatted output with legend and symbols
- ? NOT create/modify/delete actual resources when -WhatIf is used
- ? Show appropriate changes in the output
- ? Work consistently across different scopes (ResourceGroup, Subscription, ManagementGroup)

## Cleanup

After testing, clean up your resources:
```powershell
# Remove test stacks
Remove-AzResourceGroupDeploymentStack -Name "test-stack-update" -ResourceGroupName "bugbash-deploystack-rg" -ActionOnUnmanage DeleteAll -Force

# Remove resource group (if you created it for testing)
Remove-AzResourceGroup -Name "bugbash-deploystack-rg" -Force
```

## Questions or Issues?

Contact: [Your contact info]
Branch: `anapandey/pwcmdlet`
Commit: `f034eee9941`
Loading
Loading