0
votes

I created an ARM template with a virtual machine scale set, Now I am stuck in my ARM template development because I couldn't get private IPs of the virtual machine created inside the scale set. Private IPs are required to update Cassandra seeds using extension scripts.

{
            "type": "Microsoft.Compute/virtualMachineScaleSets",
            "apiVersion": "2020-06-01",
            "name": "[parameters('vmName')]",
            "location": "[parameters('location')]",
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]",
                "Microsoft.Compute/images/myCustomImage"
            ],
            "identity": {
                "type": "SystemAssigned"
            },
            "sku": {
                "name": "[parameters('vmSku')]",
                "tier": "Standard",
                "capacity": "[parameters('instanceCount')]"
            },
            "properties": {
                "overprovision": "false",
                "upgradePolicy": {
                    "mode": "Manual"
                },
                "virtualMachineProfile": {
                    "storageProfile": {
                      "imageReference": {
                        "id": "[resourceId('Microsoft.Compute/images', 'myCustomImage')]"
                      }
                    },
                    "osProfile": {
                        "computerNamePrefix": "[parameters('vmName')]",
                        "customdata": "1",
                        "adminUsername": "centos",
                        "linuxConfiguration": {
                            "disablePasswordAuthentication": true,
                            "ssh": {
                                "publicKeys": [
                                    {
                                        "path": "/home/centos/.ssh/authorized_keys",
                                        "keyData": "xxxx"
                                    }
                                ]
                            }
                        }
                    },
                    "networkProfile": {
                        "networkInterfaceConfigurations": [
                            {
                                "name": "[parameters('nicName')]",
                                "properties": {
                                    "primary": true,
                                    "ipConfigurations": [
                                        {
                                            "name": "[variables('ipConfigName')]",
                                            "properties": {
                                                "subnet": {
                                                    "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), 'cassandra')]"
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            }
        }

How to get private IPs of VMs created within the scale set?

1
Any more updates on this question? Does it solve your problem? Why not give any response and also do not accept it?Charles Xu

1 Answers

1
votes

You can use the function reference to get the NIC resource of the VMSS instances. And the resource id of the instance NICs, look like this:

/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/virtualMachines/{instanceId}/networkInterfaces/{nicName}

So you can set the variables for each instance id and then get the private IP addresses, the part of the template looks like this:

"variables": {
    "instanceNic-0": "[concat('/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/virtualMachines/0/networkInterfaces/', parameters('nicName'))]" 
},
"outputs": {
    "instanceNic-0-IP": {
        "type": "string",
        "value": "[reference(variables('instanceNic-0'), '2016-09-01').ipConfigurations[0].properties.privateIPAddress]"
    }
}