Reputation: 1995
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.
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.
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"
}
What I need is to only output the PublicIP Address if is is Static, if it is Dynamic it can be ignored
Help appreciated
Upvotes: 1
Views: 3630
Reputation: 72191
I think you are talking about PublicIP resource, so you have a typo (case sensitivity):
reference(variables('primaryPIPAddressName')).IpAddress
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')]]"
Upvotes: 3