Skip to content

Commit ac66d5b

Browse files
authored
[Blueprint] Add management group level assignment support (#11582)
* Update Blueprint SDK to the latest version. * Fix a parameter name. * PSBlueprintAssignment.FromAssignment now takes scope from Assignment. * Fix a parameter name. * Add MG level assignment support to existing cmdlets. * Update help docs.
1 parent 2b16f96 commit ac66d5b

40 files changed

+2253
-662
lines changed

src/Blueprint/Blueprint.Test/Blueprint.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<None Remove="UnitTests\**" />
1616
</ItemGroup>
1717
<ItemGroup>
18-
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.14.0-preview" />
18+
<PackageReference Include="Microsoft.Azure.Management.Blueprint" Version="0.20.6-preview" />
1919
</ItemGroup>
2020
<ItemGroup>
2121
<ProjectReference Include="..\Blueprint\Blueprint.csproj" />
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace Microsoft.Azure.Commands.Blueprint.Test.ScenarioTests
2+
{
3+
using Microsoft.Azure.Commands.ScenarioTest;
4+
using Microsoft.Azure.ServiceManagement.Common.Models;
5+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
9+
public class ManagementGroupAssignmentTests
10+
{
11+
private XunitTracingInterceptor logger;
12+
13+
public ManagementGroupAssignmentTests(ITestOutputHelper output)
14+
{
15+
16+
this.logger = new XunitTracingInterceptor(output);
17+
XunitTracingInterceptor.AddToContext(this.logger);
18+
TestExecutionHelpers.SetUpSessionAndProfile();
19+
}
20+
21+
[Fact]
22+
[Trait(Category.AcceptanceType, Category.CheckIn)]
23+
public void TestGetAssignmentsInManagementGroup()
24+
{
25+
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-GetAssignmentsInManagementGroup");
26+
}
27+
28+
[Fact]
29+
[Trait(Category.AcceptanceType, Category.CheckIn)]
30+
public void TestGetSingleAssignmentInManagementGroup()
31+
{
32+
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-GetSingleAssignmentInManagementGroup");
33+
}
34+
35+
[Fact(Skip = "Investigate auto-registration for RP")]
36+
[Trait(Category.AcceptanceType, Category.CheckIn)]
37+
public void TestCreateAssignmentInManagementGroup()
38+
{
39+
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-CreateAssignmentInManagementGroup");
40+
}
41+
42+
[Fact(Skip = "Investigate auto-registration for RP")]
43+
[Trait(Category.AcceptanceType, Category.CheckIn)]
44+
public void TestUpdateAssignmentInManagementGroup()
45+
{
46+
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-UpdateAssignmentInManagementGroup");
47+
}
48+
49+
[Fact]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
public void TestRemoveAssignmentInManagementGroup()
52+
{
53+
TestController.NewInstance.RunPowerShellTest(this.logger, "Test-RemoveAssignmentInManagementGroup");
54+
}
55+
}
56+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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

Comments
 (0)