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: Allow vMotions to other clusters #474

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
3 changes: 2 additions & 1 deletion tf-vsphere-devrc.mk.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export VSPHERE_IPV4_GATEWAY ?= 10.0.0.1 # Customization gateway
export VSPHERE_DNS ?= 10.0.0.10 # Customization DNS
export VSPHERE_DATACENTER ?= vm-dc # VM placement DC
export VSPHERE_CLUSTER ?= vm-clus1 # VM placement cluster
export VSPHERE_EMPTY_CLUSTER ?= vm-clus2 # Empty cluster for testing
export VSPHERE_CLUSTER2 ?= vm-clus2 # Extra cluster for testing
export VSPHERE_EMPTY_CLUSTER ?= clus-empty # Empty cluster for testing
export VSPHERE_RESOURCE_POOL ?= vm-respool # VM resource resource pool
export VSPHERE_DATASTORE ?= datastore1 # VM placement datastore
export VSPHERE_DATASTORE2 ?= datastore2 # 2nd datastore for vMotion
Expand Down
18 changes: 18 additions & 0 deletions vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,11 @@ func resourceVSphereVirtualMachineCustomizeDiff(d *schema.ResourceDiff, meta int
return err
}

// Process changes to resource pool
if err := resourceVSphereVirtualMachineCustomizeDiffResourcePoolOperation(d); err != nil {
return err
}

// Normalize datastore cluster vs datastore
if err := datastoreClusterDiffOperation(d, client); err != nil {
return err
Expand Down Expand Up @@ -661,6 +666,19 @@ func resourceVSphereVirtualMachineCustomizeDiff(d *schema.ResourceDiff, meta int
return nil
}

func resourceVSphereVirtualMachineCustomizeDiffResourcePoolOperation(d *schema.ResourceDiff) error {
if d.HasChange("resource_pool_id") && !d.HasChange("host_system_id") {
log.Printf(
"[DEBUG] %s: resource_pool_id modified without change to host_system_id, marking as computed",
resourceVSphereVirtualMachineIDString(d),
)
if err := d.SetNewComputed("host_system_id"); err != nil {
return err
}
}
return nil
}

func datastoreClusterDiffOperation(d *schema.ResourceDiff, client *govmomi.Client) error {
podID, podOk := d.GetOk("datastore_cluster_id")
podKnown := d.NewValueKnown("datastore_cluster_id")
Expand Down
30 changes: 30 additions & 0 deletions vsphere/resource_vsphere_virtual_machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,33 @@ func TestAccResourceVSphereVirtualMachine_resourcePoolVMotion(t *testing.T) {
})
}

func TestAccResourceVSphereVirtualMachine_clusterVMotion(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccResourceVSphereVirtualMachinePreCheck(t)
},
Providers: testAccProviders,
CheckDestroy: testAccResourceVSphereVirtualMachineCheckExists(false),
Steps: []resource.TestStep{
{
Config: testAccResourceVSphereVirtualMachineConfigResourcePoolVMotion(os.Getenv("VSPHERE_RESOURCE_POOL")),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereVirtualMachineCheckExists(true),
testAccResourceVSphereVirtualMachineCheckResourcePool(os.Getenv("VSPHERE_RESOURCE_POOL")),
),
},
{
Config: testAccResourceVSphereVirtualMachineConfigResourcePoolVMotion(fmt.Sprintf("%s/Resources", os.Getenv("VSPHERE_CLUSTER2"))),
Check: resource.ComposeTestCheckFunc(
testAccResourceVSphereVirtualMachineCheckExists(true),
testAccResourceVSphereVirtualMachineCheckResourcePool(fmt.Sprintf("%s/Resources", os.Getenv("VSPHERE_CLUSTER2"))),
),
},
},
})
}

func TestAccResourceVSphereVirtualMachine_storageVMotionGlobalSetting(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
Expand Down Expand Up @@ -2559,6 +2586,9 @@ func testAccResourceVSphereVirtualMachinePreCheck(t *testing.T) {
if os.Getenv("VSPHERE_CLUSTER") == "" {
t.Skip("set VSPHERE_CLUSTER to run vsphere_virtual_machine acceptance tests")
}
if os.Getenv("VSPHERE_CLUSTER2") == "" {
t.Skip("set VSPHERE_CLUSTER2 to run vsphere_virtual_machine acceptance tests")
}
if os.Getenv("VSPHERE_RESOURCE_POOL") == "" {
t.Skip("set VSPHERE_RESOURCE_POOL to run vsphere_virtual_machine acceptance tests")
}
Expand Down