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

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

问题描述

仅当正在创建PublicIP时,我才尝试从Arm模板输出Public 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.

在用于在输出部分中构建vm的模板中,我尝试了以下代码,但是它不起作用并返回错误,如下所示:无法评估模板输出'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"
}

我需要的是仅输出PublicIP地址(如果为静态),如果为动态,则可以忽略

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使用此:

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天全站免登陆