Whenever I try to deploy a Google Cloud Platform (GCP) Cloud Function, I encounter this error. However, when I check the dashboard, the function has deployed correctly.
Preparing function...
.done.
Updating function (may take a while)...
[Build].....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................warning
[Service]........................................................................warning
Completed with warnings:
Warning: G] *** Improve build performance by generating and committing package-lock.json.
[INFO] A new revision will be deployed serving with 100% traffic.
ERROR: (gcloud.functions.deploy) ResponseError: status=[403], code=[Ok], message=[Permission 'run.services.setIamPolicy' denied on resource 'projects/my-project-abcdef/locations/us-central1/services/my-function-name' (or resource may not exist).]
Error: Process completed with exit code 1.
My IAM service account has the following permissions:
And in the Cloud Build settings panel, the IAM service account has both the Cloud Functions and Service Accounts services enabled.
I found out adding Cloud Functions Admin role to the IAM service account fixed the issue. I'm not sure if that's the suggested way but it works.