mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-11 18:00:59 -04:00
Updates and tweaks
This commit is contained in:
@@ -106,8 +106,14 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone UUID
|
||||
zoneid, e := retrieveUUID(cs, "zone", d.Get("zone").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone object
|
||||
zone, _, err := cs.Zone.GetZoneByName(d.Get("zone").(string))
|
||||
zone, _, err := cs.Zone.GetZoneByID(zoneid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -168,12 +174,18 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
||||
if userData, ok := d.GetOk("user_data"); ok {
|
||||
ud := base64.StdEncoding.EncodeToString([]byte(userData.(string)))
|
||||
|
||||
// deployVirtualMachine uses POST, so max userdata is 32K
|
||||
// https://github.com/xanzy/go-cloudstack/commit/c767de689df1faedfec69233763a7c5334bee1f6
|
||||
if len(ud) > 32768 {
|
||||
// deployVirtualMachine uses POST by default, so max userdata is 32K
|
||||
maxUD := 32768
|
||||
|
||||
if cs.HTTPGETOnly {
|
||||
// deployVirtualMachine using GET instead, so max userdata is 2K
|
||||
maxUD = 2048
|
||||
}
|
||||
|
||||
if len(ud) > maxUD {
|
||||
return fmt.Errorf(
|
||||
"The supplied user_data contains %d bytes after encoding, "+
|
||||
"this exeeds the limit of 32768 bytes", len(ud))
|
||||
"this exeeds the limit of %d bytes", len(ud), maxUD)
|
||||
}
|
||||
|
||||
p.SetUserdata(ud)
|
||||
@@ -204,7 +216,6 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
|
||||
if err != nil {
|
||||
if count == 0 {
|
||||
log.Printf("[DEBUG] Instance %s does no longer exist", d.Get("name").(string))
|
||||
// Clear out all details so it's obvious the instance is gone
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
@@ -216,13 +227,13 @@ func resourceCloudStackInstanceRead(d *schema.ResourceData, meta interface{}) er
|
||||
d.Set("name", vm.Name)
|
||||
d.Set("display_name", vm.Displayname)
|
||||
d.Set("ipaddress", vm.Nic[0].Ipaddress)
|
||||
d.Set("zone", vm.Zonename)
|
||||
//NB cloudstack sometimes sends back the wrong keypair name, so dont update it
|
||||
|
||||
setValueOrUUID(d, "network", vm.Nic[0].Networkname, vm.Nic[0].Networkid)
|
||||
setValueOrUUID(d, "service_offering", vm.Serviceofferingname, vm.Serviceofferingid)
|
||||
setValueOrUUID(d, "template", vm.Templatename, vm.Templateid)
|
||||
setValueOrUUID(d, "project", vm.Project, vm.Projectid)
|
||||
setValueOrUUID(d, "zone", vm.Zonename, vm.Zoneid)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -256,7 +267,8 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
||||
// Attributes that require reboot to update
|
||||
if d.HasChange("service_offering") || d.HasChange("keypair") {
|
||||
// Before we can actually make these changes, the virtual machine must be stopped
|
||||
_, err := cs.VirtualMachine.StopVirtualMachine(cs.VirtualMachine.NewStopVirtualMachineParams(d.Id()))
|
||||
_, err := cs.VirtualMachine.StopVirtualMachine(
|
||||
cs.VirtualMachine.NewStopVirtualMachineParams(d.Id()))
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error stopping instance %s before making changes: %s", name, err)
|
||||
@@ -299,12 +311,14 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
|
||||
}
|
||||
|
||||
// Start the virtual machine again
|
||||
_, err = cs.VirtualMachine.StartVirtualMachine(cs.VirtualMachine.NewStartVirtualMachineParams(d.Id()))
|
||||
_, err = cs.VirtualMachine.StartVirtualMachine(
|
||||
cs.VirtualMachine.NewStartVirtualMachineParams(d.Id()))
|
||||
if err != nil {
|
||||
return fmt.Errorf(
|
||||
"Error starting instance %s after making changes", name)
|
||||
}
|
||||
}
|
||||
|
||||
d.Partial(false)
|
||||
return resourceCloudStackInstanceRead(d, meta)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user