将带有特殊参数的变量传递到ARM模板时出错

时间:2020-02-26 10:15:04

标签: azure arm arm-template

我有一个主模板和几个链接模板。我想传递带有特殊字符的参数并出现错误。谁知道怎么修它? 该问题是由最后链接的模板定义中的“ servicebus_1_connectionString”参数引起的。我提供了错误信息并修改了秘密中的几个字母,因此您可以概览一下,但仍然不会泄露我的秘密。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
    "parameters": {
        "containerUri": {
            "type": "string"
        },
        "containerSasToken": {
            "type": "string"
        }
    },
  "variables": {},
    "resources": [
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2017-05-10",
            "name": "AzureServiceBusLinkedTemplate",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[concat(parameters('containerUri'), 'Infrastructure/AzureServiceBus.json', parameters('containerSasToken'))]"
                }
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2017-05-10",
            "name": "AppFunctionsLinkedTemplate",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[concat(parameters('containerUri'), 'Infrastructure/AppFunctions.json', parameters('containerSasToken'))]"
                }
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2017-05-10",
            "name": "LogicAppLinkedTemplate",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[concat(parameters('containerUri'), 'LogicApp.json', parameters('containerSasToken'))]"
                },
                 "parameters": {
                "servicebus_1_connectionString": "[reference('AzureServiceBusLinkedTemplate').outputs.SBNamespaceDefaultConnectionString.value]"
            }
            },
            "dependsOn": [
                "AzureServiceBusLinkedTemplate"
            ]
        }
    ],
  "outputs": {
  }
}
2020-02-26T09:47:34.3751880Z ##[error]At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.
2020-02-26T09:47:34.3754763Z ##[error]Details:
2020-02-26T09:47:34.3758785Z ##[error]BadRequest: {
  "error": {
    "code": "InvalidRequestContent",
    "message": "The request content was invalid and could not be deserialized: 'Error converting value \"Endpoint=sb://myservicebusname.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=I/COoOJCWH/PFMab0dzpseIbfA3+0sQMUj33d71/Rg4=\" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Data.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.servicebus_1_connectionString', line 1, position 462.'."
  }
}
2020-02-26T09:47:34.3786900Z ##[error]Task failed while creating or updating the template deployment.

编辑: 我通过更改将参数传递给以下内容的方式来解决它:

       {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2017-05-10",
            "name": "LogicAppLinkedTemplate",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[concat(parameters('containerUri'), 'LogicApp.json', parameters('containerSasToken'))]"
                },
                "parameters": {
                    "servicebus_1_connectionString": {
                        "value": "[reference('AzureServiceBusLinkedTemplate').outputs.SBNamespaceDefaultConnectionString.value]"
                    },
                    "logicAppName": {
                        "value": "DeployedFromVS"
                    }
                }
            },
            "dependsOn": [
                "AzureServiceBusLinkedTemplate"
            ]
        }

2 个答案:

答案 0 :(得分:0)

几个选项:

  1. 更有意义,不要传递它,只需使用嵌套模板中的值
  2. 奖励:代替获取部署输出的值,而是在嵌套模板中获取连接字符串的值。更有意义,更安全
  3. base64对其进行编码,然后在嵌套模板中对其进行解码。有一个为此的base64encode \ decode函数

答案 1 :(得分:0)

我通过更改将参数传递给以下内容的方式来解决它:

   {
            "type": "Microsoft.Resources/deployments",
            "apiVersion": "2017-05-10",
            "name": "LogicAppLinkedTemplate",
            "properties": {
                "mode": "Incremental",
                "templateLink": {
                    "uri": "[concat(parameters('containerUri'), 'LogicApp.json', parameters('containerSasToken'))]"
                },
                "parameters": {
                    "servicebus_1_connectionString": {
                        "value": "[reference('AzureServiceBusLinkedTemplate').outputs.SBNamespaceDefaultConnectionString.value]"
                    },
                    "logicAppName": {
                        "value": "DeployedFromVS"
                    }
                }
            },
            "dependsOn": [
                "AzureServiceBusLinkedTemplate"
            ]
        }