Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/virtual_machine: Explicitly block cloning on standalone ESXi #476

Merged
merged 1 commit into from
Apr 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ func resourceVSphereVirtualMachineCustomizeDiff(d *schema.ResourceDiff, meta int
// If this is a new resource and we are cloning, perform all clone validation
// operations.
if len(d.Get("clone").([]interface{})) > 0 {
if err := viapi.ValidateVirtualCenter(client); err != nil {
return errors.New("use of the clone sub-resource block requires vCenter")
}

switch {
case d.Get("imported").(bool):
// Imported workflows need to have the configuration of the clone
Expand Down
22 changes: 22 additions & 0 deletions vsphere/resource_vsphere_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,28 @@ func TestAccResourceVSphereVirtualMachine_cloneWithDifferentTimezone(t *testing.
})
}

func TestAccResourceVSphereVirtualMachine_cloneBlockESXi(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccResourceVSphereVirtualMachinePreCheck(t)
testAccSkipIfNotEsxi(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccResourceVSphereVirtualMachineConfigClone(),
ExpectError: regexp.MustCompile("use of the clone sub-resource block requires vCenter"),
PlanOnly: true,
},
{
Config: testAccResourceVSphereEmpty,
Check: resource.ComposeTestCheckFunc(),
},
},
})
}

func TestAccResourceVSphereVirtualMachine_cloneWithBadTimezone(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/virtual_machine.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ Windows machines), and disk attributes.

[tf-vsphere-virtual-machine-ds]: /docs/providers/vsphere/d/virtual_machine.html

~> **NOTE:** Cloning requires vCenter and is not supported on direct ESXi
connections.

```hcl
data "vsphere_datacenter" "dc" {
name = "dc1"
Expand Down Expand Up @@ -460,6 +463,10 @@ external disks on virtual machines that are assigned to datastore clusters.
specified template. Optional customization options can be submitted as well.
See [creating a virtual machine from a
template](#creating-a-virtual-machine-from-a-template) for more details.

~> **NOTE:** Cloning requires vCenter and is not supported on direct ESXi
connections.

* `vapp` - (Optional) Optional vApp configuration. The only sub-key available
is `properties`, which is a key/value map of properties for virtual machines
imported from OVF or OVA files. See [Using vApp properties to supply OVF/OVA
Expand Down Expand Up @@ -908,6 +915,9 @@ example](#cloning-and-customization-example) for a usage synopsis.
~> **NOTE:** Changing any option in `clone` after creation forces a new
resource.

~> **NOTE:** Cloning requires vCenter and is not supported on direct ESXi
connections.

The options available in the `clone` sub-resource are:

* `template_uuid` - (Required) The UUID of the source virtual machine or
Expand Down