We are triggering a bitbucket pipeline which provisions resources via terraform.
Service account with a role(comprising of appropriate permissions) is passed to job to make sure job succeeds.
While provisioning a google alert we saw below error
╷
│ Error: Error creating AlertPolicy: googleapi: Error 403: The caller does not have permission
│
│ with module.abc.google_monitoring_alert_policy.abc_error,
Role which is attached to service account has several permissions including related to alerting
monitoring.alertPolicies.create
monitoring.alertPolicies.delete
monitoring.alertPolicies.get
monitoring.alertPolicies.update
So it has permission to create alert policy but it is failing.
I encountered a similar problem and resolved it by updating the permissions as outlined in this document:
Permissions Required for Log-Based Alerts: Google Cloud Logging Access Control - Log-Based Alert Permissions
It turned out that the
roles/logging.configWriter
role was not assigned to my service account, and adding it resolved the issue.