2

Have a ARM template (https://github.com/jmspring/arm-template-neo4j-docker/blob/master/azuredeploy.json) which will launch a instance and assign a public IP.

here i need to print the IP address as Output. i tried adding the following to the template. but still it it does not print the value.

"outputs": {
"ipaddress": {
"type": "string",
"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName')),providers('Microsoft.Network', 'publicIPAddresses').apiVersions[0]).ipAddress]"
  },

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

Any assisance will be helpful.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
mebb
  • 29
  • 1
  • 4

3 Answers3

4

I have seen this a couple of times before. If you want to get the IP address immediately, then you need to use static for the "publicIPAllocationMethod" property.

If you do not 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).

Just for reference as well, for private IP addresses you can use the following to return the private IP address if this is also required:

reference('nic-name').ipConfigurations[0].properties.privateIPAddress
Martyn C
  • 166
  • 2
  • 1
    i can retrieve private address using the nic details but finding difficulty while fetching dynamically assigned IP. – mebb Apr 06 '16 at 17:46
  • 1
    That's correct, as I said you can only retrieve the IP address when it's set to static not dynamic. – Martyn C Apr 07 '16 at 07:32
  • Keep in mind that when you use the `reference()` function, if the resource isn't located in the same template you'll need to supply the resource ID using something like `reference(resourceId(parameters('resourceName')))` https://github.com/Azure/azure-quickstart-templates/blob/master/1-CONTRIBUTION-GUIDE/best-practices.md – cody.codes Nov 16 '18 at 17:12
  • FYI: 1. In the answer above, `nic-name` is a *variable* -- replace it with the name of your NIC! 2. NIC refers to the network interface associated with your VM -- to manually see yours, follow the instructions [here](https://learn.microsoft.com/en-us/azure/virtual-network/virtual-network-network-interface-vm#view-network-interfaces-for-a-vm) 3. As mentioned [here](https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-resource#reference), if the NIC name is ambiguous (multiple resources share the name) you might have to provide the full NIC ID instead – Seth Dec 07 '22 at 21:39
4

Answer really comes from Azure docs

"value": "[reference(resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))).IpAddress]",

Get fancy and construct SSH login string with username:

     "Public IP SSH": {
    "value": "[concat(
        reference(resourceId('Microsoft.Compute/virtualMachines',variables('vmName'))).osProfile.adminUsername,
        '@',
        reference(resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))).IpAddress]",
    "type": "string"
 },
Alec Istomin
  • 322
  • 1
  • 8
1

I used this to retrieve the public IP: "[reference(concat('Microsoft.Network/publicIPAddresses/', variables('masterPublicIPAddressName'))).ipAddress]" . I used "publicIPAllocationMethod" as "static"