【问题标题】:Deploy multiple resources using ARM Template使用 ARM 模板部署多个资源
【发布时间】:2020-06-21 10:20:29
【问题描述】:

我必须部署 2 个资源,并且我有一个 ARM 模板,如下所示:

Template.json

{
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "name": "Resource1",
  "properties": {
    "templateLink": {
      "uri": "Test.json"
    },
    "parameters": {
        "secretA": { "value": "" },
        "secretB": { "value": "" }
    }
  }
},
{
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "name": "Resource2",
  "properties": {
    "templateLink": {
      "uri": "Test.json"
    },
    "parameters": {
        "secretC": { "value": "" },
        "secretD": { "value": "" },
        "secretE": { "value": "" }
    }
  }
}

Test.json 如下所示:

Test.json

  "resources": 
   {
      "apiVersion": "2018-02-01",
      "type": "Microsoft.Web/sites",
      "name": "",
      "properties": {        
        "appSettings": {  
            //set secrets in this section
        }        
    }
  

我需要在 appSettings 中为 Resource1 设置 (i) secretA、secretB (ii) 在 appsettings 中为 Resource2 设置 secretC、secretD、secretE。

如何更新上述 ARM 模板以在 appSettings 中使用正确的机密部署 Resource1 和 Resource2?

例如:

Resource1 appSettings 应如下所示:

"appSettings": {
    {
      "name": "secretA",
      "value": ""
    },
    {
      "name": "secretB",
      "value": ""
    }
}

Resource2 appSettings 应如下所示:

"appSettings": {
    {
      "name": "secretC",
      "value": ""
    },
    {
      "name": "secretD",
      "value": ""
    },
    {
      "name": "secretE",
      "value": ""
    }
}

【问题讨论】:

  • 是的。您需要查看链接的手臂模板。
  • 您已经有秘密 A、B、C 或者您需要在模板中创建它们?
  • 我已经有秘密可用了。我需要根据 Resource 将正确的秘密传递给 appSettings。
  • 模板是声明性的,所以当你设置 appSettings 属性时,你会得到的只是秘密的一个子集......所以 Resource2 将替换 Resource1 的设置。如果您想在同一部署中“添加”,则需要在每次部署 test.json 时设置 all appSettings - 这是您的方案吗?
  • 请帮助我理解 - 每次部署 test.json 时设置所有 appSettings 是什么意思?

标签: azure azure-functions azure-resource-manager arm-template azure-function-app


【解决方案1】:

您可以添加一个数组参数。例如

resource1的参数如下

"parameters": {
    "secretSettings": {
        "value": [
            {
                "name": "secretA",
                "value": "",
                "slotSetting": false
            },
            {
                "name": "secretB",
                "value": "",
                "slotSetting": false
            }
        ]
    }
}

resource2的参数如下

"parameters": {
    "secretSettings": {
        "value": [
            {
                "name": "secretC",
                "value": "",
                "slotSetting": false
            },
            {
                "name": "secretD",
                "value": "",
                "slotSetting": false
            }
        ]
    }
}

然后可以参考资源模板中的参数。

"appSettings": "[parameters('secretSettings')]"

请帮助我理解 - 你所说的全部设置是什么意思 appSettings 每次部署 test.json 的时候?

这意味着新的appSettings将覆盖现有的appSettings,你应该在每次部署时在参数中添加所有你需要的appSettings。

【讨论】:

  • 非常感谢!快速提问 - 假设要在 Resource1 和 Resource2 中设置的一些秘密是相同的 - 例如,secretX、secretY、secretZ 需要在两个资源的 appSettings 中添加。两种资源的其他秘密是不同的(资源1的秘密A,秘密B,资源2的秘密C,秘密D),有没有办法在appSettings中设置这些秘密(秘密X,秘密Y,秘密Z)而不传递秘密设置参数,因为这两者都很常见资源?
  • @user989988 我认为我们需要在两个 appsettings 中添加它们。
  • 你能举个例子吗?对于常见的秘密,这将如何改变?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
  • 2020-07-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多