-1

对 ARM 模板部署有疑问,特别是使用 New-AzureRmResourceGroupDeployment cmdlet 从 Runbook Powershell 工作流调用该部署。我正在尝试使用动态复制循环,因此我在模板中使用以下格式化参数:

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

然后我基于此创建资源:

    {
        "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": []
    },

通过模板部署部署模板时所有工作

我需要从 Powershell Workflow Runbook 调用此部署,并且很难定义参数

我尝试将其设置为

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

在测试期间,但失败并显示消息“找不到参数”

所以我尝试使用ConvertFrom-Json

但它会将其发送到我的模板

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

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

请帮忙,

谢谢

来自 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
4

2 回答 2

1

嵌套对象对我也不起作用,但是将它们作为 json 字符串与json 函数相结合确实对我有用

部署脚本

$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

模板

{
    "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]"
        }
    }
}
于 2019-03-27T15:50:00.740 回答
0

尝试使用splatting。对我来说,它是唯一适用于复杂嵌套参数对象的东西。还要注意aseApAppSettings 参数是如何构造的。

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

附言。...代表占位符

于 2017-08-01T05:55:29.733 回答