diff --git a/vsphere/provider.go b/vsphere/provider.go index d65174394..ee9ec4602 100644 --- a/vsphere/provider.go +++ b/vsphere/provider.go @@ -69,16 +69,17 @@ func Provider() terraform.ResourceProvider { }, ResourcesMap: map[string]*schema.Resource{ - "vsphere_datacenter": resourceVSphereDatacenter(), - "vsphere_file": resourceVSphereFile(), - "vsphere_folder": resourceVSphereFolder(), - "vsphere_host_port_group": resourceVSphereHostPortGroup(), - "vsphere_host_virtual_switch": resourceVSphereHostVirtualSwitch(), - "vsphere_license": resourceVSphereLicense(), - "vsphere_virtual_disk": resourceVSphereVirtualDisk(), - "vsphere_virtual_machine": resourceVSphereVirtualMachine(), - "vsphere_nas_datastore": resourceVSphereNasDatastore(), - "vsphere_vmfs_datastore": resourceVSphereVmfsDatastore(), + "vsphere_datacenter": resourceVSphereDatacenter(), + "vsphere_file": resourceVSphereFile(), + "vsphere_folder": resourceVSphereFolder(), + "vsphere_host_port_group": resourceVSphereHostPortGroup(), + "vsphere_host_virtual_switch": resourceVSphereHostVirtualSwitch(), + "vsphere_license": resourceVSphereLicense(), + "vsphere_virtual_disk": resourceVSphereVirtualDisk(), + "vsphere_virtual_machine": resourceVSphereVirtualMachine(), + "vsphere_nas_datastore": resourceVSphereNasDatastore(), + "vsphere_vmfs_datastore": resourceVSphereVmfsDatastore(), + "vsphere_virtual_machine_snapshot": resourceVSphereSnapshot(), }, DataSourcesMap: map[string]*schema.Resource{ diff --git a/vsphere/resource_vsphere_virtual_machine_snapshot.go b/vsphere/resource_vsphere_virtual_machine_snapshot.go new file mode 100644 index 000000000..cf1209538 --- /dev/null +++ b/vsphere/resource_vsphere_virtual_machine_snapshot.go @@ -0,0 +1,160 @@ +package vsphere + +import ( + "context" + "fmt" + "log" + "strings" + + "github.com/hashicorp/terraform/helper/schema" + "github.com/vmware/govmomi" + "github.com/vmware/govmomi/vim25/types" +) + +func resourceVSphereSnapshot() *schema.Resource { + return &schema.Resource{ + Create: resourceVSphereSnapshotCreate, + Read: resourceVSphereSnapshotRead, + Delete: resourceVSphereSnapshotDelete, + + Schema: map[string]*schema.Schema{ + "vm_uuid": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "datacenter": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, + "snapshot_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "description": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + "memory": { + Type: schema.TypeBool, + Required: true, + ForceNew: true, + }, + "quiesce": { + Type: schema.TypeBool, + Required: true, + ForceNew: true, + }, + "remove_children": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + "consolidate": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + }, + }, + } +} + +func resourceVSphereSnapshotCreate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*govmomi.Client) + vm, err := virtualMachineFromUUID(client, d.Get("vm_uuid").(string)) + if err != nil { + return fmt.Errorf("Error while getting the VirtualMachine :%s", err) + } + ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout) // This is 5 mins + defer cancel() + task, err := vm.CreateSnapshot(ctx, d.Get("snapshot_name").(string), d.Get("description").(string), d.Get("memory").(bool), d.Get("quiesce").(bool)) + tctx, tcancel := context.WithTimeout(context.Background(), defaultAPITimeout) + defer tcancel() + taskInfo, err := task.WaitForResult(tctx, nil) + if err != nil { + log.Printf("[DEBUG] Error While Creating the Task for Create Snapshot: %v", err) + return fmt.Errorf(" Error While Creating the Task for Create Snapshot: %s", err) + } + log.Printf("[DEBUG] Task created for Create Snapshot: %v", task) + if err != nil { + log.Printf("[DEBUG] Error While waiting for the Task for Create Snapshot: %v", err) + return fmt.Errorf(" Error While waiting for the Task for Create Snapshot: %s", err) + } + log.Printf("[DEBUG] Create Snapshot completed %v", d.Get("snapshot_name").(string)) + log.Println("[DEBUG] Managed Object Reference: " + taskInfo.Result.(types.ManagedObjectReference).Value) + d.SetId(taskInfo.Result.(types.ManagedObjectReference).Value) + return nil +} + +func resourceVSphereSnapshotDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*govmomi.Client) + vm, err := virtualMachineFromUUID(client, d.Get("vm_uuid").(string)) + if err != nil { + return fmt.Errorf("Error while getting the VirtualMachine :%s", err) + } + resourceVSphereSnapshotRead(d, meta) + if d.Id() == "" { + log.Printf("[DEBUG] Error While finding the Snapshot: %v", err) + return nil + } + log.Printf("[DEBUG] Deleting snapshot with name: %v", d.Get("snapshot_name").(string)) + var consolidate_ptr *bool + var remove_children bool + + if v, ok := d.GetOk("consolidate"); ok { + consolidate := v.(bool) + consolidate_ptr = &consolidate + } else { + + consolidate := true + consolidate_ptr = &consolidate + } + if v, ok := d.GetOk("remove_children"); ok { + remove_children = v.(bool) + } else { + + remove_children = false + } + ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout) // This is 5 mins + defer cancel() + task, err := vm.RemoveSnapshot(ctx, d.Id(), remove_children, consolidate_ptr) + if err != nil { + log.Printf("[DEBUG] Error While Creating the Task for Delete Snapshot: %v", err) + return fmt.Errorf("Error While Creating the Task for Delete Snapshot: %s", err) + } + log.Printf("[DEBUG] Task created for Delete Snapshot: %v", task) + + err = task.Wait(ctx) + if err != nil { + log.Printf("[DEBUG] Error While waiting for the Task of Delete Snapshot: %v", err) + return fmt.Errorf("Error While waiting for the Task of Delete Snapshot: %s", err) + } + log.Printf("[DEBUG] Delete Snapshot completed %v", d.Get("snapshot_name").(string)) + + return nil +} + +func resourceVSphereSnapshotRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*govmomi.Client) + vm, err := virtualMachineFromUUID(client, d.Get("vm_uuid").(string)) + if err != nil { + return fmt.Errorf("Error while getting the VirtualMachine :%s", err) + } + ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout) // This is 5 mins + defer cancel() + snapshot, err := vm.FindSnapshot(ctx, d.Id()) + if err != nil { + if strings.Contains(err.Error(), "No snapshots for this VM") || strings.Contains(err.Error(), "snapshot \""+d.Get("snapshot_name").(string)+"\" not found") { + log.Printf("[DEBUG] Error While finding the Snapshot: %v", err) + d.SetId("") + return nil + } + log.Printf("[DEBUG] Error While finding the Snapshot: %v", err) + return fmt.Errorf("Error while finding the Snapshot :%s", err) + } + log.Printf("[DEBUG] Snapshot found: %v", snapshot) + return nil +} diff --git a/vsphere/resource_vsphere_virtual_machine_snapshot_test.go b/vsphere/resource_vsphere_virtual_machine_snapshot_test.go new file mode 100644 index 000000000..9e23647b4 --- /dev/null +++ b/vsphere/resource_vsphere_virtual_machine_snapshot_test.go @@ -0,0 +1,113 @@ +package vsphere + +import ( + "context" + "fmt" + "os" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/vmware/govmomi" +) + +func testBasicPreCheckSnapshot(t *testing.T) { + testAccPreCheck(t) +} + +func TestAccVmSnapshot_Basic(t *testing.T) { + var vmId, snapshotName, description, memory, quiesce string + if v := os.Getenv("VSPHERE_VM_UUID"); v != "" { + vmId = v + } + if v := os.Getenv("VSPHERE_VM_SNAPSHOT_NAME"); v != "" { + snapshotName = v + } + if v := os.Getenv("VSPHERE_VM_SNAPSHOT_DESC"); v != "" { + description = v + } + if v := os.Getenv("VSPHERE_VM_SNAPSHOT_MEMORY"); v != "" { + memory = v + } + if v := os.Getenv("VSPHERE_VM_SNAPSHOT_QUIESCE"); v != "" { + quiesce = v + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVmSnapshotDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckVSphereVMSnapshotConfig_basic(vmId, snapshotName, description, memory, quiesce), + Check: resource.ComposeTestCheckFunc( + testAccCheckVmSnapshotExists("vsphere_virtual_machine_snapshot.Test_terraform_cases"), + resource.TestCheckResourceAttr( + "vsphere_virtual_machine_snapshot.Test_terraform_cases", "snapshot_name", snapshotName), + ), + }, + }, + }) +} + +func testAccCheckVmSnapshotDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*govmomi.Client) + + for _, rs := range s.RootModule().Resources { + if rs.Type != "vsphere_virtual_machine_snapshot" { + continue + } + vm, err := virtualMachineFromUUID(client, rs.Primary.Attributes["vm_uuid"]) + if err != nil { + return fmt.Errorf("error %s", err) + } + + ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout) // This is 5 mins + defer cancel() + snapshot, err := vm.FindSnapshot(ctx, rs.Primary.Attributes["snapshot_name"]) + if err == nil { + return fmt.Errorf("Vm Snapshot still exists: %v", snapshot) + } + } + + return nil +} + +func testAccCheckVmSnapshotExists(n string) resource.TestCheckFunc { + return func(s *terraform.State) error { + rs, ok := s.RootModule().Resources[n] + + if !ok { + return fmt.Errorf("Not found: %s", n) + } + + if rs.Primary.ID == "" { + return fmt.Errorf("No Vm Snapshot ID is set") + } + client := testAccProvider.Meta().(*govmomi.Client) + + vm, err := virtualMachineFromUUID(client, rs.Primary.Attributes["vm_uuid"]) + if err != nil { + return fmt.Errorf("error %s", err) + } + ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout) // This is 5 mins + defer cancel() + snapshot, err := vm.FindSnapshot(ctx, rs.Primary.ID) + if err != nil { + return fmt.Errorf("Error while getting the snapshot %v", snapshot) + } + + return nil + } +} + +func testAccCheckVSphereVMSnapshotConfig_basic(vmUuid, snapshotName, description, memory, quiesce string) string { + return fmt.Sprintf(` +resource "vsphere_virtual_machine_snapshot" "Test_terraform_cases" { + vm_id = "%s" + snapshot_name = "%s" + description = "%s" + memory = %s + quiesce = %s +}`, vmUuid, snapshotName, description, memory, quiesce) +} diff --git a/vsphere/virtual_machine_helper.go b/vsphere/virtual_machine_helper.go new file mode 100644 index 000000000..3756882bf --- /dev/null +++ b/vsphere/virtual_machine_helper.go @@ -0,0 +1,22 @@ +package vsphere + +import ( + "context" + "log" + + "github.com/vmware/govmomi" + "github.com/vmware/govmomi/object" +) + +func virtualMachineFromUUID(client *govmomi.Client, vmUuid string) (*object.VirtualMachine, error) { + searchIndex := object.NewSearchIndex(client.Client) + ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout) + defer cancel() + reference, err := searchIndex.FindByUuid(ctx, nil, vmUuid, true, nil) + if err != nil { + log.Printf("[ERROR] " + err.Error()) + } + managedObjectRef := reference.Reference() + virtualMachine := object.NewVirtualMachine(client.Client, managedObjectRef) + return virtualMachine, err +} diff --git a/website/docs/index.html.markdown b/website/docs/index.html.markdown index ceaf4bd64..a4761f9bb 100644 --- a/website/docs/index.html.markdown +++ b/website/docs/index.html.markdown @@ -1,209 +1,222 @@ ---- -layout: "vsphere" -page_title: "Provider: VMware vSphere" -sidebar_current: "docs-vsphere-index" -description: |- - 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. ---- - -# VMware vSphere Provider - -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. - -Use the navigation to the left to read about the available resources. - -~> **NOTE:** The VMware vSphere Provider currently represents _initial support_ -and therefore may undergo significant changes as the community improves it. This -provider at this time only supports IPv4 addresses on virtual machines. - -## Example Usage - -```hcl -# Configure the VMware vSphere Provider -provider "vsphere" { - user = "${var.vsphere_user}" - password = "${var.vsphere_password}" - vsphere_server = "${var.vsphere_server}" - - # if you have a self-signed cert - allow_unverified_ssl = true -} - -# Create a folder -resource "vsphere_folder" "frontend" { - path = "frontend" -} - -# 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" -} - -# Create a disk image -resource "vsphere_virtual_disk" "extraStorage" { - size = 2 - vmdk_path = "myDisk.vmdk" - datacenter = "Datacenter" - datastore = "local" -} - -# Create a virtual machine within the folder -resource "vsphere_virtual_machine" "web" { - name = "terraform-web" - folder = "${vsphere_folder.frontend.path}" - vcpu = 2 - memory = 4096 - - network_interface { - label = "VM Network" - } - - disk { - template = "centos-7" - } -} -``` - -## Argument Reference - -The following arguments are used to configure the VMware vSphere Provider: - -* `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. -* `vsphere_server` - (Required) This is the vCenter server name for vSphere API - operations. Can also be specified with the `VSPHERE_SERVER` environment - variable. -* `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. -* `client_debug` - (Optional) Boolean to set the govomomi api to log soap calls - to disk. The log files are logged to `${HOME}/.govc`, the same path used by - `govc`. Can also be specified with the `VSPHERE_CLIENT_DEBUG` environment - variable. -* `client_debug_path` - (Optional) Override the default log path. Can also - be specified with the `VSPHERE_CLIENT_DEBUG_PATH` environment variable. -* `client_debug_path_run` - (Optional) Client debug file path for a single run. Can also - be specified with the `VSPHERE_CLIENT_DEBUG_PATH_RUN` environment variable. - -## 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) - -* License - - Add License - - Remove License - - Update License - - Update Labels - - -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. - -## Virtual Machine Customization - -Guest Operating Systems can be configured using -[customizations](https://pubs.vmware.com/vsphere-50/index.jsp#com.vmware.vsphere.vm_admin.doc_50/GUID-80F3F5B5-F795-45F1-B0FA-3709978113D5.html), -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 -[here](http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf) - -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: - -``` -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. -``` - -In order to skip the customization step for unsupported operating systems, use -the `skip_customization` argument on the virtual machine resource. - -## Acceptance Tests - -The VMware vSphere provider's acceptance tests require the above provider -configuration fields to be set using the documented environment variables. - -In addition, the following environment variables are used in tests, and must be -set to valid values for your VMware vSphere environment: - - * VSPHERE\_IPV4\_GATEWAY - * VSPHERE\_IPV4\_ADDRESS - * VSPHERE\_IPV6\_GATEWAY - * VSPHERE\_IPV6\_ADDRESS - * VSPHERE\_NETWORK\_LABEL - * VSPHERE\_NETWORK\_LABEL\_DHCP - * VSPHERE\_TEMPLATE - * VSPHERE\_MAC\_ADDRESS - * VSPHERE_LICENSE - -The following environment variables depend on your vSphere environment: - - * VSPHERE\_DATACENTER - * VSPHERE\_CLUSTER - * VSPHERE\_RESOURCE\_POOL - * VSPHERE\_DATASTORE - * VSPHERE\_TEST\_ESXI - -The following additional environment variables are needed for running the -"Mount ISO as CDROM media" acceptance tests. - - * VSPHERE\_CDROM\_DATASTORE - * VSPHERE\_CDROM\_PATH - - -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 -``` - - +--- +layout: "vsphere" +page_title: "Provider: VMware vSphere" +sidebar_current: "docs-vsphere-index" +description: |- + 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. +--- + +# VMware vSphere Provider + +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. + +Use the navigation to the left to read about the available resources. + +~> **NOTE:** The VMware vSphere Provider currently represents _initial support_ +and therefore may undergo significant changes as the community improves it. This +provider at this time only supports IPv4 addresses on virtual machines. + +## Example Usage + +```hcl +# Configure the VMware vSphere Provider +provider "vsphere" { + user = "${var.vsphere_user}" + password = "${var.vsphere_password}" + vsphere_server = "${var.vsphere_server}" + + # if you have a self-signed cert + allow_unverified_ssl = true +} + +# Create a folder +resource "vsphere_folder" "frontend" { + path = "frontend" +} + +# 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" +} + +# Create a disk image +resource "vsphere_virtual_disk" "extraStorage" { + size = 2 + vmdk_path = "myDisk.vmdk" + datacenter = "Datacenter" + datastore = "local" +} + +# Create a virtual machine within the folder +resource "vsphere_virtual_machine" "web" { + name = "terraform-web" + folder = "${vsphere_folder.frontend.path}" + vcpu = 2 + memory = 4096 + + network_interface { + label = "VM Network" + } + + disk { + template = "centos-7" + } +} + +#Create and delete a snapshot of virtual machine +resource "vsphere_virtual_machine_snapshot" "demo1" { + vm_uuid = "42392f34-82c2-6b34-175f-3d392afbc4f1" + snapshot_name = "Snapshot Name" + description = "This is Demo Snapshot" + memory = "true" + quiesce = "true" + remove_children = "false" + consolidate = "true" +} + +``` + +## Argument Reference + +The following arguments are used to configure the VMware vSphere Provider: + +* `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. +* `vsphere_server` - (Required) This is the vCenter server name for vSphere API + operations. Can also be specified with the `VSPHERE_SERVER` environment + variable. +* `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. +* `client_debug` - (Optional) Boolean to set the govomomi api to log soap calls + to disk. The log files are logged to `${HOME}/.govc`, the same path used by + `govc`. Can also be specified with the `VSPHERE_CLIENT_DEBUG` environment + variable. +* `client_debug_path` - (Optional) Override the default log path. Can also + be specified with the `VSPHERE_CLIENT_DEBUG_PATH` environment variable. +* `client_debug_path_run` - (Optional) Client debug file path for a single run. Can also + be specified with the `VSPHERE_CLIENT_DEBUG_PATH_RUN` environment variable. + +## 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) + +* License + - Add License + - Remove License + - Update License + - Update Labels + +* Snapshot + - Create snapshot of VM + - Delete snapshot of VM + +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. + +## Virtual Machine Customization + +Guest Operating Systems can be configured using +[customizations](https://pubs.vmware.com/vsphere-50/index.jsp#com.vmware.vsphere.vm_admin.doc_50/GUID-80F3F5B5-F795-45F1-B0FA-3709978113D5.html), +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 +[here](http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf) + +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: + +``` +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. +``` + +In order to skip the customization step for unsupported operating systems, use +the `skip_customization` argument on the virtual machine resource. + +## Acceptance Tests + +The VMware vSphere provider's acceptance tests require the above provider +configuration fields to be set using the documented environment variables. + +In addition, the following environment variables are used in tests, and must be +set to valid values for your VMware vSphere environment: + + * VSPHERE\_IPV4\_GATEWAY + * VSPHERE\_IPV4\_ADDRESS + * VSPHERE\_IPV6\_GATEWAY + * VSPHERE\_IPV6\_ADDRESS + * VSPHERE\_NETWORK\_LABEL + * VSPHERE\_NETWORK\_LABEL\_DHCP + * VSPHERE\_TEMPLATE + * VSPHERE\_MAC\_ADDRESS + * VSPHERE_LICENSE + +The following environment variables depend on your vSphere environment: + + * VSPHERE\_DATACENTER + * VSPHERE\_CLUSTER + * VSPHERE\_RESOURCE\_POOL + * VSPHERE\_DATASTORE + * VSPHERE\_TEST\_ESXI + +The following additional environment variables are needed for running the +"Mount ISO as CDROM media" acceptance tests. + + * VSPHERE\_CDROM\_DATASTORE + * VSPHERE\_CDROM\_PATH + + +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 +``` \ No newline at end of file diff --git a/website/docs/r/virtual_machine_snapshot.html.markdown b/website/docs/r/virtual_machine_snapshot.html.markdown new file mode 100644 index 000000000..53510f45b --- /dev/null +++ b/website/docs/r/virtual_machine_snapshot.html.markdown @@ -0,0 +1,47 @@ +--- +layout: "vsphere" +page_title: "VMware vSphere: vsphere_virtual_machine_snapshot" +sidebar_current: "docs-vsphere-resource-virtual-machine-snapshot" +description: |- + Provides a VMware vSphere virtual machine snapshot resource. This can be used to create and delete virtual machine's snapshot. +--- + +# vsphere\_virtual\_machine\_snapshot + +Provides a VMware vSphere virtual machine snapshot resource. This can be used to create and +delete. + +## Example Usage + +```hcl +resource "vsphere_virtual_machine_snapshot" "demo1" { + vm_uuid = "42392f34-82c2-6b34-175f-3d392afbc4f1" + snapshot_name = "Snapshot Name" + description = "This is Demo Snapshot" + memory = "true" + quiesce = "true" + remove_children = "false" - getting used during delete vm + consolidate = "true" +} + +``` + + +## Argument Reference + +The following arguments are supported: + +For resource vsphere_virtual_machine_snapshot + +* `vm_uuid` - (Required) The virtual machine uuid +* `snapshot_name` - (Required) New name for the snapshot. +* `description` - (Required) New description for the snapshot. +* `memory` - (Required) If the memory flag set to true, a dump of the internal state of the virtual machine is included in the snapshot. +* `quiesce` - (Required) If the quiesce flag set to true, and the virtual machine is powered on when the snapshot is taken, VMware Tools is used to quiesce the file system in the virtual machine. +* `remove_children` - (Optional) Flag to specify removal of the entire snapshot subtree. +* `consolidate` - (Optional) If set to true, the virtual disk associated with this snapshot will be merged with other disk if possible. Defaults to true. + + + + + diff --git a/website/vsphere.erb b/website/vsphere.erb index dc3f98e98..2b36a42c4 100644 --- a/website/vsphere.erb +++ b/website/vsphere.erb @@ -58,6 +58,9 @@ > vsphere_vmfs_datastore + > + vsphere_virtual_machine_snapshot +