Soru

Zorluk: OrtaBuilding and Managing Infrastructure as Code (IaC)

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.

  1. 1Write the Terraform configuration files (HCL) matching the existing infrastructure resource attributes and specify the Cloud Storage backend block.
  2. 2Run terraform init to download required GCP provider plugins and configure the remote Cloud Storage backend for state locking.
  3. 3Execute terraform import commands targeting each resource ID to map existing GCP infrastructure into the remote state file.
  4. 4Execute terraform plan to verify that the HCL configuration matches the imported state with zero proposed infrastructure changes.

Cevap

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.

Adım Adım Çözüm

1
Define configuration and backend
HCL code is declared with backend metadata.
Terraform needs resource block declarations and backend settings before initialization.
2
Initialize Terraform backend
Provider plugins are downloaded and GCS remote backend is activated.
Backend initialization establishes state locking mechanisms in Cloud Storage before state modifications occur.
3
Import live infrastructure into state
Remote state file is populated with existing resource attributes.
Terraform import updates state metadata so Terraform becomes aware of existing GCP resources.
4
Validate state alignment via plan
Verification confirms zero proposed modifications.
Validating alignment ensures HCL configuration accurate matches live infrastructure prior to applying continuous deployments.

Anahtar Kavram

Brownfield Infrastructure as Code Adoption and Resource Import Workflow
Bu soruyu puanla