【问题标题】:Multiple IP address variable in Azure ARM TemplateAzure ARM 模板中的多个 IP 地址变量
【发布时间】:2022-12-23 12:36:19
【问题描述】:

如果我使用 ARM 模板在 Azure 中创建 IP 组并希望将多个 IP 地址添加为参数而不是将它们放入资源主体中,这可能吗?

模板如下

{
  "type": "Microsoft.Network/ipGroups",
  "apiVersion": "2021-05-01",
  "name": "string",
  "location": "string",
  "tags": {
    "tagName1": "tagValue1",
    "tagName2": "tagValue2"
  },
  "properties": {
    "ipAddresses": [ "10.10.10.10",
      "10.10.10.11" ]
  }
}

如果我创建如下所示的参数

        "ipgipaddress": {
            "type": "string
            "Value": 
                "10.10.10.10",
                "10.10.10.11"
        }

并将代码更新为

{
  "type": "Microsoft.Network/ipGroups",
  "apiVersion": "2021-05-01",
  "name": "string",
  "location": "string",
  "tags": {
    "tagName1": "tagValue1",
    "tagName2": "tagValue2"
  },
  "properties": {
    "ipAddresses": "[parameters('ipgroupsettings')]"
  }
}

【问题讨论】:

    标签: json azure azure-resource-manager


    【解决方案1】:

    想要添加多个 IP 地址作为参数而不是将 他们在资源的正文中这可能吗?

    是的,您可以添加多个 IP 地址作为参数。根据documentation,属性ipAddresses 是字符串数组类型。

    为了重现这一点,在我们的 ARM 模板中,我们将那些 ipaddresses 初始化为数组类型的参数,并使用 "[paramerter(ipaddresses)]" 进一步传递这些值。

    我们已经对此进行了测试,它工作正常。

    这是ARM模板:

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "ipaddress":{
                "type": "array",
                "defaultValue": ["10.0.1.0/27","10.0.2.0/27"]
            }
        },
        "functions": [],
        "variables": {},
        "resources": [{
            "type": "Microsoft.Network/ipGroups",
            "apiVersion": "2020-11-01",
            "name": "testipgroups",
            "location":"[resourceGroup().location]",
            "properties":{
                "ipAddresses": "[parameters('ipaddress')]"
            }
        }
        ],
        "outputs": {}
    }
    

    这是示例输出以供参考:

    【讨论】:

      【解决方案2】:
          {
          "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
              "ipaddress":{
                  "type": "string",
                  "defaultValue": "10.0.1.0/27,10.0.2.0/27"
              }
          },
          "functions": [],
          "variables": {
            "iparray": "[split(parameters('ipaddress'),',')]"
      
           },
          "resources": [{
              "type": "Microsoft.Network/ipGroups",
              "apiVersion": "2020-11-01",
              "name": "testipgroups",
              "location":"[resourceGroup().location]",
              "properties":{
                  "ipAddresses": "[variables('iparray')]"
              }
          }
          ],
          "outputs": {}
         }
      

      如果您想节省时间以不带太多双引号 (" ") 的字符串形式提供输入,请使用拆分函数并删除定界符(上例中的逗号),这将创建一个 IP 数组。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多