Skip to content

Add support in d/vsphere_tag to lookup by ID and retrieve tag name and its category name #2683

@akli-ime

Description

@akli-ime

Code of Conduct

  • I have read and agree to the project's Code of Conduct.
  • Vote on this issue by adding a 👍 reaction to the original issue initial description to help the maintainers prioritize.
  • Do not leave "+1" or other comments that do not add relevant information or questions.
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

Currently, the Terraform vSphere provider does not provide a native way to resolve a vSphere tag ID into its corresponding tag name and category name.

When working with resources such as vsphere_virtual_machine, only tag IDs are exposed (tag_ids). There is no supported mechanism to convert those IDs into a human-readable category_name : tag_name mapping using Terraform alone.

The existing data sources:

  1. vsphere_tag
  2. vsphere_tag_category

only allow lookups by name and category_id, but not directly by id. This limitation forces users to maintain manual mapping tables or rely on external scripts (PowerCLI, Python, etc.), which increases complexity and reduces portability.

This enhancement proposes extending the existing vsphere_tag data source to support lookup by id, and to expose both the tag name and its category name in the returned attributes.

Use Case(s)

  • Converting VM tag_ids into a structured category_name : tag_name mapping.
  • Generating metadata, labels, or annotations dynamically from vSphere tags.
  • Driving conditional Terraform logic based on tag values.
  • Avoiding manual tag ID mapping tables or external data sources.

Potential Configuration

data "vsphere_tag" "by_id" {
  id = "urn:vmomi:InventoryServiceTag:tag-101:GLOBAL"
}

Expected attributes:

{
  id            = "urn:vmomi:InventoryServiceTag:tag-101:GLOBAL"
  name          = "prod"
  category_id   = "urn:vmomi:InventoryServiceCategory:cat-10:GLOBAL"
  category_name = "env"
}

Terraform usage example:

locals {
  tags_kv = {
    data.vsphere_tag.by_id.category_name = data.vsphere_tag.by_id.name
  }
}

This allows direct and native transformation of vSphere tag IDs into key:value pairs within Terraform.

References

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions