Skip to content

Commit 204b6f3

Browse files
author
Hovsep
committed
Merge pull request Azure#2238 from TianoMS/tiano-d2
Enable object and array type parameters for template deployment
2 parents 9007a56 + 0eb165a commit 204b6f3

File tree

15 files changed

+4810
-94
lines changed

15 files changed

+4810
-94
lines changed

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@
255255
</ProjectReference>
256256
</ItemGroup>
257257
<ItemGroup>
258+
<None Include="complexParameters.json">
259+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
260+
</None>
261+
<None Include="complexParametersTemplate.json">
262+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
263+
</None>
258264
<None Include="KeyVaultSetupTemplate.json">
259265
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
260266
</None>
@@ -346,9 +352,21 @@
346352
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentFromTemplateFile.json">
347353
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
348354
</None>
355+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithComplexPramaters.json">
356+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
357+
</None>
358+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithDynamicParameters.json">
359+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
360+
</None>
361+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithInvalidParameters.json">
362+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
363+
</None>
349364
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithKeyVaultReference.json">
350365
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
351366
</None>
367+
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithParameterObject.json">
368+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
369+
</None>
352370
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestSaveDeploymentTemplateFile.json">
353371
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
354372
</None>

src/ResourceManager/Resources/Commands.Resources.Test/Models.ResourceGroups/GalleryTemplatesClientTests.cs

Lines changed: 180 additions & 66 deletions
Large diffs are not rendered by default.

src/ResourceManager/Resources/Commands.Resources.Test/Resources/sampleTemplateFile.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,17 @@
1111
"type": "int"
1212
},
1313
"bool": {
14-
"type": "bool"
15-
}
14+
"type": "bool"
15+
},
16+
"object": {
17+
"type": "object"
18+
},
19+
"secureObject": {
20+
"type": "secureObject"
21+
},
22+
"array": {
23+
"type": "array"
24+
}
1625
},
1726
"variables": {
1827
"string": "string",

src/ResourceManager/Resources/Commands.Resources.Test/Resources/sampleTemplateParameterFile.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,22 @@
88
"string" : {
99
"value" : "myvalue"
1010
},
11-
"int" : {
12-
"value" : 12
13-
}
11+
"int": {
12+
"value": 12
13+
},
14+
"object": {
15+
"value": {
16+
"code": "F1",
17+
"name": "Free"
18+
}
19+
},
20+
"secureObject": {
21+
"value": {
22+
"code": "F2",
23+
"name": "Standard"
24+
}
25+
},
26+
"array": {
27+
"value": [ "A", "D", "F" ]
28+
}
1429
}
Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
11
{
22
"$schema" : "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentParameter.json#",
33
"contentVersion" : "1.0.0.0",
4-
"parameters" : {
5-
"securestring" : {
6-
"value" : "myvalue"
7-
},
8-
"bool" : {
9-
"value" : "True"
10-
},
11-
"string" : {
12-
"value" : "myvalue"
13-
},
14-
"int" : {
15-
"value" : "12"
16-
}
17-
}
4+
"parameters": {
5+
"securestring": {
6+
"value": "myvalue"
7+
},
8+
"bool": {
9+
"value": "True"
10+
},
11+
"string": {
12+
"value": "myvalue"
13+
},
14+
"int": {
15+
"value": "12"
16+
},
17+
"object": {
18+
"value": {
19+
"code": "F1",
20+
"name": "Free"
21+
}
22+
},
23+
"secureObject": {
24+
"value": {
25+
"code": "F2",
26+
"name": "Standard"
27+
}
28+
},
29+
"array": {
30+
"value": [ "A", "D", "F" ]
31+
}
32+
}
1833
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,29 @@ public void TestNewDeploymentWithKeyVaultReference()
6060
{
6161
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithKeyVaultReference");
6262
}
63+
64+
[Fact]
65+
public void TestNewDeploymentWithComplexPramaters()
66+
{
67+
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithComplexPramaters");
68+
}
69+
70+
[Fact]
71+
public void TestNewDeploymentWithParameterObject()
72+
{
73+
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithParameterObject");
74+
}
75+
76+
[Fact]
77+
public void TestNewDeploymentWithDynamicParameters()
78+
{
79+
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithDynamicParameters");
80+
}
81+
82+
[Fact]
83+
public void TestNewDeploymentWithInvalidParameters()
84+
{
85+
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithInvalidParameters");
86+
}
6387
}
6488
}

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

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,135 @@ function Test-NewDeploymentWithKeyVaultReference
219219
Clean-ResourceGroup $rgname
220220
}
221221
}
222+
223+
<#
224+
.SYNOPSIS
225+
Tests deployment with template file with complex parameters.
226+
#>
227+
function Test-NewDeploymentWithComplexPramaters
228+
{
229+
# Setup
230+
$rgname = Get-ResourceGroupName
231+
$rname = Get-ResourceName
232+
$rglocation = "EastUS"
233+
234+
try
235+
{
236+
# Test
237+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
238+
239+
$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -TemplateParameterFile complexParameters.json
240+
241+
# Assert
242+
Assert-AreEqual Succeeded $deployment.ProvisioningState
243+
244+
$subId = (Get-AzureRmContext).Subscription.SubscriptionId
245+
$deploymentId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deployments/$rname"
246+
$getById = Get-AzureRmResourceGroupDeployment -Id $deploymentId
247+
Assert-AreEqual $getById.DeploymentName $deployment.DeploymentName
248+
}
249+
250+
finally
251+
{
252+
# Cleanup
253+
Clean-ResourceGroup $rgname
254+
}
255+
}
256+
257+
<#
258+
.SYNOPSIS
259+
Tests deployment with template file with parameter object.
260+
#>
261+
function Test-NewDeploymentWithParameterObject
262+
{
263+
# Setup
264+
$rgname = Get-ResourceGroupName
265+
$rname = Get-ResourceName
266+
$rglocation = "EastUS"
267+
268+
try
269+
{
270+
# Test
271+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
272+
273+
$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -TemplateParameterObject @{appSku=@{code="f1"; name="Free"}; servicePlan="plan1"; ranks=@("c", "d")}
274+
275+
# Assert
276+
Assert-AreEqual Succeeded $deployment.ProvisioningState
277+
278+
$subId = (Get-AzureRmContext).Subscription.SubscriptionId
279+
$deploymentId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deployments/$rname"
280+
$getById = Get-AzureRmResourceGroupDeployment -Id $deploymentId
281+
Assert-AreEqual $getById.DeploymentName $deployment.DeploymentName
282+
}
283+
284+
finally
285+
{
286+
# Cleanup
287+
Clean-ResourceGroup $rgname
288+
}
289+
}
290+
291+
<#
292+
.SYNOPSIS
293+
Tests deployment with template file with dynamic parameters.
294+
#>
295+
function Test-NewDeploymentWithDynamicParameters
296+
{
297+
# Setup
298+
$rgname = Get-ResourceGroupName
299+
$rname = Get-ResourceName
300+
$rglocation = "EastUS"
301+
302+
try
303+
{
304+
# Test
305+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
306+
307+
$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -appSku @{code="f3"; name=@{major="Official"; minor="1.0"}} -servicePlan "plan1" -ranks @("c", "d")
308+
309+
# Assert
310+
Assert-AreEqual Succeeded $deployment.ProvisioningState
311+
312+
$subId = (Get-AzureRmContext).Subscription.SubscriptionId
313+
$deploymentId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deployments/$rname"
314+
$getById = Get-AzureRmResourceGroupDeployment -Id $deploymentId
315+
Assert-AreEqual $getById.DeploymentName $deployment.DeploymentName
316+
}
317+
318+
finally
319+
{
320+
# Cleanup
321+
Clean-ResourceGroup $rgname
322+
}
323+
}
324+
325+
<#
326+
.SYNOPSIS
327+
Tests error displayed for invalid parameters.
328+
#>
329+
function Test-NewDeploymentWithInvalidParameters
330+
{
331+
# Setup
332+
$rgname = Get-ResourceGroupName
333+
$rname = Get-ResourceName
334+
$rglocation = "EastUS"
335+
336+
try
337+
{
338+
# Test
339+
$ErrorActionPreference = "SilentlyContinue"
340+
$Error.Clear()
341+
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
342+
$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -appSku @{code="f4"; name="Free"} -servicePlan "plan1"
343+
}
344+
catch
345+
{
346+
Assert-True { $Error[1].Contains("The parameter value is not part of the allowed value(s)") }
347+
}
348+
finally
349+
{
350+
# Cleanup
351+
Clean-ResourceGroup $rgname
352+
}
353+
}

0 commit comments

Comments
 (0)