0

In my template output, I'd like to return the allocated public IP address. I tried the following in the "outputs" section: (in an output of 'object' type)

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

This works and returns the whole publicIpAddress object:

  "ipobj": {
    "apiVersion": "2020-07-01",
    "location": "eastus",
    "sku": {
      "name": "Basic",
      "tier": "Regional"
    },
    "properties": {
      "provisioningState": "Succeeded",
      "resourceGuid": "...",
      "ipAddress": "...",
      "publicIPAddressVersion": "IPv4",
      "publicIPAllocationMethod": "Dynamic",
      "idleTimeoutInMinutes": 4,
      "dnsSettings": {
        "domainNameLabel": "simplelinuxvm-zktwk4fzmy5p4",
        "fqdn": "simplelinuxvm-zktwk4fzmy5p4.eastus.cloudapp.azure.com"
      },
      "ipTags": [],
      "ipConfiguration": {
        "id": "/subscriptions/.../resourceGroups/.../providers/Microsoft.Network/networkInterfaces/simpleLinuxVMNetInt/ipConfigurations/ipconfig1"
      }
    },
    "subscriptionId": "...",
    "resourceGroupName": "...",
    "scope": "",
    "resourceId": "Microsoft.Network/publicIpAddresses/simpleLinuxVMPublicIP",
    "referenceApiVersion": "2020-07-01",
    "condition": true,
    "isConditionTrue": true,
    "isTemplateResource": false,
    "isAction": false,
    "provisioningOperation": "Read"
  }

This is in line with the API documentation of the publicIpAddress object. And I can retrieve some of the properties as well, using the reference without the 'Full' parameter, which, according to the Azure doc, should return the properties of the object. These work:

"[reference(variables('publicIPAddressName')).dnsSettings.fqdn]"
"[reference(variables('publicIPAddressName')).publicIPAddressVersion]"

But some other properties are not accessible:

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

According to the error message, (in case of the middle example):

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

So it seems like Azure doesn't let me access the properties which are however there in the full output. Is there any explanation/intention behind that, or a workaround at least ?

Note: the same happens if I define a "string" output (i.e. not as part of an object) as

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

or

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

2 Answers2

0

I faced similar issue recently, and below are some of the references where the reason for this scenario is mentioned.

  1. According to this:

    i)

    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.

    ii)

    It will only have the 'ipAddress' Property when attached to a service or VM which is running. If the VM is 'Stopped', it will not have the ipAddress property.

  2. And, looks like there is an open issue in github in this link, related to this. Refer to this, in case it gets resolved in the future.

  3. Check this link as well, where it is mentioned that:

    This is a known limitation in the platform where a dynamic public IP address doesn't resolve itself until the VM is up and running. There are two options to workaround:

    i) Create the Public IP Address in static mode. That will ensure that Public IP address is immediately allocated. However, note that you might incur additional charges.

    ii) Change the dependency from Public IP address to the Virtual Machine that the IP address is attached to. This will ensure that the public IP address is always available.

Arutsudar Arut
  • 195
  • 1
  • 13
-1

When you output the properties of publicIpAddress object, you should pay attention to define the correct type that matches the output value.

"outputs": {
    "publicIpipAddress": {
        "type": "string",
        "value": "[reference(parameters('publicIPAddresses_vmc_backupPublicIP_name'),'2020-07-01','Full').properties.ipAddress]"
    },
    "idleTimeoutInMinutes": {
        "type": "int",
        "value": "[reference(parameters('publicIPAddresses_vmc_backupPublicIP_name'),'2020-07-01','Full').properties.idleTimeoutInMinutes]"
    }
}

enter image description here

Nancy
  • 26,865
  • 3
  • 18
  • 34
  • It works for idleTimeoutInMinutes but I still get the same error for ipAddress. – tzp Feb 15 '21 at 12:36
  • Hi, could you please copy the full or exact sample in my rely? You should try `"value": "[reference(variables('publicIPAddressName'),'2020-07-01','Full').properties.ipAddress]" `instead of `"value": "[reference(variables('publicIPAddressName')).ipAddress]" ` in your tried sample to output the publicIpAddress. You miss the properties and api version when you tried it. – Nancy Feb 16 '21 at 08:45
  • I've tried that already. 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'.." – tzp Feb 17 '21 at 09:32
  • Did you try the `"value": "[reference(variables('publicIPAddressName'),'2020-07-01','Full').properties.ipAddress]"`? Could you show any screenshots about it? – Nancy Feb 17 '21 at 09:34
  • I cannot add images in comments, but I copied the error message above and copied the used output from the template into the original question. – tzp Feb 17 '21 at 09:36
  • It's weird. This always works on my side. Is it a public Ip address assigned to an Azure VM? – Nancy Feb 17 '21 at 09:37
  • Yes, the public IP address is fine, and the DNS name as well. I can access the machine from the internet. What is also strange that the error message is also in line with what properties I can access. ipAddress is not listed, and I cannot access it. So can there be some account/subscription specific setting which doesn't allow access to it ? But that would make no sense as I can access the whole structure, see above. – tzp Feb 17 '21 at 09:44
  • if you can access the whole object,you should get public ip as well. Check any typo or blank when you run it. – Nancy Feb 17 '21 at 10:09
  • Once again, check the error message. Azure doesn't let me access the ipAddress field, although it should, but only a few fields within the properties. "The language expression property 'ipAddress' doesn't exist" - I can't see any typo here. As shown in the original question, I can access the whole object. – tzp Feb 17 '21 at 11:03
  • Could you show the full ARM template when you validate it? What's role of the Azure account are you using for arm deployment? – Nancy Feb 19 '21 at 07:46
  • Subscription / My permissions says: You have the following access: You are a member of the group 'idm-... ()' which has been assigned the role 'Reader' (type BuiltInRole) and has access to You are a member of the group 'idm-... ()' which has been assigned the role 'Contributor' (type BuiltInRole) and has access to – tzp Feb 23 '21 at 18:56