Retrieve Instance names on scale sets using ARM template - azure

I have a ARM template which creates two scale sets, I need to retrieve the instance names from scale set 1 and use them as parameters in scale set 2 custom linux script extension. Is there a way to get the names only the fly when we are deploying the resources ?. I Have a powershell script which does the same. But I want my deployment to be using only ARM template , because we are creating the entire solution as a Managed app.

To reference first VM ip address use the following snippet:
"[reference('Microsoft.Compute/virtualMachineScaleSets/vmssName/virtualMachines/1/networkInterfaces/nicName/ipConfigurations/ipConfigurationName').ipConfigurations[0].properties.privateIPAddress]"
If you need all of those (ip from each vm in vmss) you could créate those values on the fly, you would most likely need a nested template to achieve that.

Related

Azure VMSS Flexible Orchestration - Custom Resource Names

I have created VMSS Flexible with orchestration mode with proper names, yet VMs, NICs, IPs got randomly generated suffixes.
Is it possible to automatically create VMs and corresponding resources, when adding instances through VMSS?
I’d like to have resources names like:
TST-WebServer1-VM
TST-WebServer2-VM
TST-WebServer1-VM-IP
TST-WebServer2-VM-IP
TST-WebServer1-VM-NIC
TST-WebServer2-VM-NIC
and so on.
https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-orchestration-modes#instance-naming
When you create a VM and add it to a Flexible scale set, you have full control over instance names within the Azure Naming convention rules. When VMs are automatically added to the scale set via autoscaling, you provide a prefix and Azure appends a unique number to the end of the name.
Apparently it is not actually full control over the names when they are automatically added.

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.

Azure ARM Deployment - multiple subscriptions

My ARM template has worked well, it creates a VNET, multiple subnets, NSGs, and necessary route-tables. I now need to do this same thing but across multiple subscriptions. Can't get it to work.
I know there is the nestedTemplate option. This allows you to specify a subscriptionID and requires that the resource group exist first. I built all this up and used the nestedTemplate but get an error "Subscription is not registered with NRP". Not sure how to make this work and I'm wondering if an ARM template is enough. I'm thinking of building a python script that will in turn run arm templates with separate parameter files.
I'd like to be able to take this single template and single parameter file but have it iterate through multiple subscriptions.
Couldn't get it to work, the nestedTemplates seem to require additional work. I built a python script that does the work instead.

Working with azure templates incrementaly

So I have this template that I've used to create my resource group. We are in the middle of development process, so it is pretty usual to add different resources from day to day.
How can I run the template to just add the ones that I am missing?
I've tried to deploy my template to my existing resource group, but I guess it just thinks that I want to create another set of resources.
What should I do?
ARM Templates are idempotent by default, so if you add resources to the template without changing anything else in it, it will just create\add new resources to your resource group. So that behavior is be default.
As for the parameters, it cannot magically infer the names (or anything) of things that you want to pass. You can either reuse existing deployments (it will prepopulate all the parameters), create a script that will pass in parameters, create a parameters file to pass in to the template.
Reference:
https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-group-template-deploy

Create multiple server using Terraform on Azure

I am creating multiple servers on Azure using Terraform template in a same Azure "Resource group", However when i try to run the template for individual servers each time, it is deleting the previous server while creating for next one.
Any idea how i can i reuse the same template for creating multiple server in a same Resource Group.
Thanks.
Terraform is intended to be idempotent, meaning that reapplying the same template makes no changes. If you edit the template, Terraform will edit the environment to reflect any changes or deletions.
If you need multiple VMs, you have at least two options:
Define multiple VM resources in your template.
Define a VM scale set and simply specify the number of VMs that you need.
I was able to achieve this, Here is what i did.
I created 2 separate .tf files under different folders.
1) For creating Resource group, NSG, Storage account, Vnet
2) For creating public ip, network interface and VM itself.
So i could use second configuration file for creating multiple server by just changing the values though parameters

Resources