Question

Difficulty: MediumBuilding and Managing Infrastructure as Code (IaC)

A pharmaceutical distribution company manages its Google Cloud infrastructure using Terraform within a centralized Cloud Build CI/CD pipeline. During an emergency operational incident, an engineer manually updated the machine type and auto-scaling limits of an unmanaged instance group directly in the Google Cloud Console. The infrastructure team now needs to resolve this configuration drift and bring the state back into alignment with IaC governance standards without tearing down existing production workloads. Which approach should the cloud architect recommend?

  1. Update the local Terraform HCL codebase to reflect the upgraded instance group specifications, execute a terraform plan to confirm zero resource destruction, and commit the changes to trigger the pipeline.Answer
  2. B
    Continue allowing manual updates via the Cloud Console during operational incidents, and execute a scheduled terraform apply step with a force flag to overwrite drift automatically.
  3. C
    Delete the existing remote Terraform state object in the Cloud Storage bucket and re-run terraform init to rebuild the state file from scratch.
  4. D
    Grant the Cloud Build service account the Project Owner primitive role across all environments so the pipeline can forcefully reconcile unmanaged resources.

Answer

Update the local Terraform HCL codebase to reflect the upgraded instance group specifications, execute a terraform plan to confirm zero resource destruction, and commit the changes to trigger the pipeline.
The correct approach is to update the Terraform HCL code to match the manual configuration changes, perform a plan check to ensure no destructive updates are scheduled, and commit the code to version control. This restores parity between code, state, and live GCP resources while maintaining IaC governance.

Step-by-Step Solution

1
Identify the drift source
Recognize that manual modifications performed in the Cloud Console caused the live environment to deviate from the stored state file.
Infrastructure as Code requires declarative code to represent the true desired state of managed cloud resources.
2
Update Terraform code definition
Modify the instance group resource block parameters in HCL to match the updated live resource attributes.
Bringing code in line with manual emergency changes captures valid operational adjustments in version control.
3
Validate state execution plan
Run terraform plan to verify that Terraform detects no unexpected changes or resource replacements.
Prevents accidental downtime or recreation of production resources before committing to main branches.

Key Concept

Remediating Infrastructure Configuration Drift in Terraform
Estimated Time:1m 30s
Rate this question