|
| 1 | +$managementGroupId = "AzBlueprintAssignTest" |
| 2 | +$subscriptionId = "a1bfa635-f2bf-42f1-86b5-848c674fc321" |
| 3 | +$location = "West US" |
| 4 | +$blueprintName = "shenglol-ps-test-bp" |
| 5 | +$permanentAssignmentName = "shenglol-ps-test-permanent-assignment" |
| 6 | +$transientAssignmentName = "shenglol-ps-test-transient-assignment" |
| 7 | + |
| 8 | +<# |
| 9 | +.SYNOPSIS |
| 10 | +Test getting Blueprint assignments in a management group. |
| 11 | +#> |
| 12 | +function Test-GetAssignmentsInManagementGroup |
| 13 | +{ |
| 14 | + $assignments = Get-AzBlueprintAssignment -ManagementGroupId $managementGroupId |
| 15 | + Assert-True { $assignments.Count -ge 1 } |
| 16 | + |
| 17 | + $assignment = $assignments | where { $_.Name -eq $permanentAssignmentName } |
| 18 | + Assert-NotNull $assignment |
| 19 | +} |
| 20 | + |
| 21 | +<# |
| 22 | +.SYNOPSIS |
| 23 | +Test getting single Blueprint assignment in a management group. |
| 24 | +#> |
| 25 | +function Test-GetSingleAssignmentInManagementGroup |
| 26 | +{ |
| 27 | + $assignment = Get-AzBlueprintAssignment -Name $permanentAssignmentName -ManagementGroupId $managementGroupId |
| 28 | + Assert-NotNull $assignment |
| 29 | + Assert-AreEqual $permanentAssignmentName $assignment.Name |
| 30 | +} |
| 31 | + |
| 32 | +<# |
| 33 | +.SYNOPSIS |
| 34 | +Test creating a Blueprint assignment in a management group. |
| 35 | +#> |
| 36 | +function Test-CreateAssignmentInManagementGroup |
| 37 | +{ |
| 38 | + $blueprint = $blueprint = Get-AzBlueprint -Name $blueprintName -ManagementGroupId $managementGroupId |
| 39 | + $rgParameters = @{ProdRG=@{name='shenglol-ps-test-02';location='westus'}} |
| 40 | + |
| 41 | + $assignment = New-AzBlueprintAssignment ` |
| 42 | + -Name $transientAssignmentName ` |
| 43 | + -Location $location ` |
| 44 | + -Blueprint $blueprint ` |
| 45 | + -ResourceGroupParameter $rgParameters ` |
| 46 | + -ManagementGroupId $managementGroupId ` |
| 47 | + -SubscriptionId $subscriptionId |
| 48 | + |
| 49 | + Assert-NotNull $assignment |
| 50 | + Assert-AreEqual "Creating" $assignment.ProvisioningState |
| 51 | + |
| 52 | + $timeout = New-TimeSpan -Minutes 4 |
| 53 | + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
| 54 | + |
| 55 | + while ($assignment.ProvisioningState -ne "Succeeded" -and $assignment.ProvisioningState -ne "Failed" -and $stopwatch.elapsed -lt $timeout) |
| 56 | + { |
| 57 | + Wait-Seconds 10 |
| 58 | + $assignment = Get-AzBlueprintAssignment -Name $transientAssignmentName -ManagementGroupId $managementGroupId |
| 59 | + } |
| 60 | + |
| 61 | + Assert-AreEqual "Succeeded" $assignment.ProvisioningState |
| 62 | +} |
| 63 | + |
| 64 | +<# |
| 65 | +.SYNOPSIS |
| 66 | +Test updating a Blueprint assignment in a management group. |
| 67 | +#> |
| 68 | +function Test-updateAssignmentInManagementGroup |
| 69 | +{ |
| 70 | + $blueprint = $blueprint = Get-AzBlueprint -Name $blueprintName -ManagementGroupId $managementGroupId |
| 71 | + # Update resource group name. |
| 72 | + $rgParameters = @{ProdRG=@{name='shenglol-ps-test-03';location='westus'}} |
| 73 | + |
| 74 | + $assignment = Set-AzBlueprintAssignment ` |
| 75 | + -Name $transientAssignmentName ` |
| 76 | + -Location $location ` |
| 77 | + -Blueprint $blueprint ` |
| 78 | + -ResourceGroupParameter $rgParameters ` |
| 79 | + -ManagementGroupId $managementGroupId ` |
| 80 | + -SubscriptionId $subscriptionId |
| 81 | + |
| 82 | + Assert-NotNull $assignment |
| 83 | + Assert-AreEqual "Creating" $assignment.ProvisioningState |
| 84 | + |
| 85 | + $timeout = New-TimeSpan -Minutes 4 |
| 86 | + $stopwatch = [System.Diagnostics.Stopwatch]::StartNew() |
| 87 | + |
| 88 | + while ($assignment.ProvisioningState -ne "Succeeded" -and $assignment.ProvisioningState -ne "Failed" -and $stopwatch.elapsed -lt $timeout) |
| 89 | + { |
| 90 | + Wait-Seconds 10 |
| 91 | + $assignment = Get-AzBlueprintAssignment -Name $transientAssignmentName -ManagementGroupId $managementGroupId |
| 92 | + } |
| 93 | + |
| 94 | + Assert-AreEqual "Succeeded" $assignment.ProvisioningState |
| 95 | +} |
| 96 | + |
| 97 | +<# |
| 98 | +.SYNOPSIS |
| 99 | +Test removing a Blueprint assignment in a management group. |
| 100 | +#> |
| 101 | +function Test-RemoveAssignmentInManagementGroup |
| 102 | +{ |
| 103 | + $assignment = Remove-AzBlueprintAssignment ` |
| 104 | + -Name $transientAssignmentName ` |
| 105 | + -ManagementGroupId $managementGroupId ` |
| 106 | + -PassThru |
| 107 | + |
| 108 | + Assert-NotNull $assignment |
| 109 | + Assert-AreEqual "Deleting" $assignment.ProvisioningState |
| 110 | +} |
0 commit comments