You've used Terraform to deploy a virtual machine and a database. You want to replace this virtual machine instance with an identical one without affecting the database. What is the best way to achieve this using Terraform?
You've used Terraform to deploy a virtual machine and a database. You want to replace this virtual machine instance with an identical one without affecting the database. What is the best way to achieve this using Terraform?
The best way to replace a virtual machine instance with an identical one without affecting the database is to use the terraform taint command. This command marks a resource for recreation, which means that on the next run of terraform apply, Terraform will destroy and recreate the tainted resource. This approach ensures that only the specific virtual machine instance is replaced, leaving the other resources, such as the database, unaffected.
B. for v0.15.2 and later, you can also use "terraform apply -replace=ADDRESS" to achieve the same result.
terraform apply -target - just looks at applying part of the config. In this case we'd need to taint the resource and then run an apply. Just to note taint is now deprecated - seems like it comes up in the exam mind, instead of using taint you should use terrform apply -replace=aws_instance.my_server
So answer B
Exactly I was thinking about `terraform apply -replace=...`, so answer C can also be correct. Of course answer B is also correct and deprecated!
being taint deprecated, I would go with C.
https://www.terraform.io/cli/state/taint
ITS B.
B correct