CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-google-cloud-resource-manager

Google Cloud Resource Manager API client library for managing projects, folders, organizations, and tags in Google Cloud Platform

Pending
Overview
Eval results
Files

tag-bindings.mddocs/

Tag Bindings Management

Association and management of tag values with specific Google Cloud resources, including listing effective tags that apply to resources through inheritance. TagBindings create the actual association between TagValues and cloud resources, enabling policy enforcement and resource organization.

Capabilities

Tag Binding Creation

Create associations between TagValues and Google Cloud resources. This is a long-running operation.

def create_tag_binding(
    self,
    request: CreateTagBindingRequest = None,
    *,
    tag_binding: TagBinding = 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 TagBinding between a TagValue and a cloud resource. This is a long-running operation.

    Args:
        tag_binding (TagBinding): The TagBinding 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 TagBinding
    """

Usage example:

from google.cloud.resourcemanager import TagBindingsClient
from google.cloud.resourcemanager_v3.types import TagBinding

client = TagBindingsClient()

new_binding = TagBinding(
    parent="//cloudresourcemanager.googleapis.com/projects/my-project-123",
    tag_value="tagValues/281484271805522"  # Must be an existing TagValue
)

operation = client.create_tag_binding(tag_binding=new_binding)
result = operation.result()  # Wait for completion
print(f"Created TagBinding: {result.name}")
print(f"Resource: {result.parent}")
print(f"TagValue: {result.tag_value_namespaced_name}")

Tag Binding Listing

List all TagBindings for a specified Google Cloud resource.

def list_tag_bindings(
    self,
    request: ListTagBindingsRequest = 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.ListTagBindingsPager:
    """
    Lists TagBindings for a Google Cloud resource.

    Args:
        parent (str): The resource whose TagBindings are to be listed.
            Format: //SERVICE.googleapis.com/RESOURCE_TYPE/RESOURCE_ID
            Examples:
            - //cloudresourcemanager.googleapis.com/projects/my-project
            - //compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-vm
        retry: Retry configuration for the request
        timeout: Request timeout in seconds
        metadata: Additional metadata to send with the request

    Returns:
        ListTagBindingsPager: An iterator over TagBindings that automatically
                             handles pagination
    """

Usage example:

client = TagBindingsClient()

# List TagBindings for a project
for binding in client.list_tag_bindings(
    parent="//cloudresourcemanager.googleapis.com/projects/my-project"
):
    print(f"TagBinding: {binding.name}")
    print(f"  TagValue: {binding.tag_value_namespaced_name}")
    print(f"  Resource: {binding.parent}")

# List TagBindings for a specific resource
for binding in client.list_tag_bindings(
    parent="//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-vm"
):
    print(f"VM TagBinding: {binding.tag_value_namespaced_name}")

Tag Binding Deletion

Remove TagBinding associations between TagValues and cloud resources. This is a long-running operation.

def delete_tag_binding(
    self,
    request: DeleteTagBindingRequest = 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 TagBinding. This is a long-running operation.

    Args:
        name (str): The resource name of the TagBinding to delete.
                   Format: tagBindings/{tag_binding_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
    """

Usage example:

client = TagBindingsClient()

# Delete a specific TagBinding
operation = client.delete_tag_binding(name="tagBindings/some-binding-id")
operation.result()  # Wait for completion
print("TagBinding deleted successfully")

Effective Tags Listing

List effective tags for a Google Cloud resource, including tags inherited from parent resources in the hierarchy.

def list_effective_tags(
    self,
    request: ListEffectiveTagsRequest = 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.ListEffectiveTagsPager:
    """
    Lists effective tags for a Google Cloud resource, including inherited tags.

    Args:
        parent (str): The resource whose effective tags are to be listed.
            Format: //SERVICE.googleapis.com/RESOURCE_TYPE/RESOURCE_ID
            Examples:
            - //cloudresourcemanager.googleapis.com/projects/my-project
            - //compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-vm
        retry: Retry configuration for the request
        timeout: Request timeout in seconds
        metadata: Additional metadata to send with the request

    Returns:
        ListEffectiveTagsPager: An iterator over EffectiveTag resources
    """

Usage example:

client = TagBindingsClient()

# List all effective tags for a project (direct + inherited)
for effective_tag in client.list_effective_tags(
    parent="//cloudresourcemanager.googleapis.com/projects/my-project"
):
    print(f"Effective Tag: {effective_tag.namespaced_tag_key}/{effective_tag.namespaced_tag_value}")
    print(f"  Inherited: {effective_tag.inherited}")
    if effective_tag.inherited:
        print(f"  Inherited from: {effective_tag.tag_key_parent_name}")

# List effective tags for a specific resource
for effective_tag in client.list_effective_tags(
    parent="//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-vm"
):
    print(f"VM Effective Tag: {effective_tag.namespaced_tag_key}/{effective_tag.namespaced_tag_value}")

Types

class TagBinding:
    name: str  # Resource name: tagBindings/{tag_binding_id}
    parent: str  # Cloud resource name: //SERVICE.googleapis.com/RESOURCE_TYPE/RESOURCE_ID
    tag_value: str  # TagValue resource name: tagValues/{tag_value_id}
    tag_value_namespaced_name: str  # Human-readable TagValue reference

class EffectiveTag:
    tag_key: str  # TagKey resource name: tagKeys/{tag_key_id}
    tag_key_parent_name: str  # Parent resource of the TagKey
    tag_value: str  # TagValue resource name: tagValues/{tag_value_id}
    namespaced_tag_key: str  # Human-readable TagKey reference
    namespaced_tag_value: str  # Human-readable TagValue reference
    inherited: bool  # True if tag is inherited from a parent resource

# Request/Response types
class CreateTagBindingRequest:
    tag_binding: TagBinding
    validate_only: bool  # If true, validate request without creating

class ListTagBindingsRequest:
    parent: str  # Cloud resource name
    page_token: str
    page_size: int

class ListTagBindingsResponse:
    tag_bindings: MutableSequence[TagBinding]
    next_page_token: str

class DeleteTagBindingRequest:
    name: str  # TagBinding resource name

class ListEffectiveTagsRequest:
    parent: str  # Cloud resource name
    page_token: str
    page_size: int

class ListEffectiveTagsResponse:
    effective_tags: MutableSequence[EffectiveTag]
    next_page_token: str

# Metadata types for long-running operations
class CreateTagBindingMetadata:
    # Empty metadata message

class DeleteTagBindingMetadata:
    # Empty metadata message

Resource Name Formats

TagBindings work with fully qualified cloud resource names. Here are common formats:

Resource Manager Resources

# Projects
"//cloudresourcemanager.googleapis.com/projects/my-project-id"

# Folders
"//cloudresourcemanager.googleapis.com/folders/123456789"

# Organizations
"//cloudresourcemanager.googleapis.com/organizations/123456789"

Compute Engine Resources

# VM Instances
"//compute.googleapis.com/projects/my-project/zones/us-central1-a/instances/my-vm"

# Disks
"//compute.googleapis.com/projects/my-project/zones/us-central1-a/disks/my-disk"

# Networks
"//compute.googleapis.com/projects/my-project/global/networks/my-network"

Storage Resources

# Cloud Storage Buckets
"//storage.googleapis.com/projects/_/buckets/my-bucket"

Notes

  • TagBindings create direct associations between TagValues and resources
  • Effective tags include both direct TagBindings and inherited tags from parent resources in the hierarchy
  • Tag inheritance follows the Google Cloud resource hierarchy: Organization → Folder → Project → Resource
  • TagBindings can be created on any Google Cloud resource that supports tagging
  • The parent field in TagBinding and EffectiveTag requests uses the full cloud resource name format

Install with Tessl CLI

npx tessl i tessl/pypi-google-cloud-resource-manager

docs

folders.md

index.md

organizations.md

projects.md

tag-bindings.md

tag-holds.md

tag-keys.md

tag-values.md

tile.json