Question

Difficulty: MediumInfrastructure as Code and Environment Provisioning

An enterprise platform engineering team is configuring an automated Cloud Build pipeline to provision a isolated staging environment on Google Cloud using Terraform. Place the procedural steps in the correct order to execute a secure, reliable environment provisioning workflow following Google Cloud best practices.

  1. 1Authenticate the CI/CD pipeline worker using Workload Identity Federation to obtain short-lived credentials for the designated Terraform deployment service account.
  2. 2Execute `terraform init` to configure the Cloud Storage remote backend and acquire an exclusive state lock on the environment state file.
  3. 3Run `terraform plan -out=tfplan` to validate configuration syntax, analyze resource drift, and output a speculative execution plan artifact.
  4. 4Execute `terraform apply tfplan` to provision targeted GCP resources strictly according to the saved plan file.
  5. 5Run post-provisioning automated health checks against the environment endpoints and release the state lock upon successful verification.

Answer

The correct sequence for environment provisioning is: 1) Authenticate pipeline identity via Workload Identity Federation, 2) Initialize Terraform backend and acquire GCS state lock, 3) Generate a deterministic execution plan artifact, 4) Apply the saved execution plan artifact, and 5) Run post-deployment validation tests and release state locks.
The sequence follows GCP enterprise reliability best practices: establish identity authentication first via Workload Identity Federation, initialize the remote backend to lock state and prevent concurrent updates, generate a deterministic plan artifact to lock in expected changes, apply the exact plan artifact to provision resources, and complete post-provisioning integration testing before releasing state locks.

Step-by-Step Solution

1
Authenticate pipeline service account
Pipeline worker gains temporary authorization without relying on long-lived service account keys.
Workload Identity Federation provides least-privilege security before any backend or API calls occur.
2
Initialize Terraform remote backend
GCS backend establishes connection and acquires state lock.
Remote state initialization is necessary before state drift evaluation or execution planning.
3
Generate plan artifact (`terraform plan -out=tfplan`)
Speculative plan artifact is calculated and saved.
Saving the plan artifact prevents race conditions where cloud state changes between plan and apply steps.
4
Apply the saved plan artifact (`terraform apply tfplan`)
GCP resources are created and configured exactly as planned.
Passing the stored plan guarantees idempotency and deterministic deployment.
5
Execute post-deployment validation
Environment reliability is confirmed and lock is released.
Automated validation ensures operational readiness before declaring successful deployment.

Key Concept

Automated Environment Provisioning & IaC State Lifecycle
Estimated Time:1m 30s
Rate this question