简体   繁体   English

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

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

I am creating azure firewall DNAT rules as part of an azure devops pipeline.我正在创建 azure 防火墙 DNAT 规则作为 azure devops 管道的一部分。 I dont want to specify the public IP manually, i want to pull this value from the properties of the public nic.我不想手动指定公共 IP,我想从公共网卡的属性中提取这个值。 This way if we clone the pipeline, or rebuild, we dont have to update the IP address.这样,如果我们克隆管道或重建管道,就不必更新 IP 地址。

This is just an excerpt from the ARM template.这只是 ARM 模板的摘录。 This first example works.第一个例子有效。

"destinationAddresses": [
            "52.180.91.89"
]

My attempt to replace it is below.我尝试更换它如下。 Please note that the public IP is created in the ARM template so I am not referencing the full path to the resource.请注意,公共 IP 是在 ARM 模板中创建的,因此我没有引用资源的完整路径。

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

The error i am receiving is below.我收到的错误如下。 Its returning the correct value, but I am not sure how to format it so it can be accepted in the firewall rule.它返回正确的值,但我不确定如何格式化它以便它可以在防火墙规则中被接受。

##[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

you have 2 options, convert it to array :您有 2 个选项,将其转换为数组

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

or you can use the property that accepts a string :或者您可以使用接受字符串的属性:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么错误“不是有效的资源引用。 尝试通过 Azure 中的 ARM 模板创建 VM 时触发(代码:无效参数)”? - Why error “is not a valid resource reference. (Code:InvalidParameter)” is triggered when trying to create a VM via ARM-Template in Azure? 如何解决错误:尝试连接 Azure 文件存储时指定的资源名称包含无效字符 Azure Function - How to resolve error:The specified resource name contains invalid characters when trying to connect Azure File Storage in Azure Function 尝试将 Azure ARM 模板与 object 参数一起使用,但遇到无效索引错误 - Trying to use Azure ARM template with object parameter but stuck with an invalid index error 如何在Azure中使用API​​创建防火墙规则? - how to create Firewall Rules with API in Azure? 尝试创建Azure映像时无效的VHD路径错误 - Invalid VHD path error when trying to create Azure Image ARM Resource Not Found 在尝试使用 Outputs 时,已经尝试了很多 - ARM Resource Not Found when trying to use Outputs, have tried a lot Azure ARM模板-嵌套资源参考 - Azure ARM template - nested resource reference 尝试在 Azure US Gov 中获取授权代码时出现“AADSTS650057:无效资源”错误 - Getting "AADSTS650057: Invalid resource" error when trying to get an authorization code in Azure US Gov azure上的防火墙规则 - Firewall Rules on azure Azure ARM模板中资源上属性的多个值 - Multiple values for a property on resource in Azure ARM Template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM