仅当分配方法为静态时,我如何才能从 Arm 模板中输出公共 IP 地址? [英] How can i output a Public IP address from an Arm template only if the allocation method is static?

查看:13
本文介绍了仅当分配方法为静态时,我如何才能从 Arm 模板中输出公共 IP 地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅当创建非静态的 PublicIP 时,我才尝试从 arm 模板输出公共 IP 地址.如果它是动态的,则可以忽略输出.

I am trying to output a Public IP address from an arm template only if the PublicIP being create dis static. If it is Dynamic the output can be ignored.

我们有一个主模板,它调用另一个模板来创建虚拟机.调用模板将使用参数 PIPAllocationMethod 传递构建机器所需的参数,包括公共 IP 应该是静态的还是动态的.

We have a main template which calls another template to create the virtual machine. The calling template will pass the parameters required to build the machine including whether the Public IP should be static or dynamic using the parameter PIPAllocationMethod.

在输出部分构建虚拟机的模板中,我尝试了以下代码但它不起作用并返回如下错误无法评估模板输出'publicIpAddress'无效."

In the template which builds a vm in the output section I have tried the following code but it doesnt work and returns error as below "Unable to evaluate template output'publicIpAddress' is not valid."

"outputs": {
"publicIpAddress": {
  "value": "[if(equals(parameters('PIPAllocationMethod'),'Static'), reference(variables('primaryPIPAddressName')).ipAddress, parameters('PIPAllocationMethod'))]",
  "type": "string"
}

如果是静态的,我需要的是只输出公共IP地址,如果是动态的,则可以忽略

What I need is to only output the PublicIP Address if is is Static, if it is Dynamic it can be ignored

感谢帮助

推荐答案

我认为你在谈论 PublicIP 资源,所以你有一个错字(区分大小写):

I think you are talking about PublicIP resource, so you have a typo (case sensitivity):

reference(variables('primaryPIPAddressName')).IpAddress

对于 NIC 使用这个:

for NIC use this:

reference(variables('primaryPIPAddressName')).ipConfigurations[0].properties.privateIPAddress

在你的情况下,我建议你这样做.使用以下值创建变量:

in your case i suggest you do this. créate variable with the following value:

"picker": "[if(equals(parameters('PIPAllocationMethod'),'Static'), 'IpAddress', 'publicIPAllocationMethod')]"

在你的输出中你可以这样做:

and in your output you can do this:

"value": "[reference(variables('primaryPIPAddressName')).[variables('picker')]]"

这篇关于仅当分配方法为静态时,我如何才能从 Arm 模板中输出公共 IP 地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆