vsphere_custom_attribute

The vsphere_custom_attribute resource can be used to create and manage custom attributes, which allow users to associate user-specific meta-information with vSphere managed objects. Custom attribute values must be strings and are stored on the vCenter Server and not the managed object.

For more information about custom attributes, click here.

Example Usage

This example creates a custom attribute named terraform-test-attribute. The resulting custom attribute can be assigned to VMs only.

resource "vsphere_custom_attribute" "attribute" {
  name                = "terraform-test-attribute"
  managed_object_type = "VirtualMachine"
}

Using Custom Attributes in a Supported Resource

Custom attributes can be set on vSphere resources in Terraform via the custom_attributes argument in any supported resource.

The following example builds on the above example by creating a vsphere_virtual_machine and assigning a value to created custom attribute on it.

resource "vsphere_custom_attribute" "attribute" {
  name                = "terraform-test-attribute"
  managed_object_type = "VirtualMachine"
}

resource "vpshere_virtual_machine" "web" {
  ...

  custom_attributes = "${map(vsphere_custom_attribute.attribute.id, "value")}"
}

Argument Reference

The following arguments are supported:

  • name - (Required) The name of the custom attribute.
  • managed_object_type - (Optional) The object type that this attribute may be applied to. If not set, the custom attribute may be applied to any object type. For a full list, click here. Forces a new resource if changed.

Managed Object Types

The following table will help you determine what value you need to enter for the managed object type you want the attribute to apply to.

Note that if you want a attribute to apply to all objects, leave the type unspecified.

Type Value
Folders Folder
Clusters ClusterComputeResource
Datacenters Datacenter
Datastores Datastore
Datastore Clusters StoragePod
DVS Portgroups DistributedVirtualPortgroup
Distributed vSwitches DistributedVirtualSwitch
VmwareDistributedVirtualSwitch
Hosts HostSystem
Content Libraries com.vmware.content.Library
Content Library Items com.vmware.content.library.Item
Networks HostNetwork
Network
OpaqueNetwork
Resource Pools ResourcePool
vApps VirtualApp
Virtual Machines VirtualMachine

Attribute Reference

This resource only exports the id attribute for the vSphere custom attribute.

Importing

An existing custom attribute can be imported into this resource via its name, using the following command:

terraform import vsphere_custom_attribute.attribute terraform-test-attribute

© 2018 HashiCorp
Licensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/vsphere/r/custom_attribute.html