-1

Have a question about ARM template deployment, specifically calling that deployment from Runbook Powershell workflow using New-AzureRmResourceGroupDeployment cmdlet. I am trying to use dynamic copy loop in in doing so I am using following formatted parameter in the template:

"aseApAppSettings": {
    "type": "object",
    "defaultValue": {
        "apps": [
            {
                "name": "app-api-ecom",
                "kind": "api"
            },
            {
                "name": "app-ecom",
                "kind": "web"
            }
        ]
    }
},

Then I create resources based on that:

    {
        "type": "Microsoft.Web/sites",
        "kind": "[parameters('aseApAppSettings').apps[copyIndex()].kind]",
        "name": "[concat(parameters('aseApName'),'sv-',parameters('aseApAppSettings').apps[copyIndex()].name)]",
        "apiVersion": "2016-08-01",
        "location": "East US 2",
        "scale": null,
        "properties": {...
        },
        "copy": {
            "name": "svLoop",
            "count": "[length(parameters('aseApAppSettings').apps)]"
        },
        "dependsOn": []
    },

All works when template is deployed through Template Deployment

I need to call for this deployment from Powershell Workflow runbook and having tough time defining the parameter

I've tried setting it as

{"apps":[{"name":"falcon-api-ecom","kind":"api"},{"name":"falcon-ecom","kind":"web"}]}

during test but it fails with message "Cannot find parameter"

So I have tried using ConvertFrom-Json

But it sends this to my template

"CliXml": "<Objs Version=\"1.1.0.1\" 

                          xmlns=\"http://schemas.microsoft.com/powers...

Please help,

Thanks

Sample from Runbook

workflow Build-Ase {
    param
    (
        #Environment Parameters
        [Parameter(Mandatory = $true)]
        [object]
        $aseApAppSettings
    )

    $params = @{
        "aseApAppSettings"       = $aseApAppSettings;
    }
    $job = New-AzureRmResourceGroupDeployment -ResourceGroupName $vnetRGName -TemplateUri $templateParameterUri -TemplateParameterObject $params
    Write-Output $job
old_timer
  • 69,149
  • 8
  • 89
  • 168

2 Answers2

1

Nested objects didn't work for me either, but passing them in as a json string combined with the json function did work for me

Deployment script

$addionalParameters = New-Object -TypeName Hashtable

$addionalParameter1 = "{ ""prop1"": [ { ""name"": ""a"", ""value"": ""1"" }, { ""name"": ""b"", ""value"": ""2"" } ], ""prop2"": { ""name"": ""c"", ""value"": ""3"" } }"
$addionalParameters["myComplexNestedOnjectAsJsonString"] = $addionalParameter1

$deploymentOutput = New-AzResourceGroupDeployment   -ResourceGroupName $resourceGroupName -Name $deploymentName -TemplateFile $templateFilePath `
                                                    -TemplateParameterFile $parametersFilePath @addionalParameters

Template

{
    "parameters": {
        "myComplexNestedObjectAsJsonString": {
            "type": "string"
        }
    },
    "variables": {
        "myComplexNestedObject" : "[json(parameters('myComplexNestedObjectAsJsonString'))]"
    },
    "resources": [],
    "outputs": {
        "prop1A": {
            "type": "string",
            "value": "[variables('myComplexNestedObject').prop1[0].value]"
        },
        "prop2": {
            "type": "string",
            "value": "[variables('myComplexNestedObject').prop2.value]"
        }
    }
}
0

Try using splatting. For me its the only thing that works with complex nested parameter objects. Also note how the aseApAppSettings parameter is constructed.

$params = @{
    $aseApAppSettings = @{ @( {name=...;kind=...},{...},...,{...} ) }
}
New-AzureRmResourceGroupDeployment -ResourceGroupName $vnetRGName -TemplateUri $templateParameterUri @params

ps. ... represent placeholders

4c74356b41
  • 69,186
  • 6
  • 100
  • 141