nerdexam
Google

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.

Submitted by ahmad_uae· Apr 18, 2026Building and implementing CI/CD pipelines for a service

Question

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 CI/CD pipeline. When you change the machine type on the instance template used by the managed instance group, the pipeline fails at the terraform apply stage with the following error message: You need to update the instance template and minimize disruption to the application and the number of pipeline runs. What should you do?

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)
  • A
    15% (5)
  • B
    6% (2)
  • C
    3% (1)
  • D
    76% (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.

ADelete the managed instance group, and recreate it after updating the instance template.

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.

BAdd a new instance template, update the managed instance group to use the new instance

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`.

CRemove the managed instance group from the Terraform state file, update the instance template,

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.

DSet the create_before_destroy meta-argument to true in the lifecycle block on the instanceCorrect

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

#Terraform lifecycle#Google Cloud MIGs#CI/CD deployment#Immutable infrastructure updates

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVOPS-ENGINEER Practice