Skip to content

Content Library

Type: vsphere-content-library Artifact BuilderId: vsphere.content-library

This data source retrieves information about an existing content library from vSphere and returns the name and unique identifier for a library that matches all specified filters.

Note

When more than one content library matches the filters, the data source returns an error. Narrow the filters (for example with name or tag) until exactly one library matches.

Configuration Reference

Filters Configuration

Optional:

  • name (string) - Basic filter with glob support on the content library name (e.g. lib* or lib01). Defaults to *.

  • name_regex (string) - Extended name filter with regular expression support matched against the content library name (e.g. ^lib0[0-9]+$). Default is empty. The match is checked by substring. Use ^ and $ to define a full string. The expression must use Go Regex Syntax.

  • tag ([]Tag) - Filter to return only content libraries that have all specified tags attached.

Tags Filter Configuration

Tag identifies a vSphere tag by name and category for datasource filters. Specify one or more tag blocks; every listed tag must be attached.

    tag {
      category = "environment"
      name     = "production"
    }

Required:

  • name (string) - Name of the tag that must be attached to the object.
  • category (string) - Name of the tag category that contains the tag.

    Note

    Both name and category must be specified in the tag filter.

Connection Configuration

Optional:

  • vcenter_server (string) - The fully qualified domain name or IP address of the vCenter instance.
  • username (string) - The username to authenticate with the vCenter instance.
  • password (string) - The password to authenticate with the vCenter instance.
  • insecure_connection (bool) - Do not validate the certificate of the vCenter instance. Defaults to false.

    Note

    This option is beneficial in scenarios where the certificate is self-signed or does not meet standard validation criteria.

  • datacenter (string) - The name of the datacenter object in the vSphere inventory.

    Note

    Required if more than one datacenter object exists in the vSphere inventory.

Output

  • name (string) - Name of the found content library.
  • id (string) - Unique identifier of the found content library.

Example Usage

Select Content Library by Name

data "vsphere-content-library" "build" {
  vcenter_server = "vc01.example.com"
  username       = "administrator@vsphere.local"
  password       = "VMware1!"
  datacenter     = "dc-01"
  name           = "lib01"
}

locals {
  content_library    = data.vsphere-content-library.build.name
  content_library_id = data.vsphere-content-library.build.id
}

Filter by Tags

data "vsphere-content-library" "build" {
  vcenter_server = "vc01.example.com"
  username       = "administrator@vsphere.local"
  password       = "VMware1!"
  datacenter     = "dc-01"
  tag {
    category = "environment"
    name     = "production"
  }
}

locals {
  content_library = data.vsphere-content-library.build.name
}