2015-10-12 18:42:27 +02:00
|
|
|
---
|
|
|
|
layout: "vsphere"
|
2015-11-03 03:21:08 +01:00
|
|
|
page_title: "Provider: VMware vSphere"
|
2015-10-12 18:42:27 +02:00
|
|
|
sidebar_current: "docs-vsphere-index"
|
|
|
|
description: |-
|
2015-11-03 03:21:08 +01:00
|
|
|
The VMware vSphere provider is used to interact with the resources supported by
|
|
|
|
VMware vSphere. The provider needs to be configured with the proper credentials
|
|
|
|
before it can be used.
|
2015-10-12 18:42:27 +02:00
|
|
|
---
|
|
|
|
|
2015-11-03 03:21:08 +01:00
|
|
|
# VMware vSphere Provider
|
2015-10-12 18:42:27 +02:00
|
|
|
|
2015-11-03 03:21:08 +01:00
|
|
|
The VMware vSphere provider is used to interact with the resources supported by
|
|
|
|
VMware vSphere.
|
2015-10-12 18:42:27 +02:00
|
|
|
The provider needs to be configured with the proper credentials before it can be used.
|
|
|
|
|
|
|
|
Use the navigation to the left to read about the available resources.
|
|
|
|
|
2015-11-03 03:21:08 +01:00
|
|
|
~> **NOTE:** The VMware vSphere Provider currently represents _initial support_
|
2015-11-18 05:53:55 +01:00
|
|
|
and therefore may undergo significant changes as the community improves it. This
|
|
|
|
provider at this time only supports IPv4 addresses on virtual machines.
|
2015-10-15 16:35:06 +02:00
|
|
|
|
2015-10-12 18:42:27 +02:00
|
|
|
## Example Usage
|
|
|
|
|
|
|
|
```
|
2015-11-03 03:21:08 +01:00
|
|
|
# Configure the VMware vSphere Provider
|
2015-10-12 18:42:27 +02:00
|
|
|
provider "vsphere" {
|
|
|
|
user = "${var.vsphere_user}"
|
|
|
|
password = "${var.vsphere_password}"
|
2015-11-01 15:07:23 +01:00
|
|
|
vsphere_server = "${var.vsphere_server}"
|
2015-10-12 18:42:27 +02:00
|
|
|
}
|
|
|
|
|
2015-11-16 19:44:39 +01:00
|
|
|
# Create a folder
|
|
|
|
resource "vsphere_folder" "frontend" {
|
|
|
|
path = "frontend"
|
|
|
|
}
|
|
|
|
|
2016-05-02 22:25:35 +02:00
|
|
|
# Create a file
|
|
|
|
resource "vsphere_file" "ubuntu_disk" {
|
|
|
|
datastore = "local"
|
|
|
|
source_file = "/home/ubuntu/my_disks/custom_ubuntu.vmdk"
|
|
|
|
destination_file = "/my_path/disks/custom_ubuntu.vmdk"
|
|
|
|
}
|
|
|
|
|
2015-11-16 19:44:39 +01:00
|
|
|
# Create a virtual machine within the folder
|
2015-10-12 18:42:27 +02:00
|
|
|
resource "vsphere_virtual_machine" "web" {
|
2016-03-05 00:15:09 +01:00
|
|
|
name = "terraform-web"
|
2015-11-16 19:44:39 +01:00
|
|
|
folder = "${vsphere_folder.frontend.path}"
|
2015-10-12 18:42:27 +02:00
|
|
|
vcpu = 2
|
|
|
|
memory = 4096
|
|
|
|
|
|
|
|
network_interface {
|
|
|
|
label = "VM Network"
|
|
|
|
}
|
|
|
|
|
|
|
|
disk {
|
2015-12-07 02:49:04 +01:00
|
|
|
template = "centos-7"
|
2015-10-12 18:42:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Argument Reference
|
|
|
|
|
2015-11-03 03:21:08 +01:00
|
|
|
The following arguments are used to configure the VMware vSphere Provider:
|
2015-10-12 18:42:27 +02:00
|
|
|
|
|
|
|
* `user` - (Required) This is the username for vSphere API operations. Can also
|
|
|
|
be specified with the `VSPHERE_USER` environment variable.
|
|
|
|
* `password` - (Required) This is the password for vSphere API operations. Can
|
|
|
|
also be specified with the `VSPHERE_PASSWORD` environment variable.
|
2015-11-01 15:07:23 +01:00
|
|
|
* `vsphere_server` - (Required) This is the vCenter server name for vSphere API
|
|
|
|
operations. Can also be specified with the `VSPHERE_SERVER` environment
|
2015-10-12 18:42:27 +02:00
|
|
|
variable.
|
2015-11-15 04:24:28 +01:00
|
|
|
* `allow_unverified_ssl` - (Optional) Boolean that can be set to true to
|
|
|
|
disable SSL certificate verification. This should be used with care as it
|
|
|
|
could allow an attacker to intercept your auth token. If omitted, default
|
|
|
|
value is `false`. Can also be specified with the `VSPHERE_ALLOW_UNVERIFIED_SSL`
|
|
|
|
environment variable.
|
2015-10-12 18:42:27 +02:00
|
|
|
|
2016-04-26 11:48:25 +02:00
|
|
|
## Required Privileges
|
|
|
|
|
|
|
|
In order to use Terraform provider as non priviledged user, a Role within
|
|
|
|
vCenter must be assigned the following privileges:
|
|
|
|
|
|
|
|
* Datastore
|
|
|
|
- Allocate space
|
|
|
|
- Browse datastore
|
|
|
|
- Low level file operations
|
|
|
|
- Remove file
|
|
|
|
- Update virtual machine files
|
|
|
|
- Update virtual machine metadata
|
|
|
|
|
|
|
|
* Folder (all)
|
|
|
|
- Create folder
|
|
|
|
- Delete folder
|
|
|
|
- Move folder
|
|
|
|
- Rename folder
|
|
|
|
|
|
|
|
* Network
|
|
|
|
- Assign network
|
|
|
|
|
|
|
|
* Resource
|
|
|
|
- Apply recommendation
|
|
|
|
- Assign virtual machine to resource pool
|
|
|
|
|
|
|
|
* Virtual Machine
|
|
|
|
- Configuration (all) - for now
|
|
|
|
- Guest Operations (all) - for now
|
|
|
|
- Interaction (all)
|
|
|
|
- Inventory (all)
|
|
|
|
- Provisioning (all)
|
|
|
|
|
|
|
|
These settings were tested with [vSphere
|
|
|
|
6.0](https://pubs.vmware.com/vsphere-60/index.jsp?topic=%2Fcom.vmware.vsphere.security.doc%2FGUID-18071E9A-EED1-4968-8D51-E0B4F526FDA3.html)
|
|
|
|
and [vSphere
|
|
|
|
5.5](https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.vsphere.security.doc%2FGUID-18071E9A-EED1-4968-8D51-E0B4F526FDA3.html).
|
|
|
|
For additional information on roles and permissions, please refer to official
|
|
|
|
VMware documentation.
|
2016-04-29 18:03:06 +02:00
|
|
|
|
2016-04-29 20:05:19 +02:00
|
|
|
## Virtual Machine Customization
|
2016-04-29 18:03:06 +02:00
|
|
|
|
2016-04-29 20:05:19 +02:00
|
|
|
Guest Operating Systems can be configured using
|
2016-04-29 18:03:06 +02:00
|
|
|
[customizations](https://pubs.vmware.com/vsphere-50/index.jsp#com.vmware.vsphere.vm_admin.doc_50/GUID-80F3F5B5-F795-45F1-B0FA-3709978113D5.html),
|
2016-04-29 20:05:19 +02:00
|
|
|
in order to set things properties such as domain and hostname. This mechanism
|
|
|
|
is not compatible with all operating systems, however. A list of compatible
|
|
|
|
operating systems can be found
|
2016-04-29 18:03:06 +02:00
|
|
|
[here](http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf)
|
|
|
|
|
2016-04-29 20:05:19 +02:00
|
|
|
If customization is attempted on an operating system which is not supported, Terraform will
|
|
|
|
create the virtual machine, but fail with the following error message:
|
2016-04-29 18:03:06 +02:00
|
|
|
|
|
|
|
```
|
2016-04-29 20:05:19 +02:00
|
|
|
Customization of the guest operating system 'debian6_64Guest' is not
|
|
|
|
supported in this configuration. Microsoft Vista (TM) and Linux guests with
|
|
|
|
Logical Volume Manager are supported only for recent ESX host and VMware Tools
|
|
|
|
versions. Refer to vCenter documentation for supported configurations. ```
|
2016-04-29 18:03:06 +02:00
|
|
|
```
|
|
|
|
|
2016-04-29 20:05:19 +02:00
|
|
|
In order to skip the customization step for unsupported operating systems, use
|
|
|
|
the `skip_customization` argument on the virtual machine resource.
|
|
|
|
|
2015-10-29 13:48:11 +01:00
|
|
|
## Acceptance Tests
|
|
|
|
|
2015-11-03 03:21:08 +01:00
|
|
|
The VMware vSphere provider's acceptance tests require the above provider
|
2015-10-29 13:48:11 +01:00
|
|
|
configuration fields to be set using the documented environment variables.
|
|
|
|
|
2016-04-26 11:48:25 +02:00
|
|
|
In addition, the following environment variables are used in tests, and must be
|
|
|
|
set to valid values for your VMware vSphere environment:
|
2015-10-29 13:48:11 +01:00
|
|
|
|
|
|
|
* VSPHERE\_NETWORK\_GATEWAY
|
|
|
|
* VSPHERE\_NETWORK\_IP\_ADDRESS
|
|
|
|
* VSPHERE\_NETWORK\_LABEL
|
|
|
|
* VSPHERE\_NETWORK\_LABEL\_DHCP
|
|
|
|
* VSPHERE\_TEMPLATE
|
2015-10-30 10:18:25 +01:00
|
|
|
|
|
|
|
The following environment variables depend on your vSphere environment:
|
2015-11-18 05:53:55 +01:00
|
|
|
|
2015-10-30 10:18:25 +01:00
|
|
|
* VSPHERE\_DATACENTER
|
|
|
|
* VSPHERE\_CLUSTER
|
|
|
|
* VSPHERE\_RESOURCE\_POOL
|
|
|
|
* VSPHERE\_DATASTORE
|
|
|
|
|
2016-04-26 11:48:25 +02:00
|
|
|
The following additional environment variables are needed for running the
|
|
|
|
"Mount ISO as CDROM media" acceptance tests.
|
2015-11-25 15:35:37 +01:00
|
|
|
|
|
|
|
* VSPHERE\_CDROM\_DATASTORE
|
|
|
|
* VSPHERE\_CDROM\_PATH
|
|
|
|
|
2015-10-29 13:48:11 +01:00
|
|
|
|
|
|
|
These are used to set and verify attributes on the `vsphere_virtual_machine`
|
|
|
|
resource in tests.
|
|
|
|
|
|
|
|
Once all these variables are in place, the tests can be run like this:
|
|
|
|
|
|
|
|
```
|
|
|
|
make testacc TEST=./builtin/providers/vsphere
|
|
|
|
```
|
2016-04-26 11:48:25 +02:00
|
|
|
|
|
|
|
|