Question

Difficulty: EasyBuilding and Managing Infrastructure as Code (IaC)

A cloud administrator at a media streaming enterprise discovers that a security analyst manually modified a Compute Engine firewall rule using the Google Cloud Console during an emergency incident response. The environment's infrastructure is managed using Terraform. Which action should the administrator take to align the actual infrastructure state with the source-controlled configuration code?

  1. Run terraform plan to identify the configuration drift, and then execute terraform apply to revert the manual changes back to the defined code state.Answer
  2. B
    Manually edit the firewall rule via the Cloud Console again to match the settings written in the Terraform code.
  3. C
    Delete the remote Terraform state file stored in Google Cloud Storage so Terraform can rediscover and recreate all resources.
  4. D
    Assign the primitive Owner role to the deployment pipeline service account to bypass firewall validation checks.

Answer

Run terraform plan to identify the configuration drift, and then execute terraform apply to revert the manual changes back to the defined code state.
Terraform maintains resource states declaratively. When manual modifications occur in Google Cloud outside of the IaC workflow, running `terraform plan` compares the real-world infrastructure against the configuration code to highlight the drift. Running `terraform apply` overwrites the out-of-band console changes and restores the firewall rule to match the declared source code.

Step-by-Step Solution

1
Detect configuration drift between cloud infrastructure and declared code
Running terraform plan displays the differences introduced by the manual Cloud Console modification
Terraform reads the current state of real-world resources and compares them against the configuration files
2
Apply the declarative configuration code
Running terraform apply updates the firewall rule back to its declared specification
Terraform enforces declarative infrastructure by aligning actual GCP resources with source code

Key Concept

Infrastructure as Code Drift Remediation
Rate this question