The vsphere_tag
resource can be used to create and manage tags, which allow you to attach metadata to objects in the vSphere inventory to make these objects more sortable and searchable.
For more information about tags, click here.
NOTE: Tagging support is unsupported on direct ESXi connections and requires vCenter 6.0 or higher.
This example creates a tag named terraform-test-tag
. This tag is assigned the terraform-test-category
category, which was created by the vsphere_tag_category
resource. The resulting tag can be assigned to VMs and datastores only, and can be the only value in the category that can be assigned, as per the restrictions defined by the category.
resource "vsphere_tag_category" "category" { name = "terraform-test-category" cardinality = "SINGLE" description = "Managed by Terraform" associable_types = [ "VirtualMachine", "Datastore", ] } resource "vsphere_tag" "tag" { name = "terraform-test-tag" category_id = "${vsphere_tag_category.category.id}" description = "Managed by Terraform" }
Tags can be applied to vSphere resources in Terraform via the tags
argument in any supported resource.
The following example builds on the above example by creating a vsphere_virtual_machine
and applying the created tag to it:
resource "vsphere_tag_category" "category" { name = "terraform-test-category" cardinality = "SINGLE" description = "Managed by Terraform" associable_types = [ "VirtualMachine", "Datastore", ] } resource "vsphere_tag" "tag" { name = "terraform-test-tag" category_id = "${vsphere_tag_category.category.id}" description = "Managed by Terraform" } resource "vsphere_virtual_machine" "web" { ... tags = ["${vsphere_tag.tag.id}"] }
The following arguments are supported:
name
- (Required) The display name of the tag. The name must be unique within its category. category_id
- (Required) The unique identifier of the parent category in which this tag will be created. Forces a new resource if changed. description
- (Optional) A description for the tag. The only attribute that is exported for this resource is the id
, which is the uniform resource name (URN) of this tag.
An existing tag can be imported into this resource by supplying both the tag's category name and the name of the tag as a JSON string to terraform import
, as per the example below:
terraform import vsphere_tag.tag \ '{"category_name": "terraform-test-category", "tag_name": "terraform-test-tag"}'
© 2018 HashiCorpLicensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/vsphere/r/tag.html