I have several projects under an organization in GCP.I have an service account with certain scopes set on a project (for automation).I wanted to add the same service account to all other projects as an member, I did manually until now.
is there any way I can automate this, like whenever a project is created the service account along with its scopes should be added as its member?
If you're using Terraform to create the projects the idea would remain the same. Just as for creating projects in GCP, there's an equivalent
gcloudcommand and aRESTAPI behind it. Thegcloudcommand specifically would begcloud projects add-iam-policy-binding:Here's a Terraform example you can use:
main.tffile or anything else you want to call the Terraform config file.[email protected]with your Service Account,roles/editorwith the role you want to give it andyour-project-idwith your Project ID.terraform applyin the same directory the Terraform config file is at.I think you could even use Ansible for that. Or if you really want to, create a
Bashscript.