Azure-quickstart-templates: [Question] How to get the dynamic public IP address inside a VM?

Created on 7 Sep 2015  Â·  7Comments  Â·  Source: Azure/azure-quickstart-templates

I assign a dynamic IP for a VM when I am deploying a template. During or after the creation of VM, is there a way to get the dynamic IP?
Thanks

All 7 comments

You can get this information from the ipConfigurations property on the NIC resource reference.

using something like the following

reference('nic-name').ipConfigurations[0].properties.privateIPAddress

The following is from the postgress template and returns the dynamically assigned IP address as an output property, which is then passed as a parameter to another template.

"outputs": {
    "masterip": {
      "value": "[reference(concat(variables('nicName'),0)).ipConfigurations[0].properties.privateIPAddress]",
      "type": "string"
    }
  }

@trentmswanson Thanks for your response.
Sorry that I did not describe my question clearly. I want to get a dynamic public IP.
https://github.com/Azure/azure-quickstart-templates/blob/master/bosh-setup/azuredeploy.json#L137

I assigned a dynamic public IP to a VM. And for some reason, I want to get this IP in the VM.

  1. As far as I know, the dynamic public IP is determined when the VM is created. So, I can't get it like the privateIPAddress. Is that right?
  2. My workaround is getting it via http://www.whereismyip.com. But it is not a right way in the long run.

@bingosummer This came up recently in another thread. Here's the reply from @mahthi

If you want to get the IP address immediately, then you need to use “static” for the “publicIPAllocationMethod”

If you don’t want to use “static” (Reserved IPs), then you need to put a dependency on the Virtual Machine that is attached to the Public IP (the address will be allocated then)

@singhkay Thanks for your help.
AFAIK, network interfaces can use only dynamic public IPs in ARM mode. So I can't assign a static one to it. But I need to get the public IP address inside the VM. I have two choices:

  1. Pass the public IP address in azuredeploy.json just like https://github.com/Azure/azure-quickstart-templates/blob/master/bosh-setup/azuredeploy.json#L298. But the dynamic IP address is not ready when azuredepoy.json is rendered.
  2. Get the public IP address inside the VM using http://www.whereismyip.com.

The first way does not work for me. So I choose the second one as a workaround.

@singhkays

If you don’t want to use “static” (Reserved IPs), then you need to put a dependency on the Virtual Machine that is attached to the Public IP (the address will be allocated then)

Can you please confirm on this? In a normal exported VM ARM template, VM has the dependency on the network interface which has the dependency on the public IP address. It doesn't output the IP address right way from ARM. It takes awhile to get the IP address. If I miss out something, please share me an example ARM template. Thanks.

@michaelsync

Can you please confirm on this? In a normal exported VM ARM template, VM has the dependency on the network interface which has the dependency on the public IP address. It doesn't output the IP address right way from ARM. It takes awhile to get the IP address. If I miss out something, please share me an example ARM template. Thanks.

have you managed to solve this issue?
because it looks like circular dependency - if you try to exclude "publicIP" from NIC, "publicIP" won't attach to VM and so on.

Probably too late, but I remember having done this with a dirty little trick: you use a nested template that depends on the VM, so that it is only triggered when the VM is finished. The nested template will output the ipAddress property of the public IP, and the main/root template will take the output of the nested deployment

Was this page helpful?
0 / 5 - 0 ratings