google-cloud-resourcemanager overview (1.4.0)

com.google.cloud.resourcemanager

A client for Cloud Resource Manager - Centrally manage all your projects, IAM, and resource containers.

Here's a simple usage example for using google-cloud from App/Compute Engine. This example creates a project if it does not exist. For the complete source code see GetOrCreateProject.java.


ResourceManagerresourceManager=ResourceManagerOptions.getDefaultInstance().getService();
StringprojectId="my-globally-unique-project-id";// Change to a unique project ID.
Projectproject=resourceManager.get(projectId);
if(project==null){
project=resourceManager.create(ProjectInfo.builder(projectId).build());
}
System.out.println("Got project "+project.getProjectId()+" from the server.");

This second example shows how to update a project if it exists and list all projects the user has permission to view. For the complete source code see UpdateAndListProjects.java.


ResourceManagerresourceManager=ResourceManagerOptions.getDefaultInstance().getService();
Projectproject=resourceManager.get("some-project-id");// Use an existing project's ID
if(project!=null){
ProjectnewProject=project.toBuilder()
.addLabel("launch-status","in-development")
.build()
.replace();
System.out.println("Updated the labels of project "+newProject.getProjectId()
+" to be "+newProject.getLabels());
}
Iterator<Project>projectIterator=resourceManager.list().iterateAll();
System.out.println("Projects I can view:");
while(projectIterator.hasNext()){
System.out.println(projectIterator.next().getProjectId());
}

Remember that you must authenticate using the Google Cloud SDK. See more about providing credentials here. See Also: Google Cloud Resource Manager

com.google.cloud.resourcemanager.spi

com.google.cloud.resourcemanager.spi.v1beta1

com.google.cloud.resourcemanager.testing

A testing helper for Google Cloud Resource Manager.

A simple usage example: Before the test:


LocalResourceManagerHelperresourceManagerHelper=LocalResourceManagerHelper.create();
resourceManagerHelper.start();
ResourceManagerresourceManager=resourceManagerHelper.getOptions().getService();

After the test:


resourceManagerHelper.stop();

com.google.cloud.resourcemanager.v3

The interfaces provided are listed below, along with usage samples.

FoldersClient

Service Description: Manages Cloud Platform folder resources. Folders can be used to organize the resources under an organization and to control the policies applied to groups of resources.

Sample for FoldersClient:


// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try(FoldersClientfoldersClient=FoldersClient.create()){
FolderNamename=FolderName.of("[FOLDER]");
Folderresponse=foldersClient.getFolder(name);
}

OrganizationsClient

Service Description: Allows users to manage their organization resources.

Sample for OrganizationsClient:


// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try(OrganizationsClientorganizationsClient=OrganizationsClient.create()){
OrganizationNamename=OrganizationName.of("[ORGANIZATION]");
Organizationresponse=organizationsClient.getOrganization(name);
}

ProjectsClient

Service Description: Manages Google Cloud Projects.

Sample for ProjectsClient:


// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try(ProjectsClientprojectsClient=ProjectsClient.create()){
ProjectNamename=ProjectName.of("[PROJECT]");
Projectresponse=projectsClient.getProject(name);
}

TagBindingsClient

Service Description: Allow users to create and manage TagBindings between TagValues and different cloud resources throughout the GCP resource hierarchy.

Sample for TagBindingsClient:


// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try(TagBindingsClienttagBindingsClient=TagBindingsClient.create()){
ResourceNameparent=FolderName.of("[FOLDER]");
for(TagBindingelement:tagBindingsClient.listTagBindings(parent).iterateAll()){
// doThingsWith(element);
}
}

TagKeysClient

Service Description: Allow users to create and manage tag keys.

Sample for TagKeysClient:


// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try(TagKeysClienttagKeysClient=TagKeysClient.create()){
TagKeyNamename=TagKeyName.of("[TAG_KEY]");
TagKeyresponse=tagKeysClient.getTagKey(name);
}

TagValuesClient

Service Description: Allow users to create and manage tag values.

Sample for TagValuesClient:


// This snippet has been automatically generated for illustrative purposes only.
// It may require modifications to work in your environment.
try(TagValuesClienttagValuesClient=TagValuesClient.create()){
TagValueNamename=TagValueName.of("[TAG_VALUE]");
TagValueresponse=tagValuesClient.getTagValue(name);
}

com.google.cloud.resourcemanager.v3.stub

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年10月30日 UTC.