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.
There are 4 IAM roles and anyone of those three should be in place to create alerting policy in GCP
Monitoring Editor
Grants read-write access to Monitoring in the Google Cloud console and API, and grants read-write access to a metrics scope when using the Google Cloud console. Write access to a metrics scope grants permission to add (or remove) monitored Google Cloud projects to that metrics scope.
Predefined role :
roles/monitoring.editorMonitoring Admin
Grants full access to Monitoring in the Google Cloud console and API, and grants read-write access to a metrics scope. Write access to a metrics scope grants permission to add (or remove) monitored Google Cloud projects to that metrics scope.
Predefined role :
roles/monitoring.adminProject Owner
The Monitoring permissions are the same as those in roles/monitoring.admin.
Predefined role :
roles/ownerAlert Policy Editor
This role ID grants the minimal permissions that are needed to create an alerting policy. It has
Predefined role :
roles/monitoring.alertPolicyEditorUse either predefined role
roles/monitoring.alertPolicyEditoror addmonitoring.alertPolicies.listin order to create a alert policy.Note :
Sometimes an alerting policy requires some extra permissions related to cloud logging and notification channels so you might need to provide
roles/monitoring.editorrole to create alerting policy.References :
https://cloud.google.com/monitoring/alerts#cc-perms https://cloud.google.com/monitoring/alerts#api-perms