Google Cloud Resource Manager API client library for managing projects, folders, organizations, and tags in Google Cloud Platform
—
Management of specific values within tag categories, providing the actual tags that can be applied to Google Cloud resources. TagValues represent the "value" portion of key-value tags and must be created under existing TagKeys.
Retrieve detailed information about a specific TagValue using its resource name.
def get_tag_value(
self,
request: GetTagValueRequest = None,
*,
name: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> TagValue:
"""
Retrieves a TagValue identified by the specified resource name.
Args:
name (str): The resource name of the TagValue to retrieve.
Format: tagValues/{tag_value_id}
retry: Retry configuration for the request
timeout: Request timeout in seconds
metadata: Additional metadata to send with the request
Returns:
TagValue: The requested TagValue resource
Raises:
google.api_core.exceptions.NotFound: If the TagValue doesn't exist
google.api_core.exceptions.PermissionDenied: If access is denied
"""Retrieve a TagValue using its namespaced name format for more intuitive access.
def get_namespaced_tag_value(
self,
request: GetNamespacedTagValueRequest = None,
*,
name: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> TagValue:
"""
Retrieves a TagValue by its namespaced name.
Args:
name (str): The namespaced name of the TagValue.
Format: {parent_id}/{tag_key_short_name}/{tag_value_short_name}
Example: 123456789/environment/production
retry: Retry configuration for the request
timeout: Request timeout in seconds
metadata: Additional metadata to send with the request
Returns:
TagValue: The requested TagValue resource
"""Usage example:
from google.cloud.resourcemanager import TagValuesClient
client = TagValuesClient()
# Get by resource name
tag_value = client.get_tag_value(name="tagValues/281484271805522")
print(f"TagValue: {tag_value.short_name} - {tag_value.description}")
# Get by namespaced name (more intuitive)
tag_value = client.get_namespaced_tag_value(name="123456789/environment/production")
print(f"TagValue: {tag_value.short_name} under {tag_value.parent}")List all TagValues under a specified TagKey.
def list_tag_values(
self,
request: ListTagValuesRequest = None,
*,
parent: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> pagers.ListTagValuesPager:
"""
Lists TagValues that are direct children of the specified TagKey.
Args:
parent (str): The parent TagKey whose TagValues are to be listed.
Format: tagKeys/{tag_key_id}
retry: Retry configuration for the request
timeout: Request timeout in seconds
metadata: Additional metadata to send with the request
Returns:
ListTagValuesPager: An iterator over TagValues that automatically
handles pagination
"""Usage example:
client = TagValuesClient()
# List all TagValues under a TagKey
for tag_value in client.list_tag_values(parent="tagKeys/281484271805521"):
print(f"TagValue: {tag_value.short_name} - {tag_value.description}")
print(f" Namespaced: {tag_value.namespaced_name}")Create new TagValues under existing TagKeys. This is a long-running operation.
def create_tag_value(
self,
request: CreateTagValueRequest = None,
*,
tag_value: TagValue = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> operation.Operation:
"""
Creates a new TagValue. This is a long-running operation.
Args:
tag_value (TagValue): The TagValue resource to create
retry: Retry configuration for the request
timeout: Request timeout in seconds
metadata: Additional metadata to send with the request
Returns:
Operation: Long-running operation that resolves to the created TagValue
"""Usage example:
from google.cloud.resourcemanager import TagValuesClient
from google.cloud.resourcemanager_v3.types import TagValue
client = TagValuesClient()
new_tag_value = TagValue(
parent="tagKeys/281484271805521", # Must be an existing TagKey
short_name="production",
description="Production environment resources"
)
operation = client.create_tag_value(tag_value=new_tag_value)
result = operation.result() # Wait for completion
print(f"Created TagValue: {result.short_name} ({result.name})")
print(f"Namespaced name: {result.namespaced_name}")Update TagValue attributes such as description. This is a long-running operation.
def update_tag_value(
self,
request: UpdateTagValueRequest = None,
*,
tag_value: TagValue = None,
update_mask: field_mask_pb2.FieldMask = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> operation.Operation:
"""
Updates the specified TagValue. This is a long-running operation.
Args:
tag_value (TagValue): The TagValue resource with updated values
update_mask (FieldMask): Fields to update. If not provided,
all mutable fields are updated
retry: Retry configuration for the request
timeout: Request timeout in seconds
metadata: Additional metadata to send with the request
Returns:
Operation: Long-running operation that resolves to the updated TagValue
"""Usage example:
from google.protobuf import field_mask_pb2
client = TagValuesClient()
# Get existing TagValue
tag_value = client.get_tag_value(name="tagValues/281484271805522")
# Update description
tag_value.description = "Updated production environment resources"
# Specify which fields to update
update_mask = field_mask_pb2.FieldMask(paths=["description"])
operation = client.update_tag_value(
tag_value=tag_value,
update_mask=update_mask
)
result = operation.result()
print(f"Updated TagValue: {result.description}")Delete TagValues if no TagBindings exist. This is a long-running operation that permanently removes the TagValue.
def delete_tag_value(
self,
request: DeleteTagValueRequest = None,
*,
name: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> operation.Operation:
"""
Deletes a TagValue if no TagBindings exist. This is a long-running operation.
The TagValue must have no active TagBindings to be deleted.
Args:
name (str): The resource name of the TagValue to delete.
Format: tagValues/{tag_value_id}
retry: Retry configuration for the request
timeout: Request timeout in seconds
metadata: Additional metadata to send with the request
Returns:
Operation: Long-running operation with no return value
Raises:
google.api_core.exceptions.FailedPrecondition: If TagValue has active TagBindings
"""Usage example:
client = TagValuesClient()
# Delete a TagValue (only works if no TagBindings exist)
operation = client.delete_tag_value(name="tagValues/281484271805522")
operation.result() # Wait for completion
print("TagValue deleted successfully")Manage IAM (Identity and Access Management) policies for TagValues, controlling who can bind these tags to resources.
def get_iam_policy(
self,
request: iam_policy_pb2.GetIamPolicyRequest = None,
*,
resource: str = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> policy_pb2.Policy:
"""
Gets the IAM access control policy for a TagValue.
Args:
resource (str): Resource name of the TagValue.
Format: tagValues/{tag_value_id}
Returns:
Policy: The IAM policy for the TagValue
"""
def set_iam_policy(
self,
request: iam_policy_pb2.SetIamPolicyRequest = None,
*,
resource: str = None,
policy: policy_pb2.Policy = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> policy_pb2.Policy:
"""
Sets the IAM access control policy for a TagValue.
Args:
resource (str): Resource name of the TagValue
policy (Policy): The new IAM policy
Returns:
Policy: The updated IAM policy
"""
def test_iam_permissions(
self,
request: iam_policy_pb2.TestIamPermissionsRequest = None,
*,
resource: str = None,
permissions: MutableSequence[str] = None,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
) -> iam_policy_pb2.TestIamPermissionsResponse:
"""
Tests the specified permissions against the IAM policy for a TagValue.
Args:
resource (str): Resource name of the TagValue
permissions (Sequence[str]): List of permissions to test
Returns:
TestIamPermissionsResponse: Results of the permission test
"""class TagValue:
name: str # Resource name: tagValues/{tag_value_id}
parent: str # Parent TagKey: tagKeys/{tag_key_id}
short_name: str # User-assigned short name (e.g., "production")
namespaced_name: str # Computed field: {parent_org_id}/{tag_key_short_name}/{short_name}
display_name: str # Human-readable display name
description: str # Description of the TagValue's purpose
create_time: timestamp_pb2.Timestamp # Creation timestamp
update_time: timestamp_pb2.Timestamp # Last update timestamp
etag: str # Entity tag for optimistic concurrency
# Request/Response types
class GetTagValueRequest:
name: str
class GetNamespacedTagValueRequest:
name: str # Format: {parent_org_id}/{tag_key_short_name}/{tag_value_short_name}
class ListTagValuesRequest:
parent: str # Format: tagKeys/{tag_key_id}
page_token: str
page_size: int
class ListTagValuesResponse:
tag_values: MutableSequence[TagValue]
next_page_token: str
class CreateTagValueRequest:
tag_value: TagValue
validate_only: bool # If true, validate request without creating
class UpdateTagValueRequest:
tag_value: TagValue
update_mask: field_mask_pb2.FieldMask
validate_only: bool
class DeleteTagValueRequest:
name: str
validate_only: bool
etag: str # Current etag for optimistic concurrency
# Metadata types for long-running operations
class CreateTagValueMetadata:
# Empty metadata message
class UpdateTagValueMetadata:
# Empty metadata message
class DeleteTagValueMetadata:
# Empty metadata messageTagValues must be created under existing TagKeys and follow a hierarchical naming structure. The namespaced name provides a human-readable path that makes it easier to understand the tag hierarchy, following the format: {organization_id}/{tag_key_short_name}/{tag_value_short_name}.
TagValues cannot be deleted if they have active TagBindings. You must first remove all TagBindings for a TagValue before it can be deleted.
Install with Tessl CLI
npx tessl i tessl/pypi-google-cloud-resource-manager