A cloud architecture team at a healthcare informatics enterprise is transitioning manually provisioned Google Cloud VPC networks and subnetworks into an automated Infrastructure as Code (IaC) workflow managed by Terraform. The team must establish remote state management with state locking, avoid resource recreation, and ensure existing production workloads experience zero downtime during the adoption process. What is the correct sequence of steps to safely import these unmanaged GCP infrastructure resources into Terraform state and align the HCL configuration?
- 1Provision a Google Cloud Storage bucket with object versioning enabled and define the backend "gcs" block in the Terraform root module.
- 2Execute terraform init to configure remote backend state storage and download required provider plugins.
- 3Write skeleton HCL resource blocks in the local module matching the resource types of the target VPC network and subnetworks.
- 4Execute terraform import commands referencing declared resource addresses and their full GCP resource URIs.
- 5Run terraform plan and iteratively align HCL resource arguments until the execution plan outputs zero changes.
Cevap
The correct operational sequence begins with establishing the Cloud Storage backend configuration and versioning, followed by running terraform init to initialize backend locks. Next, empty or skeleton resource blocks must be declared in HCL so that terraform import commands can bind GCP resource URIs to state addresses. Finally, running terraform plan and adjusting HCL attributes until zero differences remain ensures complete state and code parity without service disruption.
The sequence correctly follows Google Cloud and Terraform best practices for brownfield adoption: 1) Backend setup (GCS bucket + code block), 2) Workspace initialization (terraform init), 3) HCL block declaration, 4) Resource state import (terraform import), and 5) Plan validation and attribute alignment (terraform plan).
Adım Adım Çözüm
Anahtar Kavram
Brownfield Infrastructure Import and IaC State Alignment