I am not able to list all the projects in my GCP organization using Python

610 Views Asked by At

I need to list all projects under an Organization in GCP. I am using Resource Manager for the same.

def list_projects():
proj_list = []
credentials = service_account.Credentials.from_service_account_file('../key.json')
# Create resourcemanager_v3 ProjectsClient
resourcemanager_v3_projects_client = resourcemanager_v3.ProjectsClient(credentials=credentials)
#resourcemanager_v3_projects_client = resourcemanager_v3.ProjectsClient()
list_projects_request = resourcemanager_v3.ListProjectsRequest(show_deleted=False, parent='organizations/12345')
page_result = resourcemanager_v3_projects_client.list_projects(request=list_projects_request)

for response in page_result:
  proj_list.append(response.project_id)

The above Code skips all the projects under a Folder. The Service Account running this code has Organization Administrator and Folder Viewer Roles.

0

There are 0 best solutions below