List all VM Instances in a virtual machine scaleset using ARM template - arm-template

Is it possible to get the list of all instances of a virtual machine scaleset from within the ARM template deployment as an output? I am deploying an ARM template which creates a virtual machine scaleset with 3 instances. As part of the deployment output, I want the list of all the VM's inside the scaleset. I have tried these so far -
"value": "[reference(concat('/subscriptions/SubscriptionID/resourceGroups/ResourceGrpName/providers/Microsoft.Compute/virtualMachineScaleSets/ScalesetName'), '2019-12-01', 'Full')]" -
This only returns the scaleset information.
"value": "[reference(concat('/subscriptions/SubscriptionID/resourceGroups/ResourceGrpName/providers/Microsoft.Compute/virtualMachineScaleSets//virtualMachines'), '2019-12-01', 'Full')]" -
This returns an error - "The resource namespace 'subscriptions' is invalid."
There is a similar REST API mentioned here - https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-instance-ids which works.

it should be like this (i'm not sure it even works, tbh):
reference(concat(resourceId('SubscriptionID', 'ResourceGrpName',
'Microsoft.Compute/virtualMachineScaleSets', 'scaleSetName'),
'/virtualMachines'), '2019-12-01', 'Full')]"
line breaks only for readability

Related

SecureString in ARM template deployment through Terraform does an update in place everytime?

I am using Terraform to provision my Azure resources which works great, however, for some resources such as Logic Apps, doing this natively doesn't really work so I am using the Logic Apps ARM template and doing a Terraform "azurerm_resource_group_template_deployment" in order to provision. I know doing an ARM template deployment within Terraform is a bit of a last resort. It works ok though and deploys fine but I have a Service Bus connection defined and that is of type "securestring". By default, these are not saved as part of ARM deployment so everytime Terraform runs in my pipeline, even if the Logic App ARM template has not changed, it still does the deployment as the top level deployment state Terraform knows about previously did not have the value saved so will always see it as new. Is there any way around this other than changing the "securestring" to "string" which I obviously do not want to do given the endpoint contains the SAS key etc?
Hit same issues today - really limits what is viable. Managed to work around my two scenario's.
For things like keys and connection strings you can use the listkeys function inside of the ARM template - some examples here. I had this exact issue trying to get a log analytics workspace key in to the template - https://github.com/Azure/azure-quickstart-templates/blob/master/demos/arm-template-retrieve-azure-storage-access-keys/azuredeploy.json - Get connection strings in ARM
Another scenario I had was wanting to pass a service principal secret from TF to template as securestring, to get around this I ended up getting the secret from keyvault inside of the ARM template instead.

Is it possible to update the assigned Azure DSC configuration to a VM via ARM Template?

I need to change the Azure DSC configuration that has been previously assigned to a VM.
I'm trying to do this programatically because it's part of an automation I'm developing and because of this, I'm using ARM Templates.
However, redeploying the same VM DSC extension by ARM Template results in an error stating a VM can't have two of the same extensions, which sounds logical.
What I want to know if it's possible to, by ARM Template, "update" or "modify" the current extension with just one setting changed: The configuration name.
Is this possible?
Sure - you can update the existing VM extension by providing new configuration in your ARM template. As you have found out, you cannot use a different name for the extension - that would result in two VM extensions of the same type on the VM. Instead, you need to reuse the same name of the existing VM extension when performing the update.

using azure cli, vmss json template doesn't create vmss with datadisk

Context:
Trying to create VMs in Azure (cloud) using VMSS in ARM mode and using json templates.
Problem:
Creating a VMSS from an os image and datadisk image using Azure CLI and json template creates new VMSS but not the datadisk.
My success so far:
Successfully created VMs using CLI with both os and data disk from a custom image using json template. Also successfully created VMSS (Virtual Machine Scale Set) from a valid custom os image using CLI with json template.
My research for problem:
There isn't any sample on github for this scenario git hub templates. Microsoft azure site also have sample for os disk only and not creating a VMSS with data disk.
blkid comand doesn't show the data disk at all, meaning it was never created and mounted. My json template virtualMachineProfile->storageProfile declares a valid dataDisks object and I know it's works as it successfully creates VM (not VMSS) with data disk and also CLI doesn't return any error.
I know json based template is new and Microsoft is working on adding more features/functionalities so my questions is "Is there anything wrong that I am doing and is it that creating VMSS with data disk is not yet implemented in Azure ?"
Environment: Linux (Debian/RHEL)
Azure CLI : 0.9.13 (ARM mode)
Azure Api: 2015-06-15
Image: (CentOS 6.7)
Thanks for your help.
As per this blog post VMSS and data disks, it is not yet supported. Such a bummer..... Hopefully Microsoft will soon release this feature before selling VMSS too much.

azure vm location default using command line?

I'm trying to use the azure command line to start a vm:
azure vm start myvmnamehere
But it's telling me:
No deployments were found
I'm guessing that I need to specify the location "West US"?
azure vm start is going to start a virtual machine that you've already created, within a specific region. To do that, you'd first need to call azure vm create. You would first create your vm from an image in the gallery (and within a dns name, xxxxx.cloudapp.net). To see the images available to you, try running azure vm image list.
Also: don't forget to add --ssh or --rdp so you can have remote access, when calling azure vm create.
Jeff Wilcox blogged about this in more detail, here.

Move DevTest Lab VM to another DevTest Lab

I'm trying to move a VM custom image from one DevTest Lab to another and can't seem to find an easy way to accomplish that. My VM is using managed disks and also has a data disk.
I've read the following article https://azure.microsoft.com/en-us/updates/azure-devtest-labs-changes-in-exporting-custom-image-vhd-files/ and it states that
Azure DevTest Lab now generates a managed image and "…This allows
Sysprep'ed/deprovisioned custom images to support data disks in
addition to the OS disk through a single image."
This is fine but the image that is created can't be exported.
Is it even possible to accomplish, am I missing something?
Thanks for your help
This is fine but the image that is created can't be exported.
The article you posted is right, you can follow it to export the VM OS disk(not image) to your local machine. You should export the VM OS disk from the Resource group which contains your Devtest VM. The main steps are below:
Generate your VM
Go to Azure Portal > find the resource group which name contains your DevtestLab VM :
Then, you can find the Disk and export it to your local machine:
Go to your another Devtest Lab > Configuration and plocies > Custom images > Add > Enter your VHD location and choose the OS type > OK > the coustom image will be uploaded Then you can use it to create your Devtest VM.

Resources