2015-10-12 18:42:27 +02:00
---
layout: "vsphere"
2015-11-03 03:27:22 +01:00
page_title: "VMware vSphere: vsphere_virtual_machine"
2015-10-12 18:42:27 +02:00
sidebar_current: "docs-vsphere-resource-virtual-machine"
description: |-
2015-11-03 03:27:22 +01:00
Provides a VMware vSphere virtual machine resource. This can be used to create, modify, and delete virtual machines.
2015-10-12 18:42:27 +02:00
---
# vsphere\_virtual\_machine
2015-11-03 03:27:22 +01:00
Provides a VMware vSphere virtual machine resource. This can be used to create,
2015-10-12 18:42:27 +02:00
modify, and delete virtual machines.
## Example Usage
```
resource "vsphere_virtual_machine" "web" {
name = "terraform_web"
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
}
}
```
2016-04-24 19:41:27 +02:00
## Example Usage VMware Cluster
```
resource "vsphere_virtual_machine" "lb" {
name = "lb01"
folder = "Loadbalancers"
vcpu = 2
memory = 4096
domain = "MYDOMAIN"
datacenter = "EAST"
cluster = "Production Cluster"
resource_pool = "Production Cluster/Resources/Production Servers"
gateway = "10.20.30.254"
network_interface {
label = "10_20_30_VMNet"
ipv4_address = "10.20.30.40"
ipv4_prefix_length = "24"
}
disk {
datastore = "EAST/VMFS01-EAST"
template = "Templates/Centos7"
}
}
```
2015-10-12 18:42:27 +02:00
## Argument Reference
The following arguments are supported:
* `name` - (Required) The virtual machine name
* `vcpu` - (Required) The number of virtual CPUs to allocate to the virtual machine
* `memory` - (Required) The amount of RAM (in MB) to allocate to the virtual machine
2016-04-25 13:15:37 +02:00
* `memory_reservation` - (Optional) The amount of RAM (in MB) to reserve physical memory resource; defaults to 0 (means not to reserve)
2015-10-12 18:42:27 +02:00
* `datacenter` - (Optional) The name of a Datacenter in which to launch the virtual machine
* `cluster` - (Optional) Name of a Cluster in which to launch the virtual machine
2016-04-24 19:41:27 +02:00
* `resource_pool` (Optional) The name of a Resource Pool in which to launch the virtual machine. Requires full path (see cluster example).
2016-05-03 18:27:24 +02:00
* `gateway` - __Deprecated, please use `network_interface.ipv4_gateway` instead__ .
2015-10-12 18:42:27 +02:00
* `domain` - (Optional) A FQDN for the virtual machine; defaults to "vsphere.local"
2016-03-23 21:46:33 +01:00
* `time_zone` - (Optional) The [Linux ](https://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/timezone.html ) or [Windows ](https://msdn.microsoft.com/en-us/library/ms912391.aspx ) time zone to set on the virtual machine. Defaults to "Etc/UTC"
2015-10-12 18:42:27 +02:00
* `dns_suffixes` - (Optional) List of name resolution suffixes for the virtual network adapter
* `dns_servers` - (Optional) List of DNS servers for the virtual network adapter; defaults to 8.8.8.8, 8.8.4.4
* `network_interface` - (Required) Configures virtual network interfaces; see [Network Interfaces ](#network-interfaces ) below for details.
* `disk` - (Required) Configures virtual disks; see [Disks ](#disks ) below for details
2015-11-25 15:35:37 +01:00
* `cdrom` - (Optional) Configures a CDROM device and mounts an image as its media; see [CDROM ](#cdrom ) below for more details.
2016-03-23 21:46:33 +01:00
* `windows_opt_config` - (Optional) Extra options for clones of Windows machines.
2016-04-13 18:42:55 +02:00
* `linked_clone` - (Optional) Specifies if the new machine is a [linked clone ](https://www.vmware.com/support/ws5/doc/ws_clone_overview.html#wp1036396 ) of another machine or not.
2016-06-09 10:19:10 +02:00
* `enable_disk_uuid` - (Optional) This option causes the vm to mount disks by uuid on the guest OS.
2015-11-11 23:50:18 +01:00
* `custom_configuration_parameters` - (Optional) Map of values that is set as virtual machine custom configurations.
2016-04-21 17:53:08 +02:00
* `skip_customization` - (Optional) skip virtual machine customization (useful if OS is not in the guest OS support matrix of VMware like "other3xLinux64Guest").
2015-10-12 18:42:27 +02:00
2015-11-24 01:53:11 +01:00
The `network_interface` block supports:
2015-10-12 18:42:27 +02:00
* `label` - (Required) Label to assign to this network interface
2016-05-03 18:27:24 +02:00
* `ipv4_address` - (Optional) Static IPv4 to assign to this network interface. Interface will use DHCP if this is left blank.
* `ipv4_prefix_length` - (Optional) prefix length to use when statically assigning an IPv4 address.
* `ipv4_gateway` - (Optional) IPv4 gateway IP address to use.
* `ipv6_address` - (Optional) Static IPv6 to assign to this network interface. Interface will use DHCPv6 if this is left blank.
* `ipv6_prefix_length` - (Optional) prefix length to use when statically assigning an IPv6.
* `ipv6_gateway` - (Optional) IPv6 gateway IP address to use.
2016-06-02 01:38:56 +02:00
* `mac_address` - (Optional) Manual MAC address to assign to this network interface. Will be generated by VMware if not set. ([VMware KB: Setting a static MAC address for a virtual NIC (219)](https://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC& externalId=219))
2015-11-24 01:53:11 +01:00
The following arguments are maintained for backwards compatibility and may be
removed in a future version:
2016-05-03 18:27:24 +02:00
* `ip_address` - __Deprecated, please use `ipv4_address` instead__ .
* `subnet_mask` - __Deprecated, please use `ipv4_prefix_length` instead__ .
2015-10-12 18:42:27 +02:00
2016-03-23 21:46:33 +01:00
The `windows_opt_config` block supports:
* `product_key` - (Optional) Serial number for new installation of Windows. This serial number is ignored if the original guest operating system was installed using a volume-licensed CD.
* `admin_password` - (Optional) The password for the new `administrator` account. Omit for passwordless admin (using `""` does not work).
* `domain` - (Optional) Domain that the new machine will be placed into. If `domain` , `domain_user` , and `domain_user_password` are not all set, all three will be ignored.
* `domain_user` - (Optional) User that is a member of the specified domain.
* `domain_user_password` - (Optional) Password for domain user, in plain text.
2015-10-12 18:42:27 +02:00
2015-11-25 15:35:37 +01:00
< a id = "disks" > < / a >
## Disks
2015-11-24 01:53:11 +01:00
The `disk` block supports:
2015-10-12 18:42:27 +02:00
2016-04-27 18:22:22 +02:00
* `template` - (Required if size and bootable_vmdk_path not provided) Template for this disk.
2015-10-12 18:42:27 +02:00
* `datastore` - (Optional) Datastore for this disk
2016-04-27 18:22:22 +02:00
* `size` - (Required if template and bootable_vmdks_path not provided) Size of this disk (in GB).
2016-05-23 23:37:06 +02:00
* `name` - (Required if size is provided when creating a new disk) This "name" is used for the disk file name in vSphere, when the new disk is created.
2015-10-12 18:42:27 +02:00
* `iops` - (Optional) Number of virtual iops to allocate for this disk.
2015-12-12 09:33:01 +01:00
* `type` - (Optional) 'eager_zeroed' (the default), or 'thin' are supported options.
2016-05-03 18:27:24 +02:00
* `vmdk` - (Required if template and size not provided) Path to a vmdk in a vSphere datastore.
2016-04-27 18:22:22 +02:00
* `bootable` - (Optional) Set to 'true' if a vmdk was given and it should attempt to boot after creation.
2016-05-21 08:21:42 +02:00
* `controller_type` = (Optional) Controller type to attach the disk to. 'scsi' (the default), or 'ide' are supported options.
2015-11-24 01:53:11 +01:00
2015-11-25 15:35:37 +01:00
< a id = "cdrom" > < / a >
## CDROM
The `cdrom` block supports:
* `datastore` - (Required) The name of the datastore where the disk image is stored.
* `path` - (Required) The absolute path to the image within the datastore.
2015-11-24 01:53:11 +01:00
## Attributes Reference
The following attributes are exported:
* `id` - The instance ID.
2016-06-29 22:45:59 +02:00
* `uuid` - The instance UUID.
2015-11-24 01:53:11 +01:00
* `name` - See Argument Reference above.
* `vcpu` - See Argument Reference above.
* `memory` - See Argument Reference above.
* `datacenter` - See Argument Reference above.
* `network_interface/label` - See Argument Reference above.
* `network_interface/ipv4_address` - See Argument Reference above.
* `network_interface/ipv4_prefix_length` - See Argument Reference above.
* `network_interface/ipv6_address` - Assigned static IPv6 address.
* `network_interface/ipv6_prefix_length` - Prefix length of assigned static IPv6 address.