Labels
Projects and folders give you levels of segregation for resources, but sometimes you want more granularity than the hierarchy alone. Labels are the finer-grained tool: user-defined key-value pairs you attach to individual resources to organize, filter, and account for them.
What a label is
A label is a simple key:value string pair you attach to a resource. You can create and
manage them from the Google Cloud console, gcloud, or the Resource Manager API,
and they attach to resources like VMs, disks, snapshots, and images.
- Labels are key-value pairs, e.g.
environment:production. - Each resource can carry up to 64 labels.
- Manage them via the console,
gcloud, or the Resource Manager API. - They propagate through billing, so you can break costs down by label in exports and reports.
- Common uses: inventory (list all
environment:productionVMs), filtering resources, and scripts that analyze costs or run bulk operations across matching resources.
What to use labels for
Group resources along whatever dimension you need to report on or operate against. A few conventions worth knowing for the exam:
Labels vs network tags
Both are user-defined strings, but they do different jobs.
See Firewall rules for how network tags target VMs in a rule's filter.