Soru

Zorluk: OrtaImplementing Infrastructure as Code using Terraform and Deployment Manager

A cloud architect is standardizing an organization's infrastructure automation practices. The team needs to safely transition a local Terraform state file to a centralized Google Cloud Storage (GCS) backend to support team collaboration and state locking. In what order should the architect execute the steps for this migration process?

  1. 1Provision a dedicated Cloud Storage bucket with object versioning enabled and uniform bucket-level access enforced.
  2. 2Add a backend "gcs" configuration block specifying the bucket name and state prefix to the Terraform root module.
  3. 3Execute terraform init and approve the prompt to copy the existing local state to the new Cloud Storage backend.
  4. 4Remove the local terraform.tfstate file and enforce least-privilege IAM permissions on the GCS bucket.

Cevap

The correct sequence of steps is: first provision the GCS bucket with versioning, next define the gcs backend configuration block, then execute terraform init to migrate the state file, and finally delete the local state file while restricting bucket permissions.
Establishing a GCS remote backend requires provisioning the prerequisite Cloud Storage bucket first, declaring the backend gcs block in configuration code second, running terraform init to trigger state migration third, and completing post-migration local cleanup and access restriction fourth.

Adım Adım Çözüm

1
Provision GCS Bucket
A secure, version-enabled GCS bucket is created.
Terraform requires an existing GCS bucket endpoint before it can store state remotely.
2
Declare GCS Backend
The Terraform root configuration references the target GCS bucket and path prefix.
Terraform CLI relies on backend configuration code to determine where remote state operations are targeted.
3
Run Initialization and Migrate
Local state is uploaded to GCS and state lock tracking is initialized.
Executing terraform init detects backend changes and prompts to transfer local state to the newly configured GCS backend.
4
Post-Migration Cleanup and Security
Local state file is removed and IAM permissions are configured for state protection.
Prevents state drift or accidental state file exposure, while ensuring team access follows least-privilege security controls.

Anahtar Kavram

Remote Infrastructure State Management and Migration in Terraform
Bu soruyu puanla