An enterprise cloud engineering team needs to safely transition manually provisioned Google Cloud SQL databases and Cloud Storage buckets into Terraform management while establishing a remote backend for state storage. Order the following operational steps in the correct logical sequence to complete this brownfield IaC onboarding workflow while preventing state corruption or resource re-creation.
- 1Write the Terraform configuration files (HCL) matching the existing infrastructure resource attributes and specify the Cloud Storage backend block.
- 2Run terraform init to download required GCP provider plugins and configure the remote Cloud Storage backend for state locking.
- 3Execute terraform import commands targeting each resource ID to map existing GCP infrastructure into the remote state file.
- 4Execute terraform plan to verify that the HCL configuration matches the imported state with zero proposed infrastructure changes.
Answer
The correct operational order is: 1) Write the HCL configuration code and specify the backend, 2) Run terraform init to configure backend state storage and provider plugins, 3) Execute terraform import commands to map live resources to state, and 4) Run terraform plan to validate zero drift before active management.
The correct sequence begins by defining the resource blocks and backend parameters in HCL. Next, initializing the workspace (`terraform init`) downloads the GCP provider and connects to the GCS remote backend. Once initialized, existing GCP resources can be bound to the state file using `terraform import`. Finally, running `terraform plan` confirms that the HCL definitions perfectly mirror the imported resources, ensuring future automation will not cause unwanted resource replacement.
Step-by-Step Solution
Key Concept
Brownfield Infrastructure as Code Adoption and Resource Import Workflow