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.
Question
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)- A9% (5)
- B4% (2)
- C4% (2)
- D84% (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.
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.
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.
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.
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
Community Discussion
No community discussion yet for this question.