Skip to content

Enable object and array type parameters for template deployment #2238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="complexParameters.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="complexParametersTemplate.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="KeyVaultSetupTemplate.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -346,9 +352,21 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentFromTemplateFile.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithComplexPramaters.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithDynamicParameters.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithInvalidParameters.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithKeyVaultReference.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestNewDeploymentWithParameterObject.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.DeploymentTests\TestSaveDeploymentTemplateFile.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,17 @@
"type": "int"
},
"bool": {
"type": "bool"
}
"type": "bool"
},
"object": {
"type": "object"
},
"secureObject": {
"type": "secureObject"
},
"array": {
"type": "array"
}
},
"variables": {
"string": "string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@
"string" : {
"value" : "myvalue"
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent! Thanks for adding these to our existing test.

"int" : {
"value" : 12
}
"int": {
"value": 12
},
"object": {
"value": {
"code": "F1",
"name": "Free"
}
},
"secureObject": {
"value": {
"code": "F2",
"name": "Standard"
}
},
"array": {
"value": [ "A", "D", "F" ]
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
{
"$schema" : "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentParameter.json#",
"contentVersion" : "1.0.0.0",
"parameters" : {
"securestring" : {
"value" : "myvalue"
},
"bool" : {
"value" : "True"
},
"string" : {
"value" : "myvalue"
},
"int" : {
"value" : "12"
}
}
"parameters": {
"securestring": {
"value": "myvalue"
},
"bool": {
"value": "True"
},
"string": {
"value": "myvalue"
},
"int": {
"value": "12"
},
"object": {
"value": {
"code": "F1",
"name": "Free"
}
},
"secureObject": {
"value": {
"code": "F2",
"name": "Standard"
}
},
"array": {
"value": [ "A", "D", "F" ]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,29 @@ public void TestNewDeploymentWithKeyVaultReference()
{
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithKeyVaultReference");
}

[Fact]
public void TestNewDeploymentWithComplexPramaters()
{
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithComplexPramaters");
}

[Fact]
public void TestNewDeploymentWithParameterObject()
{
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithParameterObject");
}

[Fact]
public void TestNewDeploymentWithDynamicParameters()
{
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithDynamicParameters");
}

[Fact]
public void TestNewDeploymentWithInvalidParameters()
{
ResourcesController.NewInstance.RunPsTest("Test-NewDeploymentWithInvalidParameters");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,135 @@ function Test-NewDeploymentWithKeyVaultReference
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests deployment with template file with complex parameters.
#>
function Test-NewDeploymentWithComplexPramaters
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "EastUS"

try
{
# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation

$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -TemplateParameterFile complexParameters.json

# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState

$subId = (Get-AzureRmContext).Subscription.SubscriptionId
$deploymentId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deployments/$rname"
$getById = Get-AzureRmResourceGroupDeployment -Id $deploymentId
Assert-AreEqual $getById.DeploymentName $deployment.DeploymentName
}

finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests deployment with template file with parameter object.
#>
function Test-NewDeploymentWithParameterObject
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "EastUS"

try
{
# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation

$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -TemplateParameterObject @{appSku=@{code="f1"; name="Free"}; servicePlan="plan1"; ranks=@("c", "d")}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState

$subId = (Get-AzureRmContext).Subscription.SubscriptionId
$deploymentId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deployments/$rname"
$getById = Get-AzureRmResourceGroupDeployment -Id $deploymentId
Assert-AreEqual $getById.DeploymentName $deployment.DeploymentName
}

finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests deployment with template file with dynamic parameters.
#>
function Test-NewDeploymentWithDynamicParameters
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "EastUS"

try
{
# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation

$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -appSku @{code="f3"; name=@{major="Official"; minor="1.0"}} -servicePlan "plan1" -ranks @("c", "d")

# Assert
Assert-AreEqual Succeeded $deployment.ProvisioningState

$subId = (Get-AzureRmContext).Subscription.SubscriptionId
$deploymentId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deployments/$rname"
$getById = Get-AzureRmResourceGroupDeployment -Id $deploymentId
Assert-AreEqual $getById.DeploymentName $deployment.DeploymentName
}

finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests error displayed for invalid parameters.
#>
function Test-NewDeploymentWithInvalidParameters
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = "EastUS"

try
{
# Test
$ErrorActionPreference = "SilentlyContinue"
$Error.Clear()
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
$deployment = New-AzureRmResourceGroupDeployment -Name $rname -ResourceGroupName $rgname -TemplateFile complexParametersTemplate.json -appSku @{code="f4"; name="Free"} -servicePlan "plan1"
}
catch
{
Assert-True { $Error[1].Contains("The parameter value is not part of the allowed value(s)") }
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}
Loading