A media publishing enterprise needs to onboard existing, manually provisioned Google Cloud infrastructure—specifically Cloud Storage buckets and Compute Engine instances—into a managed Terraform workflow backed by a secure remote state. What is the correct sequence of operational steps to safely import these resources and ensure configuration alignment?
- 1Provision a dedicated Google Cloud Storage bucket with object versioning and uniform bucket-level access to serve as the remote backend.
- 2Configure the GCS backend block in the main Terraform configuration and execute `terraform init` to establish remote state locking.
- 3Write matching declarative resource definitions in Terraform HCL for the existing Cloud Storage buckets and Compute Engine instances.
- 4Execute `terraform import` commands mapping each GCP resource ID to its corresponding Terraform resource address.
- 5Run `terraform plan` to validate that the resource configurations match the imported state with zero proposed changes.
Answer
The correct operational sequence begins with provisioning the remote GCS backend bucket with versioning and uniform access, followed by configuring the backend and running `terraform init`. Next, matching declarative Terraform HCL resource blocks are defined, after which `terraform import` binds the live GCP resources to state addresses. Finally, `terraform plan` is executed to confirm zero configuration drift.
Safely incorporating existing (brownfield) Google Cloud infrastructure into Terraform requires establishing the infrastructure state lifecycle in a precise sequence. First, the GCS bucket for remote backend state must be created with state protection features (versioning and uniform bucket-level access). Second, `terraform init` initializes the workspace to connect to this remote backend. Third, HCL resource definitions are written to provide the schema target. Fourth, `terraform import` maps the existing live infrastructure IDs into the remote state file. Finally, `terraform plan` validates that no unintended drift or destructive actions will occur when managing the resources declaratively going forward.
Step-by-Step Solution
Key Concept
Brownfield resource import into Terraform state using secure GCS remote backend governance