I'm looking to put together a script that I can run from Cloud Shell to enable an API in all projects. It is successfully going through each project, but I am getting a permission denied message for every one. I am the owner so there shouldn't be any permission issues.
As a permission test, if I run just "gcloud services enable cloudresourcemanager.googleapis.com", the API successfully enables.
What am I missing?
#!/bin/bash
for project in  $(gcloud projects list --format="value(projectId)")
do
    echo "ProjectId:  $project"
    for enableapi in $(gcloud services enable cloudresourcemanager.googleapis.com list --project $project --format=list)
     do
        echo "    -> Enabled $enableapi"
    done
done
Lucas, this way could work:
#!/bin/bash
for project in  $(gcloud projects list --format="value(projectId)")
do
    echo "ProjectId:  $project"
    gcloud config set project $project
    gcloud services enable cloudresourcemanager.googleapis.com  --project $project
done
I'm following this doc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With