Skip to content

d/vsphere_datastore: Please Add Default Policy Name Or Default Policy ID as a returned Attribute #2617

@idcos-cloudiac

Description

@idcos-cloudiac

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_datastore data source in the Terraform vSphere provider returns basic information about a datastore (e.g., name, type, capacity, etc.), but it does not expose the associated VM Storage Policy—specifically, the default storage policy name or ID applied to the datastore. In environments that leverage VM Storage Policies for storage placement and compliance (e.g., vSAN or VVols), knowing the default policy tied to a datastore is critical for infrastructure-as-code workflows that aim to align VM or disk placement with organizational policy requirements. This enhancement would allow users to reference the default policy directly from the datastore data source, improving policy-aware provisioning and validation.

Use Case(s)

  1. Policy-Aware VM Provisioning: When deploying VMs using Terraform, users may want to ensure that the VM’s disks are placed on datastores that comply with a specific storage policy. If the datastore’s default policy is known, it can be cross-referenced or used as a fallback when an explicit policy is not defined.
  2. Compliance Validation: Infrastructure teams may audit or validate that datastores are associated with expected default policies (e.g., “Gold”, “Silver”, or custom policies). Having this attribute available enables automated compliance checks within Terraform configurations.
  3. Dynamic Policy Assignment: In modular Terraform setups, modules could automatically inherit the datastore’s default policy for disk creation, reducing the need for hard-coded policy IDs or names and increasing portability across environments.

Potential Configuration

data "vsphere_datastore" "example" {
  name          = "ds01"
  datacenter_id = data.vsphere_datacenter.dc.id
}

# New attributes (proposed)
output "default_storage_policy_id" {
  value = data.vsphere_datastore.example.default_storage_policy_id
}

output "default_storage_policy_name" {
  value = data.vsphere_datastore.example.default_storage_policy_name
}

The vsphere_datastore data source would gain two new optional computed attributes:

default_storage_policy_id (string): The UUID of the default VM storage policy assigned to the datastore.
default_storage_policy_name (string): The human-readable name of the default VM storage policy.
If no default policy is set, these attributes would return empty strings or null.

References

VMware vSphere API Documentation – Datastore Managed Object
vSphere Storage Policy-Based Management (SPBM) Overview: https://docs.vmware.com/en/VMware-vSphere/8.0/vsphere-storage/GUID-3B5C2E7A-3A0F-4F1A-8B0D-7F5E9C3A3B5C.html
Terraform vSphere Provider – vsphere_datastore data source: https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/data-sources/datastore

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions