Soru

Zorluk: OrtaBuilding and Managing Infrastructure as Code (IaC)

A retail organization wants to bring a manually created Google Cloud Storage bucket used for transactional archives under Terraform management without destroying the existing bucket. Which sequence of operational steps must the Cloud Architect execute to safely import the bucket into the Terraform state using declarative import configuration?

  1. 1Declare the resource block for the Cloud Storage bucket and write a corresponding import block specifying the target resource address and GCP bucket identifier in the Terraform configuration file.
  2. 2Run terraform plan to inspect the execution plan, verifying that Terraform matches the live GCP storage bucket configuration without requesting unexpected resource recreation.
  3. 3Run terraform apply to lock the remote Cloud Storage state backend and record the bucket's live attributes into the state file.
  4. 4Remove the temporary import block from the Terraform configuration while retaining the resource block for future CI/CD pipeline management.

Cevap

The correct operational sequence is: 1) Declare the resource and import blocks in the HCL configuration file, 2) Execute terraform plan to inspect the import plan without introducing resource destruction, 3) Execute terraform apply to bind the live resource into the remote Cloud Storage state file while acquiring backend locks, and 4) Remove the temporary import block from the configuration.
The correct sequence follows Google Cloud and Terraform best practices for brownfield IaC onboarding: configuration declaration (resource and import blocks), plan verification to prevent resource destruction, apply execution to update state safely with remote backend locking, and post-import cleanup of temporary import metadata.

Adım Adım Çözüm

1
Define the target resource block along with an import block specifying the HCL address and live GCP bucket name.
Terraform configuration is prepared with declarative import metadata.
Terraform requires both the HCL schema target and live resource mapping to process an import.
2
Run terraform plan.
The plan output displays an import action without showing any resource replacements or deletions.
Running plan validates that configuration definitions match live infrastructure attributes, preventing accidental destruction.
3
Run terraform apply.
The live resource state is imported into the Google Cloud Storage backend state file.
Applying the plan persists the imported resource into state while maintaining state lock integrity.
4
Remove the import block from the code repository.
The configuration contains only standard resource blocks for ongoing deployment operations.
Leaving import blocks after state registration causes redundant evaluation during future CI/CD execution.

Anahtar Kavram

Declarative Infrastructure as Code resource import workflow and state management
Bu soruyu puanla