nerdexam
Google

PROFESSIONAL-CLOUD-DEVOPS-ENGINEER · Question #165

You are deploying a Cloud Build job that deploys Terraform code when a Git branch is updated. While testing, you noticed that the job fails. You see the following error in the build logs…

The correct answer is D. Grant the roles/storage.objectAdmin Identity and Access Management (1AM) role to the Cloud. The Cloud Build job is failing with a 403 error when querying Cloud Storage for Terraform state, indicating a permission issue where the Cloud Build service account lacks the necessary IAM role to access the Cloud Storage bucket.

Submitted by kavita_s· Apr 18, 2026Building and implementing CI/CD pipelines for a service

Question

You are deploying a Cloud Build job that deploys Terraform code when a Git branch is updated. While testing, you noticed that the job fails. You see the following error in the build logs: Initializing the backend... Error: Failed to get existing workspaces: querying Cloud Storage failed: googleapi: Error 403 You need to resolve the issue by following Google-recommended practices. What should you do?

Options

  • AChange the Terraform code to use local state.
  • BCreate a storage bucket with the name specified in the Terraform configuration.
  • CGrant the roles/owner Identity and Access Management (IAM) role to the Cloud Build service
  • DGrant the roles/storage.objectAdmin Identity and Access Management (1AM) role to the Cloud

How the community answered

(55 responses)
  • A
    9% (5)
  • B
    4% (2)
  • C
    4% (2)
  • D
    84% (46)

Why each option

The Cloud Build job is failing with a 403 error when querying Cloud Storage for Terraform state, indicating a permission issue where the Cloud Build service account lacks the necessary IAM role to access the Cloud Storage bucket.

AChange the Terraform code to use local state.

Changing to local state would eliminate the Cloud Storage backend issue but is not a recommended practice for collaborative Terraform development in a CI/CD pipeline, as it makes state management difficult for multiple users.

BCreate a storage bucket with the name specified in the Terraform configuration.

The error `Error 403` implies the bucket exists but access is denied; if the bucket was missing, the error would typically be 'bucket not found' or similar.

CGrant the roles/owner Identity and Access Management (IAM) role to the Cloud Build service

Granting `roles/owner` is an overly permissive role and goes against the principle of least privilege, as `roles/storage.objectAdmin` is sufficient and more secure for managing objects in a specific bucket.

DGrant the roles/storage.objectAdmin Identity and Access Management (1AM) role to the CloudCorrect

The `Error 403` when querying Cloud Storage indicates a permission denied error. The Cloud Build service account, which executes the Terraform code using a Cloud Storage backend, requires the `roles/storage.objectAdmin` role on the specific Cloud Storage bucket to read and write Terraform state files, thus resolving the authentication issue with appropriate least privilege.

Concept tested: Cloud Build IAM permissions for Cloud Storage Terraform backend

Source: https://cloud.google.com/terraform/docs/configure-backend#access_control_for_the_backend

Topics

#Cloud Build#IAM#Terraform state#Permissions

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVOPS-ENGINEER Practice