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: add vApp properties #303

Merged
merged 23 commits into from
Jan 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fe8c313
Add VApp properties to r/virtual_machine
rowanjacobs Dec 8, 2017
812d2d3
Nest properties under top-level vApp subresource
rowanjacobs Dec 8, 2017
53925ef
Test updating and removing vapp properties
mcwumbly Dec 8, 2017
050919e
support empty vapp and vapp.properties blocks
rowanjacobs Dec 13, 2017
6cc04ab
Return *VmConfigSpec instead of BaseVmConfigSpec
rowanjacobs Jan 2, 2018
3e1d394
Use CoreOS OVA for testing
rowanjacobs Jan 2, 2018
8017ae4
Get old vApp properties from VM template
rowanjacobs Jan 2, 2018
817a852
zero out unset properties
rowanjacobs Jan 3, 2018
c27efe4
respect nonempty default values set in vapp properties
rowanjacobs Jan 3, 2018
31881de
Read all non-default vapp property values
desmondrawls Jan 3, 2018
4cb7e4f
Move vapp to schemaVirtualMachineConfigSpec
rowanjacobs Jan 3, 2018
032d70c
Reboot required for change in vApp config
rowanjacobs Jan 8, 2018
dfb9168
Don't need to loop over new vApp map values
rowanjacobs Jan 11, 2018
3170e96
Unsupported vApp properties throw an error
Jan 12, 2018
de8cf26
Spelling
rowanjacobs Jan 12, 2018
4cc701b
r/virtual_machine: Roll back clones on errors with config expansion
vancluever Jan 12, 2018
eb013b2
r/virtual_machine: Block vApp properties on from-scratch scenarios
vancluever Jan 12, 2018
c3fd7da
r/virtual_machine: Fix a couple of golint issues
vancluever Jan 12, 2018
c309d3c
r/virtual_machine: Document new vApp functionality
vancluever Jan 12, 2018
646758c
Merge branch 'master' into rowanjacobs/master
vancluever Jan 12, 2018
b19e6d3
r/virtual_machine: vApp tests use CoreOS template
vancluever Jan 12, 2018
ab73496
r/virtual_machine: Fix tests
vancluever Jan 12, 2018
ca780b0
r/virtual_machine: Add vApp property failure tests
vancluever Jan 13, 2018
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
1 change: 1 addition & 0 deletions tf-vsphere-devrc.mk.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export VSPHERE_ALLOW_UNVERIFIED_SSL ?= false
# succeed, it's probably best to set all of these to valid values.
export VSPHERE_TEMPLATE ?= base-linux # VM template to clone
export VSPHERE_TEMPLATE_WINDOWS ?= base-win # Windows VM template
export VSPHERE_TEMPLATE_COREOS ?= base-core # CoreOS template from OVA
export VSPHERE_NETWORK_LABEL ?= vm-network # Port group label
export VSPHERE_NETWORK_LABEL_DHCP ?= vm-network # Port group label for DHCP
export VSPHERE_NETWORK_LABEL_PXE ?= vm-network # Port group label for PXE
Expand Down
53 changes: 40 additions & 13 deletions vsphere/resource_vsphere_virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,12 @@ func resourceVSphereVirtualMachineUpdate(d *schema.ResourceData, meta interface{
if err != nil {
return fmt.Errorf("error fetching VM properties: %s", err)
}
spec, changed := expandVirtualMachineConfigSpecChanged(d, client, vprops.Config)

spec, changed, err := expandVirtualMachineConfigSpecChanged(d, client, vprops.Config)
if err != nil {
return fmt.Errorf("error in virtual machine configuration: %s", err)
}

devices := object.VirtualDeviceList(vprops.Config.Hardware.Device)
if spec.DeviceChange, err = applyVirtualDevices(d, client, devices); err != nil {
return err
Expand Down Expand Up @@ -648,7 +653,10 @@ func resourceVSphereVirtualMachineCreateBare(d *schema.ResourceData, meta interf
}

// Ready to start making the VM here. First expand our main config spec.
spec := expandVirtualMachineConfigSpec(d, client)
spec, err := expandVirtualMachineConfigSpec(d, client)
if err != nil {
return nil, fmt.Errorf("error in virtual machine configuration: %s", err)
}

// Set the datastore for the VM.
ds, err := datastore.FromID(client, d.Get("datastore_id").(string))
Expand Down Expand Up @@ -741,7 +749,10 @@ func resourceVSphereVirtualMachineCreateClone(d *schema.ResourceData, meta inter
// configuration of the newly cloned VM. This is basically a subset of update
// with the stipulation that there is currently no state to help move this
// along.
cfgSpec := expandVirtualMachineConfigSpec(d, client)
cfgSpec, err := expandVirtualMachineConfigSpec(d, client)
if err != nil {
return nil, resourceVSphereVirtualMachineRollbackCreate(d, meta, vm, fmt.Errorf("error in virtual machine configuration: %s", err))
}

// To apply device changes, we need the current devicecfgSpec from the config
// info. We then filter this list through the same apply process we did for
Expand Down Expand Up @@ -777,16 +788,7 @@ func resourceVSphereVirtualMachineCreateClone(d *schema.ResourceData, meta inter

// Perform updates
if err := virtualmachine.Reconfigure(vm, cfgSpec); err != nil {
// Delete the virtual machine if the update failed here. Updates are
// largely atomic, so more than likely no disks with keep_on_remove were
// attached, but just in case, we run this through delete to make sure to
// safely remove any disk that may have been attached as part of this
// process if it was flagged as such.
if derr := resourceVSphereVirtualMachineDelete(d, meta); derr != nil {
return nil, fmt.Errorf(formatVirtualMachinePostCloneRollbackError, vm.InventoryPath, err, derr)
}
d.SetId("")
return nil, fmt.Errorf("error reconfiguring virtual machine: %s", err)
return nil, resourceVSphereVirtualMachineRollbackCreate(d, meta, vm, fmt.Errorf("error reconfiguring virtual machine: %s", err))
}

var cw *virtualMachineCustomizationWaiter
Expand Down Expand Up @@ -824,6 +826,31 @@ func resourceVSphereVirtualMachineCreateClone(d *schema.ResourceData, meta inter
return vm, nil
}

// resourceVSphereVirtualMachineRollbackCreate attempts to "roll back" a
// resource due to an error that happened post-create that will put the VM in a
// state where it cannot be worked with. This should only be done early on in
// the process, namely on clone operations between when the clone actually
// happens, and no later than after the initial post-clone update is complete.
//
// If the rollback fails, an error is displayed prompting the user to manually
// delete the virtual machine before trying again.
func resourceVSphereVirtualMachineRollbackCreate(
d *schema.ResourceData,
meta interface{},
vm *object.VirtualMachine,
origErr error,
) error {
// Updates are largely atomic, so more than likely no disks with
// keep_on_remove were attached, but just in case, we run this through delete
// to make sure to safely remove any disk that may have been attached as part
// of this process if it was flagged as such.
if err := resourceVSphereVirtualMachineDelete(d, meta); err != nil {
return fmt.Errorf(formatVirtualMachinePostCloneRollbackError, vm.InventoryPath, origErr, err)
}
d.SetId("")
return fmt.Errorf("error reconfiguring virtual machine: %s", origErr)
}

// resourceVSphereVirtualMachineUpdateLocation manages vMotion. This includes
// the migration of a VM from one host to another, or from one datastore to
// another (storage vMotion).
Expand Down
Loading