A telecommunications enterprise is onboarding manually provisioned core network billing resources—including custom VPC subnetworks, firewall rules, and Cloud SQL database instances—into a managed Infrastructure as Code (IaC) workflow using Terraform. The cloud architecture team must safely import these brownfield Google Cloud resources into a remote Cloud Storage (GCS) backend while ensuring zero downtime and preventing state corruption. What is the correct chronological sequence of operational steps to safely import and govern these existing resources using Terraform?
- 1Write the Terraform HCL resource declarations matching existing GCP resource attributes and configure the GCS remote backend in the root configuration module.
- 2Execute `terraform init` to initialize the working directory, download the Google provider plugins, and establish connectivity with the remote GCS backend bucket.
- 3Execute `terraform import` commands for each existing infrastructure component, mapping live GCP resource IDs to their corresponding Terraform resource addresses.
- 4Execute `terraform plan` to compare the declared HCL code against the newly imported state and verify that zero infrastructure changes or drift are reported.
- 5Commit the verified Terraform HCL code, module definitions, and provider dependency lockfile (`.terraform.lock.hcl`) to the Git version control repository.
Answer
The correct sequence begins with writing matching HCL resource blocks and backend configuration, running `terraform init` to configure plugins and backend storage, executing `terraform import` to map live GCP resource IDs to state addresses, running `terraform plan` to confirm zero drift, and finally committing the verified configuration code to version control.
Safely bringing existing brownfield Google Cloud infrastructure into Terraform requires establishing matching HCL definitions and backend configuration first, initializing backend storage and provider plugins (`init`), mapping live GCP resource IDs into state metadata (`import`), verifying configuration alignment to ensure zero unexpected modifications (`plan`), and committing verified configuration files to Git.
Step-by-Step Solution
Key Concept
Brownfield Resource Import and IaC State Governance