0

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?

usr1234
  • 61
  • 2
  • 9

1 Answers1

1

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.

Martin Atkins
  • 62,420
  • 8
  • 120
  • 138