Skip to content

Add support for returning tags and custom_attributes in the d/vsphere_virtual_machine data source #2615

@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 vsphere_virtual_machine data source does not expose vSphere tags or custom attributes assigned to a VM.
This information is available through the vSphere REST and SOAP APIs, but it is not accessible from the Terraform provider, which limits automation and compliance use cases.

When using the API directly (via /rest/com/vmware/cis/tagging/tag-association or /rest/vcenter/vm), tags and custom attributes can be retrieved — however, the vsphere_virtual_machine data source only provides core VM properties (CPU, memory, disks, network, etc.) and omits metadata like tags and .

Adding these fields would make it easier to:

  • Dynamically manage resources by tag (e.g., environments, cost centers)
  • Integrate Terraform with CMDB or governance tools
  • Perform drift detection and validation based on custom attributes

Use Case(s)

  • Reading an existing VM and using its tags to drive conditional logic or dynamic configuration in Terraform (e.g., assigning network profiles or backup policies).
  • Propagating vSphere custom attributes to other systems such as CMDBs or cost-management tools.
  • Validating that existing VMs are correctly tagged as part of compliance or governance pipelines.
  • Simplifying reporting and resource classification workflows that depend on metadata.

Potential Configuration

data "vsphere_virtual_machine" "vm" {
  name          = "app-prod-01"
  datacenter_id = data.vsphere_datacenter.dc.id
}

output "vm_tags" {
  value = data.vsphere_virtual_machine.vm.tags
}

output "vm_custom_attributes" {
  value = data.vsphere_virtual_machine.vm.custom_attributes
}

Expected Terraform output:

vm_tags = [
  {
    category = "Environment"
    name     = "Production"
  },
  {
    category = "Owner"
    name     = "TeamA"
  }
]

vm_custom_attributes = {
  "Application" = "APP"
  "CostCenter"  = "001"
}

References

vSphere REST API documentation:
https://developer.broadcom.com/xapis/vsphere-automation-api/v7.0u3/cis/api/cis/tagging/tag-association__action=list-attached-tags/post/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions