Skip to content

Commit 6a5d296

Browse files
authored
Fixed issues with TemplateSpec deployments in New-AzTenantDeployment … (#14179)
* Fixed issues with TemplateSpec deployments in New-AzTenantDeployment and New-AzManagementGroupDeployment * Review fixes * Modified and re-recorded Test-NewMGDeploymentFromTemplateSpec
1 parent 8dbbb6a commit 6a5d296

File tree

11 files changed

+15223
-0
lines changed

11 files changed

+15223
-0
lines changed

src/Resources/ResourceManager/Implementation/Deployments/NewAzureManagementGroupDeploymentCmdlet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public class NewAzureManagementGroupDeploymentCmdlet : DeploymentCreateCmdlet
8282
QueryString = this.QueryString,
8383
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
8484
TemplateObject = this.TemplateObject,
85+
TemplateSpecId = TemplateSpecId,
8586
TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
8687
ParameterUri = this.TemplateParameterUri,
8788
DeploymentDebugLogLevel = this.GetDeploymentDebugLogLevel(this.DeploymentDebugLogLevel),
@@ -94,6 +95,7 @@ public class NewAzureManagementGroupDeploymentCmdlet : DeploymentCreateCmdlet
9495
deploymentName: this.Name,
9596
location: this.Location,
9697
mode: DeploymentMode.Incremental,
98+
templateSpecId: TemplateSpecId,
9799
queryString: this.QueryString,
98100
templateUri: this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
99101
templateObject: this.TemplateObject,

src/Resources/ResourceManager/Implementation/Deployments/NewAzureTenantDeploymentCmdlet.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public class NewAzureTenantDeploymentCmdlet: DeploymentCreateCmdlet
7777
QueryString = this.QueryString,
7878
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
7979
TemplateObject = this.TemplateObject,
80+
TemplateSpecId = this.TemplateSpecId,
8081
TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
8182
ParameterUri = this.TemplateParameterUri,
8283
DeploymentDebugLogLevel = GetDeploymentDebugLogLevel(this.DeploymentDebugLogLevel),
@@ -91,6 +92,7 @@ public class NewAzureTenantDeploymentCmdlet: DeploymentCreateCmdlet
9192
queryString: this.QueryString,
9293
templateUri : TemplateUri ?? this.TryResolvePath(TemplateFile),
9394
templateObject : this.TemplateObject,
95+
templateSpecId: TemplateSpecId,
9496
templateParametersUri : this.TemplateParameterUri,
9597
templateParametersObject : GetTemplateParameterObject(this.TemplateParameterObject),
9698
resultFormat : this.WhatIfResultFormat,

src/Resources/Resources.Test/ScenarioTests/DeploymentTests.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@ public void TestNewDeploymentTemplateSpec()
5555
TestRunner.RunTestScript("Test-NewDeploymentFromTemplateSpec");
5656
}
5757

58+
[Fact]
59+
[Trait(Category.AcceptanceType, Category.CheckIn)]
60+
[Trait(Category.RunType, Category.CoreOnly)]
61+
public void TestNewSubscriptionDeploymentTemplateSpec()
62+
{
63+
TestRunner.RunTestScript("Test-NewSubscriptionDeploymentFromTemplateSpec");
64+
}
65+
66+
[Fact]
67+
[Trait(Category.AcceptanceType, Category.CheckIn)]
68+
[Trait(Category.RunType, Category.CoreOnly)]
69+
public void TestNewFailedSubscriptionDeploymentTemplateSpec()
70+
{
71+
TestRunner.RunTestScript("Test-NewFailedSubscriptionDeploymentFromTemplateSpec");
72+
}
73+
74+
[Fact]
75+
[Trait(Category.AcceptanceType, Category.CheckIn)]
76+
[Trait(Category.RunType, Category.CoreOnly)]
77+
public void TestNewMGDeploymentTemplateSpec()
78+
{
79+
TestRunner.RunTestScript("Test-NewMGDeploymentFromTemplateSpec");
80+
}
81+
82+
[Fact]
83+
[Trait(Category.AcceptanceType, Category.CheckIn)]
84+
[Trait(Category.RunType, Category.CoreOnly)]
85+
public void TestNewTenantDeploymentTemplateSpec()
86+
{
87+
TestRunner.RunTestScript("Test-NewTenantDeploymentFromTemplateSpec");
88+
}
89+
5890
[Fact]
5991
[Trait(Category.AcceptanceType, Category.CheckIn)]
6092
public void TestTestResourceGroupDeploymentErrors()

src/Resources/Resources.Test/ScenarioTests/DeploymentTests.ps1

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,155 @@ function Test-NewDeploymentFromTemplateSpec
146146
}
147147
}
148148

149+
function Test-NewSubscriptionDeploymentFromTemplateSpec
150+
{
151+
# Setup
152+
$rgname = Get-ResourceGroupName
153+
$rname = Get-ResourceName
154+
$rglocation = "West US 2"
155+
$subId = (Get-AzContext).Subscription.SubscriptionId
156+
157+
try
158+
{
159+
# Prepare our RG and basic template spec:
160+
161+
New-AzResourceGroup -Name $rgname -Location $rglocation
162+
163+
$sampleTemplateJson = Get-Content -Raw -Path "subscription_level_template.json"
164+
$basicCreatedTemplateSpec = New-AzTemplateSpec -ResourceGroupName $rgname -Name $rname -Location $rgLocation -Version "v1" -TemplateJson $sampleTemplateJson
165+
166+
$resourceId = $basicCreatedTemplateSpec.Id + "/versions/v1"
167+
168+
#Create deployment
169+
$deployment = New-AzSubscriptionDeployment -Name $rname -TemplateSpecId $resourceId -TemplateParameterFile "subscription_level_parameters.json" -Location $rglocation
170+
171+
# Assert
172+
Assert-AreEqual Succeeded $deployment.ProvisioningState
173+
174+
}
175+
176+
finally
177+
{
178+
# Cleanup
179+
Clean-DeploymentAtSubscription $deployment
180+
Clean-ResourceGroup $rgname
181+
}
182+
}
183+
184+
function Test-NewFailedSubscriptionDeploymentFromTemplateSpec
185+
{
186+
# Setup
187+
$rgname = Get-ResourceGroupName
188+
$rname = Get-ResourceName
189+
$rglocation = "West US 2"
190+
$subId = (Get-AzContext).Subscription.SubscriptionId
191+
192+
try
193+
{
194+
# Prepare our RG and basic template spec:
195+
196+
New-AzResourceGroup -Name $rgname -Location $rglocation
197+
198+
#Use template that will fail at subscription scope
199+
$sampleTemplateJson = Get-Content -Raw -Path "subscription_level_template.json"
200+
$basicCreatedTemplateSpec = New-AzTemplateSpec -ResourceGroupName $rgname -Name $rname -Location $rgLocation -Version "v1" -TemplateJson $sampleTemplateJson
201+
202+
$resourceId = $basicCreatedTemplateSpec.Id + "/versions/v1"
203+
204+
#Create deployment
205+
try {
206+
$deployment = New-AzSubscriptionDeployment -Name $rname -TemplateSpecId $resourceId -TemplateParameterFile "subscription_level_parameters.json" -Location $rglocation
207+
}
208+
Catch {
209+
Assert-True { $Error[0].Contains("ResourceNotFound")}
210+
}
211+
212+
}
213+
214+
finally
215+
{
216+
# Cleanup
217+
Clean-DeploymentAtSubscription $deployment
218+
Clean-ResourceGroup $rgname
219+
}
220+
}
221+
222+
function Test-NewMGDeploymentFromTemplateSpec
223+
{
224+
# Setup
225+
$rgname = Get-ResourceGroupName
226+
$rname = Get-ResourceName
227+
$managementGroupId = Get-ResourceName
228+
$rglocation = "West US 2"
229+
$subId = (Get-AzContext).Subscription.SubscriptionId
230+
231+
try
232+
{
233+
#Create New MG
234+
New-AzManagementGroup -GroupName $managementGroupId -ParentId "/providers/Microsoft.Management/managementGroups/AzDeploymentsPSTest"
235+
236+
# Prepare our RG and basic template spec:
237+
238+
New-AzResourceGroup -Name $rgname -Location $rglocation
239+
240+
$sampleTemplateJson = Get-Content -Raw -Path "simpleTemplate.json"
241+
$basicCreatedTemplateSpec = New-AzTemplateSpec -ResourceGroupName $rgname -Name $rname -Location $rgLocation -Version "v1" -TemplateJson $sampleTemplateJson
242+
243+
$resourceId = $basicCreatedTemplateSpec.Id + "/versions/v1"
244+
245+
#Create deployment
246+
$deployment = New-AzManagementGroupDeployment -ManagementGroupId $managementGroupId -Name $rname -TemplateSpecId $resourceId -TemplateParameterFile "simpleTemplateParams.json" -Location $rglocation
247+
248+
# Assert
249+
Assert-AreEqual Succeeded $deployment.ProvisioningState
250+
251+
}
252+
253+
finally
254+
{
255+
# Cleanup
256+
Remove-AzManagementGroupDeployment -ManagementGroup $managementGroupId -Name $rname
257+
Clean-ResourceGroup $rgname
258+
Remove-AzManagementGroup -GroupName $managementGroupId
259+
}
260+
}
261+
262+
function Test-NewTenantDeploymentFromTemplateSpec
263+
{
264+
# Setup
265+
$rgname = Get-ResourceGroupName
266+
$rname = Get-ResourceName
267+
$rglocation = "West US 2"
268+
$subId = (Get-AzContext).Subscription.SubscriptionId
269+
270+
try
271+
{
272+
# Prepare our RG and basic template spec:
273+
274+
New-AzResourceGroup -Name $rgname -Location $rglocation
275+
276+
$sampleTemplateJson = Get-Content -Raw -Path "simpleTemplate.json"
277+
$basicCreatedTemplateSpec = New-AzTemplateSpec -ResourceGroupName $rgname -Name $rname -Location $rgLocation -Version "v1" -TemplateJson $sampleTemplateJson
278+
279+
$resourceId = $basicCreatedTemplateSpec.Id + "/versions/v1"
280+
281+
#Create deployment
282+
$deployment = New-AzTenantDeployment -Name $rname -TemplateSpecId $resourceId -TemplateParameterFile "simpleTemplateParams.json" -Location $rglocation
283+
284+
# Assert
285+
Assert-AreEqual Succeeded $deployment.ProvisioningState
286+
287+
}
288+
289+
finally
290+
{
291+
# Cleanup
292+
Clean-ResourceGroup $rgname
293+
Remove-AzTenantDeployment -Name $rname
294+
Clean-DeploymentAtTenant $rname
295+
}
296+
}
297+
149298
function Test-NewDeploymentFromTemplateObject
150299
{
151300
# Setup

0 commit comments

Comments
 (0)