Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: (gcloud.services.enable) User does not have permission to access project (or it may not exist): The caller does not have permission

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
like image 916
Lucas Avatar asked Feb 19 '19 00:02

Lucas


Video Answer


1 Answers

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.

like image 120
hkanjih Avatar answered Oct 14 '22 09:10

hkanjih