This document provides details on how to create and update labels for projects using gcloud CLI, the Cloud Resource Manager API, and the Cloud de Confiance console.
Create labels for projects
To add labels to a single project: Open the Labels page in the Cloud de Confiance console. Select your project from the Select a project drop-down. To add a new label entry, click + Add label and enter a label key and
value for each label you want to add. When you're finished adding labels, click Save. To add labels for more than one project at the same time: Open the Manage resources page in the Cloud de Confiance console. On the Manage resources page, select the projects for
which you want to add labels. In the info panel, in the Labels tab, click + Add label and
enter a label key and value for each label you want to add. When you're finished adding labels, click Save. After you add labels, you can filter projects by typing a label key or value in
the filter box above the projects list. The filter box will suggest keys and
values so you can preview results.Console
To create a new project with labels using gcloud CLI, use the
To add labels to an existing project, use the Where:gcloud
gcloud projects create command with the --labels flag:
gcloud projects create PROJECT_ID \
--labels=KEY1=VALUE1,KEY2=VALUE2
gcloud projects update
command with the --update-labels flag:
gcloud projects update PROJECT_ID \
--update-labels=KEY1=VALUE1,KEY2=VALUE2
PROJECT_ID is the ID of the project you want to create
or update.KEY1=VALUE1 is a key-value pair for the
label you want to add.
To create a new project with a label, include the To add labels to an existing project, use the REST
labels field when you
make a POST request to the projects.create method:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{
"projectId": "PROJECT_ID",
"displayName": "PROJECT_NAME",
"labels": {
"environment": "development"
}
}' \
"https://cloudresourcemanager.googleapis.com/v3/projects"
projects.patch method:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{
"labels": {
"environment": "development"
}
}' \
"https://cloudresourcemanager.googleapis.com/v3/projects/PROJECT_ID?updateMask=labels"
Update labels for projects
Console
To update labels for a single project:
Open the Labels page in the Cloud de Confiance console.
Select your project from the Select a project drop-down.
Update the labels for your project:
- To edit a label, click the value that you want to edit, then make your desired changes.
- To delete a label, hold the pointer over the key or value, then click .
When you're finished updating labels, click Save.
To update labels for more than one project at the same time:
Open the Manage resources page in the Cloud de Confiance console.
On the Manage resources page, select the projects for which you want to update labels.
In the info panel, click the Labels tab and update labels for the selected projects:
- To edit a label, click the value that you want to edit, then make your desired changes.
- To delete a label, hold the pointer over the key or value, then click .
When you're finished updating labels, click Save.
To update labels for a project using gcloud CLI, use the
To add or update labels: To remove specific labels: To remove all labels from a project:gcloud
gcloud projects update command with the --update-labels, --remove-labels,
or --clear-labels flag.
gcloud projects update PROJECT_ID \
--update-labels=KEY1=VALUE1,KEY2=VALUE2
gcloud projects update PROJECT_ID \
--remove-labels=KEY1,KEY2
gcloud projects update PROJECT_ID \
--clear-labels
To update a project's labels using the API, send a Where REST
PATCH request to the
projects.patch method:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
-d '{
"labels": {
"color": "red"
}
}' \
"https://cloudresourcemanager.googleapis.com/v3/projects/PROJECT_ID?updateMask=labels"
PROJECT_ID is the ID of the project you want to
update.