1

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.

Atharva
  • 11
  • 2
  • You're not paging through results but, more importantly, I think you need to list the Folders at each level and then (recursively) enumerate the Projects that have each of the Folders as their parent. See: https://cloud.google.com/resource-manager/docs/listing-all-resources#list_all_resources_example – DazWilkin Jun 12 '22 at 02:16

0 Answers0