Question

Difficulty: MediumDeploying Infrastructure using Deployment Manager or Terraform

A Cloud Engineer is setting up an automated Google Cloud infrastructure deployment process using Terraform. To follow Google Cloud security and operational best practices, the engineer must ensure that team members can collaborate without state file conflicts and that deployment processes do not rely on static, long-lived authentication keys. Which two actions should the engineer take to achieve this configuration?

  1. Configure a `backend "gcs"` block in the Terraform configuration to store the state file in a central Cloud Storage bucket with object versioning enabled.Answer
  2. Configure the automated CI/CD pipeline to use IAM Service Account Impersonation or Workload Identity Federation for authenticating Terraform commands.Answer
  3. C
    Commit and push the local `terraform.tfstate` file into the shared source control repository so all developers have access to state changes.
  4. D
    Enable all required resource APIs in the organization billing project rather than enabling them in the target infrastructure project.

Answer

The correct configuration requires defining a Cloud Storage remote backend (`backend "gcs"`) with object versioning enabled for state locking and backup, and configuring authentication using IAM Service Account Impersonation or Workload Identity Federation instead of static service account keys.
Configuring the `backend "gcs"` block allows Terraform to manage state centrally in a Cloud Storage bucket with locking and versioning. Authenticating using IAM Service Account Impersonation or Workload Identity Federation ensures zero long-lived key storage, aligning with GCP security principles.

Step-by-Step Solution

1
Configure remote state storage in Cloud Storage
Terraform state is stored securely in a central GCS bucket with state locking to prevent concurrent state corruption.
Remote state backends allow teams to collaborate safely and prevent state file sync issues.
2
Configure passwordless IAM authentication
Short-lived tokens are issued automatically via IAM Service Account Impersonation or Workload Identity.
Static long-lived JSON keys pose credential leak risks and violate security best practices.

Key Concept

Terraform Remote Backend and IAM Authentication Best Practices in GCP
Rate this question