Reputation: 10978
How can I downsize a virtual machine after its provisioning, from terraform
script? Is there a way to update a resource without modifying the initial .tf
file?
Upvotes: 1
Views: 3722
Reputation: 11
How about passing in a command line argument that is used in a conditional variable?
For example, declare a conditional value in your .tf file:
vm_size = "${var.vm_size == "small" ? var.small_vm : var.large_vm}"
And when you want to provision the small VM, you simply pass the vm_size variable in on the command line:
$ terraform apply -var="vm_size=small"
Upvotes: 0
Reputation: 19223
I have a solution, maybe you could try.
1.Copy your tf file, for example cp vm.tf vm_back.tf
and move vm.tf
to another directory.
2.Modify vm_size
in vm_back.tf
. I use this tf file, so I use the following command to change the value.
sed -i 's/vm_size = "Standard_DS1_v2"/vm_size = "Standard_DS2_v2"/g' vm_back.tf
3.Update VM size by executing terraform apply
.
4.Remove vm_back.tf and mv vm.tf to original directory.
Upvotes: 1