Packer
VMware vSphere
@hashicorp
The vSphere plugin is able to create vSphere virtual machines for use with any VMware product.
- Official
- HCP Ready
Updated 2 years ago
- GitHub(opens in new tab)
vSphere
Type: vsphere
Artifact BuilderId: packer.post-processor.vsphere
This post-processor uploads an artifact to a vSphere endpoint.
The artifact must be a VMX, OVA, or OVF file.
Note: This post-processor is developed to maintain compatibility with VMware vSphere versions until their respective End of General Support dates. For detailed information, refer to the Broadcom Product Lifecycle.
Examples
Examples are available in the examples directory of the GitHub repository.
Configuration Reference
The following configuration options are available for the post-processor.
Required:
cluster
(string) - The cluster or ESXi host to upload the virtual machine. This can be either the name of the vSphere cluster or the fully qualified domain name (FQDN) or IP address of the ESXi host.datacenter
(string) - The name of the vSphere datacenter object to place the virtual machine. This is not required ifresource_pool
is specified.datastore
(string) - The name of the vSphere datastore to place the virtual machine.host
(string) - The fully qualified domain name or IP address of the vCenter Server or ESXi host.password
(string) - The password to use to authenticate to the vSphere endpoint.username
(string) - The username to use to authenticate to the vSphere endpoint.
Optional:
disk_mode
(string) - The disk format of the target virtual machine. One ofthin
,thick
,esxi_host
(string) - The fully qualified domain name or IP address of the ESXi host to upload the virtual machine. This is not required ifhost
is a vCenter Server.insecure
(bool) - Skip the verification of the server certificate. Defaults tofalse
.options
([]string) - Options to send toovftool
when uploading the virtual machine. Useovftool --help
to list all the options available.overwrite
(bool) - Overwrite existing files. Iftrue
, forces overwrites of existing files. Defaults tofalse
.resource_pool
(string) - The name of the resource pool to place the virtual machine.vm_folder
(string) - The name of the virtual machine folder path where the virtual machine will be placed.vm_name
(string) - The name of the virtual machine to be created on the vSphere endpoint.vm_network
(string) - The name of the network in which to place the virtual machine.hardware_version
(string) - The maximum virtual hardware version for the deployed virtual machine.It does not upgrade the virtual hardware version of the source VM. Instead, it limits the virtual hardware version of the deployed virtual machine to the specified version. If the source virtual machine's hardware version is higher than the specified version, the deployed virtual machine's hardware version will be downgraded to the specified version.
If the source virtual machine's hardware version is lower than or equal to the specified version, the deployed virtual machine's hardware version will be the same as the source virtual machine's.
This option is useful when deploying to vCenter Server instance ot an ESXi host whose version is different than the one used to create the artifact.
Refer to KB 315655 for more information on supported virtual hardware versions.
max_retries
(int) - The maximum number of times to retry the upload operation if it fails. Defaults to5
.
keep_input_artifact
(boolean) - Preserve the local virtual machines files, even after importing them to the vSphere endpoint. Defaults tofalse
.
Example Usage
The following is an example of the post-processor used in conjunction with the null
builder to
upload a VMX to a vSphere cluster. You can also use this post-processor with the VMX artifact from a
build.
An example is shown below, showing only the post-processor configuration:
HCL Example:
source "null" "example" {
communicator = "none"
}
build {
sources = [
"source.null.example"
]
post-processors {
post-processor "vsphere"{
vm_name = "foo"
host = "vcenter.example.com"
username = "administrator@vsphere.local"
password = "VMw@re1!"
datacenter = "dc-01"
cluster = "cluster-01"
datastore = "datastore-01"
vm_network = "VM Network"
keep_input_artifact = true
}
}
}
JSON Example:
{
"builders": [
{
"type": "null",
"communicator": "none"
}
],
"post-processors": [
[
{
"type": "vsphere",
"vm_name": "foo",
"host": "vcenter.example.com",
"username": "administrator@vsphere.local",
"password": "VMw@re1!",
"datacenter": "dc-01",
"cluster": "cluster-01",
"datastore": "datastore-01",
"vm_network": "VM Network",
"keep_input_artifact": true
}
]
]
}
Privileges
The post-processor uses ovftool
and needs several privileges to be able to run ovftool
.
Rather than giving Administrator access, you can create a role to give the post-processor the privileges necessary to run.
Below is an example role that will work. Please note that this is a user-supplied list so there may be a few extraneous privileges that are not strictly required.
For vSphere, the role needs the following privileges:
Datastore.AllocateSpace
Host.Config.AdvancedConfig
Host.Config.NetService
Host.Config.Network
Network.Assign
System.Anonymous
System.Read
System.View
VApp.Import
VirtualMachine.Config.AddNewDisk
VirtualMachine.Config.AdvancedConfig
VirtualMachine.Inventory.Delete
The role must be authorized on the:
- Cluster of the host.
- The destination folder.
- The destination datastore.
- The network to be assigned.