Soru

Zorluk: OrtaBuilding and Managing Infrastructure as Code (IaC)

An interactive game streaming platform needs to transition its manually provisioned Google Cloud Bigtable clusters and Cloud Storage assets into Terraform management. The platform team requires a safe operational workflow that uses a remote Google Cloud Storage (GCS) backend with state locking to prevent state corruption or service disruption. Arrange the operational steps in the correct sequence to import existing cloud resources into Terraform state.

  1. 1Write the Terraform HCL code blocks defining the expected resource schema and configure the GCS remote backend stanza.
  2. 2Run `terraform init` to set up the GCS backend connection and download the Google provider plugins.
  3. 3Execute `terraform import` commands mapping the existing GCP resource identifiers to their declared Terraform HCL resource addresses.
  4. 4Run `terraform plan` to inspect for configuration drift and confirm that no resource modification or destruction is scheduled.
  5. 5Execute `terraform apply` to commit the synchronized state and establish the automated pipeline baseline.

Cevap

The correct operational sequence is: 1) Write the Terraform HCL code blocks and backend configuration, 2) Run `terraform init` to initialize the remote backend, 3) Execute `terraform import` to bind GCP resource IDs to state, 4) Run `terraform plan` to verify zero drift or unwanted changes, and 5) Execute `terraform apply` to commit the baseline state.
Safely bringing brownfield resources into Terraform management requires defining matching HCL configurations, initializing the GCS remote backend to secure state locks, importing existing GCP resource IDs into state, verifying zero unexpected diffs via `terraform plan`, and finally applying to lock in baseline operational state.

Adım Adım Çözüm

1
Define HCL resource definitions and backend configuration
Local HCL files describe the target infrastructure schema and specify the GCS state bucket location.
Terraform requires code declarations and backend configuration before state operations can be performed.
2
Execute `terraform init`
The GCS remote state backend is initialized and Google Cloud provider plugins are downloaded.
Backend initialization establishes connectivity and locking mechanisms required for state storage.
3
Run `terraform import` commands
Live GCP infrastructure objects are mapped to Terraform resource addresses inside the GCS remote state file.
Importing populates state with existing resource attributes without recreating live infrastructure.
4
Perform `terraform plan` verification
Terraform compares declared HCL with the imported state and outputs a diff report.
Verification ensures that declared configuration attributes match existing GCP resource parameters to prevent accidental destruction.
5
Run `terraform apply`
The baseline state synchronization is finalized and locked under remote IaC pipeline governance.
Applying completes the import process and verifies that the live environment is fully managed via IaC.

Anahtar Kavram

Brownfield Infrastructure as Code Import Workflow
Bu soruyu puanla