|
| 1 | +<# |
| 2 | +.SYNOPSIS |
| 3 | +Test Blueprint assignment cmdlets. Get a single Blueprint and assignment it to a subscription and delete. |
| 4 | +#> |
| 5 | + |
| 6 | +function Test-GetBlueprintAssignment |
| 7 | +{ |
| 8 | + $assignments = Get-AzBlueprintAssignment |
| 9 | + |
| 10 | + Assert-True { $assignments.Count -ge 1 } |
| 11 | + Assert-NotNull $assignments[0].Name |
| 12 | + Assert-NotNull $assignments[0].Id |
| 13 | + Assert-NotNull $assignments[0].BlueprintId |
| 14 | + Assert-NotNull $assignments[0].Scope |
| 15 | + Assert-NotNull $assignments[0].Location |
| 16 | +} |
| 17 | + |
| 18 | +function Test-NewBlueprintAssignment |
| 19 | +{ |
| 20 | + $mgId = "AzBlueprintAssignTest" |
| 21 | + $blueprintName = "Filiz-Ps-Test1" |
| 22 | + $subscriptionId = "28cbf98f-381d-4425-9ac4-cf342dab9753" |
| 23 | + $assignmentName = "PS-ScenarioTest-NewAssignment" |
| 24 | + $location = "East US" |
| 25 | + $params = @{audituseofclassicvirtualmachines_effect='Audit'} |
| 26 | + $rg1 = @{name='bp-testrg';location='eastus'} |
| 27 | + $rgs = @{ResourceGroup=$rg1} |
| 28 | + $identity = "/subscriptions/996a2f3f-ee01-4ffd-9765-d2c3fc98f30a/resourceGroups/user-assigned-test/providers/Microsoft.ManagedIdentity/userAssignedIdentities/owner-identity" |
| 29 | + |
| 30 | + $blueprint = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName -LatestPublished |
| 31 | + Assert-NotNull $blueprint |
| 32 | + |
| 33 | + $assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity |
| 34 | + |
| 35 | + $expectedProvisioningState = "Creating" |
| 36 | + Assert-NotNull $assignment |
| 37 | + Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState |
| 38 | +} |
| 39 | + |
| 40 | +function Test-NewBlueprintAssignmentWithSystemAssignedIdentity |
| 41 | +{ |
| 42 | + $subscriptionId = "0b1f6471-1bf0-4dda-aec3-cb9272f09590" |
| 43 | + $assignmentName = "PS-ScenarioTest-NewSystemAssignedIdentityAssignment" |
| 44 | + $location = "West US" |
| 45 | + $blueprintName = "PS-SimpleBlueprintDefinition" |
| 46 | + |
| 47 | + #deploy blueprint |
| 48 | + $deployment = New-AzDeployment -Name $blueprintName -Location $location -TemplateFile SubscriptionLevelSimpleBlueprint.json |
| 49 | + Assert-AreEqual Succeeded $deployment.ProvisioningState |
| 50 | + |
| 51 | + $blueprint = Get-AzBlueprint -SubscriptionId $subscriptionId -Name $blueprintName -LatestPublished |
| 52 | + Assert-NotNull $blueprint |
| 53 | + |
| 54 | + $assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location |
| 55 | + Assert-NotNull $assignment |
| 56 | +} |
| 57 | + |
| 58 | +function Test-SetBlueprintAssignment |
| 59 | +{ |
| 60 | + $mgId = "AzBlueprintAssignTest" |
| 61 | + $blueprintName = "Filiz-Ps-Test1" |
| 62 | + $subscriptionId = "28cbf98f-381d-4425-9ac4-cf342dab9753" |
| 63 | + $assignmentName = "PS-ScenarioTest-SetAssignment" |
| 64 | + $location = "East US" |
| 65 | + $params = @{audituseofclassicvirtualmachines_effect='Audit'} |
| 66 | + $rg1 = @{name='bp-testrg';location='eastus'} |
| 67 | + $rgs = @{ResourceGroup=$rg1} |
| 68 | + $identity = "/subscriptions/996a2f3f-ee01-4ffd-9765-d2c3fc98f30a/resourceGroups/user-assigned-test/providers/Microsoft.ManagedIdentity/userAssignedIdentities/owner-identity" |
| 69 | + |
| 70 | + # Get the test blueprint |
| 71 | + $blueprint = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName -LatestPublished |
| 72 | + Assert-NotNull $blueprint |
| 73 | + |
| 74 | + # Assign blueprint |
| 75 | + $assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity |
| 76 | + $expectedProvisioningState = "Creating" |
| 77 | + Assert-NotNull $assignment |
| 78 | + Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState |
| 79 | + |
| 80 | + # Retrieve assigned blueprint |
| 81 | + $assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName |
| 82 | + # Wait till the provisioning state changes to succeeded |
| 83 | + $assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName |
| 84 | + while($assigned.ProvisioningState -eq "Creating" -or $assigned.ProvisioningState -eq "Deploying" -or $assigned.ProvisioningState -eq "Waiting") |
| 85 | + { |
| 86 | + Wait-Seconds 10 |
| 87 | + $assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName |
| 88 | + } |
| 89 | + |
| 90 | + #update rg name and re-assign |
| 91 | + $newTestRg = "bp-testrg-new" |
| 92 | + $rg1 = @{name= $newTestRg;location='eastus'} |
| 93 | + $rgs = @{ResourceGroup=$rg1} |
| 94 | + $assignment = Set-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity |
| 95 | + $expectedProvisioningState = "Creating" |
| 96 | + Assert-NotNull $assignment |
| 97 | + Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState |
| 98 | +} |
| 99 | + |
| 100 | +function Test-RemoveBlueprintAssignment |
| 101 | +{ |
| 102 | + $mgId = "AzBlueprintAssignTest" |
| 103 | + $blueprintName = "Filiz-Ps-Test1" |
| 104 | + $subscriptionId = "28cbf98f-381d-4425-9ac4-cf342dab9753" |
| 105 | + $assignmentName = "PS-ScenarioTest-RemoveAssignment" |
| 106 | + $location = "East US" |
| 107 | + $params = @{audituseofclassicvirtualmachines_effect='Audit'} |
| 108 | + $rg1 = @{name='bp-testrg';location='eastus'} |
| 109 | + $rgs = @{ResourceGroup=$rg1} |
| 110 | + $identity = "/subscriptions/996a2f3f-ee01-4ffd-9765-d2c3fc98f30a/resourceGroups/user-assigned-test/providers/Microsoft.ManagedIdentity/userAssignedIdentities/owner-identity" |
| 111 | + |
| 112 | + # Get the test blueprint |
| 113 | + $blueprint = Get-AzBlueprint -ManagementGroupId $mgId -Name $blueprintName -LatestPublished |
| 114 | + Assert-NotNull $blueprint |
| 115 | + |
| 116 | + # Assign blueprint |
| 117 | + $assignment = New-AzBlueprintAssignment -Name $assignmentName -Blueprint $blueprint -SubscriptionId $subscriptionId -Location $location -Parameter $params -ResourceGroup $rgs -UserAssignedIdentity $identity |
| 118 | + $expectedProvisioningState = "Creating" |
| 119 | + Assert-NotNull $assignment |
| 120 | + Assert-AreEqual $assignment.ProvisioningState $expectedProvisioningState |
| 121 | + |
| 122 | + # Retrieve assigned blueprint |
| 123 | + $assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName |
| 124 | + while($assigned.ProvisioningState -eq "Creating" -or $assigned.ProvisioningState -eq "Deploying" -or $assigned.ProvisioningState -eq "Waiting") |
| 125 | + { |
| 126 | + Wait-Seconds 10 |
| 127 | + $assigned = Get-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignmentName |
| 128 | + } |
| 129 | + |
| 130 | + # remove assignment |
| 131 | + $removed = Remove-AzBlueprintAssignment -SubscriptionId $subscriptionId -Name $assignment.Name -PassThru |
| 132 | + $expectedProvisioningState = "Deleting" |
| 133 | + Assert-NotNull $removed |
| 134 | + Assert-AreEqual $removed.Name $assignment.Name |
| 135 | + Assert-AreEqual $removed.ProvisioningState $expectedProvisioningState |
| 136 | +} |
| 137 | + |
0 commit comments