尝试使用 Azure ARM 中的引用函数基于资源 属性 创建防火墙规则时出现无效 Json 错误

invalid Json error when trying to use the reference function in Azure ARM to create firewall rules based on resource property

我正在创建 azure 防火墙 DNAT 规则作为 azure devops 管道的一部分。我不想手动指定 public IP,我想从 public 网卡的属性中提取这个值。这样,如果我们克隆或重建管道,就不必更新 IP 地址。

这只是 ARM 模板的摘录。第一个示例有效。

"destinationAddresses": [
            "52.180.91.89"
]

下面是我尝试替换它的尝试。请注意,public IP 是在 ARM 模板中创建的,因此我没有引用资源的完整路径。

"destinationAddresses": "[reference(variables('arm_firewall_buildagentip')).ipAddress]"

我收到的错误如下。它返回了正确的值,但我不确定如何格式化它才能在防火墙规则中被接受。

##[error]BadRequest: {
  "error": {
    "code": "InvalidRequestFormat",
    "message": "Cannot parse the request.",
    "details": [
      {
        "code": "InvalidJson",
        "message": "Error converting value \"52.180.91.89\" to type 'System.Collections.Generic.List`1[System.String]'. Path 'properties.natRuleCollections[0].properties.rules[1].destinationAddresses', line 1, position 2880."
      }
    ]
  }
} undefined

你有 2 个选项,将其转换为 array:

"[array(reference(variables('arm_firewall_buildagentip')).ipAddress)]"

或者您可以使用接受 a string:

的 属性
"destinationAddressPrefix": "[reference(variables('arm_firewall_buildagentip')).ipAddress]"