-
Notifications
You must be signed in to change notification settings - Fork 484
Add support in d/vsphere_tag to lookup by ID and retrieve tag name and its category name #2683
Description
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:
vsphere_tagvsphere_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_idsinto a structuredcategory_name : tag_namemapping. - 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
- vSphere REST API – Tagging Service
- Terraform vSphere provider documentation:
https://registry.terraform.io/providers/vmware/vsphere/latest/docs/data-sources/tag
https://registry.terraform.io/providers/vmware/vsphere/latest/docs/resources/virtual_machine