ARM template output: Why can I not access the ipAddress of a publicIpAddress ?

Zoltán Tóth 1 Reputation point
2021-02-17T10:39:52.34+00:00

In an ARM template output, I have this:

"ip": {  
    "type": "string",  
    "value": "[reference(variables('publicIPAddressName'),'2020-07-01','Full').properties.ipAddress]"    
},  

or the same applies for this:

"ip": {  
    "type": "string",  
    "value": "[reference(variables('publicIPAddressName')).ipAddress]"    
},  

This will cause a deployment error at output evaluation, as:

The template output 'ip' is not valid: The language expression property 'ipAddress' doesn't exist, available properties are 'provisioningState, resourceGuid, publicIPAddressVersion, publicIPAllocationMethod, idleTimeoutInMinutes, dnsSettings, ipTags'.."  

And indeed, I can only access the fields listed in the error message (e.g. publicIPAddressVersion)
This is weird because I can access the whole object via

"[reference(variables('publicIPAddressName'),'2020-07-01','Full')]"  

which contains the ipAddress under properties, as specified.

Other people say this very example (for "ip") works for them.

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,516 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. TravisCragg-MSFT 5,681 Reputation points Microsoft Employee
    2021-03-05T06:28:28.907+00:00

    I have a possible explanation for this -

    The 'ipaddress' property only exists if the 'publicIPAllocationMethod' is set to 'Static'. ( A Static Public IP Address). If you did this on an IP Address that was not static, it would return an error, but work for those that were static.

    You can use resources.azure.com to view the JSON of any of your azure resources, and verify that a property exists or not.

    0 comments No comments

  2. Zoltán Tóth 1 Reputation point
    2021-03-05T10:33:48.703+00:00

    I can still see the ipAddress as part of the whole object, with dynamic address allocation:

    {
      "name": "simpleLinuxVMPublicIP",
      "id": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Network/publicIPAddresses/simpleLinuxVMPublicIP",
      "etag": "W/\"053bdc94-a30a-423d-9097-a4ce3de4dbf0\"",
      "location": "eastus",
      "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "...",
        "ipAddress": "40.114.82.xxx",                     // <-------------
        "publicIPAddressVersion": "IPv4",
        "publicIPAllocationMethod": "Dynamic",           // <--------------
        "idleTimeoutInMinutes": 4,
        "dnsSettings": {
          "domainNameLabel": "simplelinuxvm-...",
          "fqdn": "simplelinuxvm-....eastus.cloudapp.azure.com"
        },
        "ipTags": [],
        "ipConfiguration": {
          "id": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Network/networkInterfaces/simpleLinuxVMNetInt/ipConfigurations/ipconfig1"
        }
      },
      "type": "Microsoft.Network/publicIPAddresses",
      "sku": {
        "name": "Basic"
      }
    }
    

    Also note that I get this in my output if I query the whole object (with ...'Full', as I wrote above.)
    (Btw, it would be really strange if I could not get a dynamically allocated IP address afterwards)


  3. Nathan Bell 26 Reputation points
    2022-03-09T03:09:26.227+00:00

    I had the same problem: when running a deployment to create a VM with dynamically assigned public IP address, the property was not available in the output object. However, if I re-ran the exact same deployment i.e. the VM already exists, the dynamic IP address was then available in the output. As Travis mentioned, with a static IP address, the property was available in both cases. In order to prevent the error for a dynamic address, I used the following bicep expression:

    publicIp.properties.publicIPAllocationMethod == 'Dynamic' ? '' : publicIp.properties.ipAddress
    

    which compiles to json as:

    "[if(equals(reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpName'))).publicIPAllocationMethod, 'Dynamic'), '', reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIpName'))).ipAddress)]"
    

    Later in the deployment script, I gathered the public IP address using something like:

    $publicIpAddress = Get-AzPublicIpAddress -ResourceGroupName 'MyResourceGroupName' -Name 'MyPublicIpName' | Select-Object -ExpandProperty ipAddress
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.