PROFESSIONAL-CLOUD-DEVOPS-ENGINEER · Question #77
You use Terraform to manage an application deployed to a Google Cloud environment. The application runs on instances deployed by a managed instance group. The Terraform code is deployed by using a…
The correct answer is D. Set the create_before_destroy meta-argument to true in the lifecycle block on the instance. To update an instance template's machine type with minimal disruption and a single pipeline run when terraform apply fails, use create_before_destroy on the instance template resource.
Question
Options
- ADelete the managed instance group, and recreate it after updating the instance template.
- BAdd a new instance template, update the managed instance group to use the new instance
- CRemove the managed instance group from the Terraform state file, update the instance template,
- DSet the create_before_destroy meta-argument to true in the lifecycle block on the instance
How the community answered
(34 responses)- A15% (5)
- B6% (2)
- C3% (1)
- D76% (26)
Why each option
To update an instance template's machine type with minimal disruption and a single pipeline run when `terraform apply` fails, use `create_before_destroy` on the instance template resource.
Deleting and recreating the managed instance group would cause significant application downtime and would require multiple steps or pipeline runs, contradicting the goal of minimizing disruption and pipeline runs.
Manually adding a new instance template and then updating the MIG is a multi-step, less automated approach than using `create_before_destroy` within a single `terraform apply`.
Removing the managed instance group from the Terraform state file is an anti-pattern that breaks Infrastructure as Code principles and would not resolve the underlying issue of updating the instance template without disruption.
The `create_before_destroy = true` meta-argument in the `lifecycle` block ensures that Terraform creates the new instance template with the updated machine type before attempting to destroy the old one. This allows the managed instance group to roll out new instances gracefully, minimizing application disruption during the update in a single `terraform apply`.
Concept tested: Terraform lifecycle meta-arguments for resource replacement
Source: https://developer.hashihashicorp.com/terraform/language/meta-arguments/lifecycle#create_before_destroy
Topics
Community Discussion
No community discussion yet for this question.