A fintech startup has manually provisioned a production environment in Google Cloud consisting of Cloud Pub/Sub topics and BigQuery datasets via the GCP Console. To bring these resources under Infrastructure as Code (IaC) governance, the cloud architecture team needs to safely import the resources into Terraform state while setting up a centralized Cloud Storage (GCS) backend for state storage. In what sequence should the engineering team execute the following operational steps to import the existing infrastructure without accidental resource destruction?
- 1Write matching HCL configuration blocks for the Cloud Pub/Sub topics and BigQuery datasets and declare the GCS remote backend block in code.
- 2Run `terraform init` to download necessary provider plugins and initialize connection to the remote Cloud Storage backend bucket.
- 3Execute `terraform import` for each resource using their full Google Cloud resource IDs to associate live GCP infrastructure with state addresses.
- 4Run `terraform plan` to verify that the declared HCL code matches the imported state with zero planned changes or resource replacements.
- 5Commit the validated HCL code to the team's version control repository to integrate with automated CI/CD deployment pipelines.
Answer
The correct operational sequence is: 1) Write matching HCL configuration and GCS backend declarations, 2) Run terraform init to connect to the remote backend, 3) Execute terraform import using full GCP resource IDs, 4) Run terraform plan to verify zero configuration drift, and 5) Commit the verified HCL code to version control.
Safely bringing existing (brownfield) Google Cloud infrastructure under Terraform management requires first writing corresponding HCL code and backend settings, initializing the backend via `terraform init`, executing `terraform import` with exact GCP resource IDs, validating zero drift using `terraform plan`, and finally committing code to Git for CI/CD integration.
Step-by-Step Solution
Key Concept
Infrastructure as Code (IaC) Brownfield Resource Import Workflow