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.
Related
Currently for our Azure Disaster recovery plan we replicate workloads from a primary site/region to a secondary site. Where we mirror the source VM config and create required or associated resource groups, storage accounts, virtual networks, etc.
We are looking into an alternate method the wouldn't require a second resource group. This would require:
Use one, already existing resource group; i.e. testGroup-rg in East-US
Deploy new IaC components into the same RG but in Central-US
So in the singular resource group, if we wanted a function app, we would have two sets of components. testFuncApp in East-US and testFuncApp in Central-US.
This way we would only ever have one set of IaC created. Of course we would need to automate how to flow traffic etc. into a particular region if both exist.
Is this a possibility? If it is, is it even necessary/worth it?
Unfortunately there is no way to use the same RG. We need to have a resource group in target region if not Site Recovery creates a new resource group in the target region, with an "asr" suffix.
I am trying to remove a particular instance from my scaleset using terraform. I know there is a REST API for this:
https://learn.microsoft.com/en-us/rest/api/compute/virtualmachinescalesets/deleteinstances
However, the page for azure tf doesnt really mention this anywhere.
https://www.terraform.io/docs/providers/azurerm/r/virtual_machine_scale_set.html
How do i do this with terraform?
When managing a virtual machine scale set with Terraform, Terraform does not interact with the individual instances at all. Instead, it can change update the settings of a scale set to match what you've written in configuration and then let the scale set itself respond to that new configuration appropriately.
For example, if you wish to have fewer instances of a particular SKU then you might edit your Terraform configuration to have a lower value for the capacity argument for that SKU and run terraform apply. If you accept that plan, Terraform will update the scale set to have a lower capacity and then the remote scale set system will decide how to respond to that.
To delete something Terraform is managing, like the scale set itself, we would remove it from the configuration and run terraform apply. Because Terraform is not managing the individual instances in this scale set, we can't tell Terraform to delete them directly. If you need that sort of control then you'd need to either manage the virtual machines directly with Terraform (not using a scale set at all) or use a separate tool (outside of Terraform) to interact with the API you mentioned.
I have one resource group that I set up with the portal and another that I tried to configure the same way using Terraform.
Each group contains
Application Gateway with Web App Firewall
Virtual networks and subnets
VMs and associated storage
Public IPs, NSGs, NIC etc
Is there a way for me to compare the two sets of configurations?
For you, I assume you want to create the same resources with the same configurations in another group through Terraform. On my side, there are not many things you need to care about. Just according to the configuration of the resources to create the terraform script.
each resource region
the public IP and the NIC allocation method
NSG rules
vnet and the subnet address prefix
application gateway properties and the rules
The above points are that I think you need to care about. And the properties of the resources in Terraform also need to according to. I think there is no other way to compare two sets of configurations. If you really want, you can compare the template of each group when you create them. The group template shows below:
No, i dont think there is a reasonable straight forward way of doing this, you can create a powershell script that would get resources in each resource group and then try and compare properties, but its hard to give some sort of estimation how accurate it would be, there is a Compare-Object cmdlet in powershell, which might help you with that.
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.
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