You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by "sureshanaparti (via GitHub)" <gi...@apache.org> on 2026/08/17 11:07:21 UTC
[PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
sureshanaparti opened a new pull request, #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323
When the service_offering of an instance changes, the provider must call ScaleVirtualMachine to actually scale the VM's CPU and memory resources. The previous implementation used ChangeServiceForVirtualMachine which only updated CloudStack metadata without scaling the actual VM.
This change ensures that when a service offering is updated, the VM is properly scaled with the new compute resources.
Fixes: #273
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "sureshanaparti (via GitHub)" <gi...@apache.org>.
sureshanaparti commented on code in PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#discussion_r3801006482
##########
cloudstack/resource_cloudstack_instance_test.go:
##########
@@ -695,3 +761,41 @@ resource "cloudstack_instance" "foobar" {
expunge = true
# Note: project is NOT specified here - it should be inherited from the network
}`
+
+const testAccCloudStackInstance_scale = `
+resource "cloudstack_network" "foo" {
+ name = "terraform-network"
+ display_text = "terraform-network"
+ cidr = "10.1.1.0/24"
+ network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
+ zone = "Sandbox-simulator"
+}
+
+resource "cloudstack_instance" "foobar" {
+ name = "terraform-test"
+ display_name = "terraform-test"
+ service_offering = "Small Instance"
+ network_id = cloudstack_network.foo.id
+ template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
+ zone = "Sandbox-simulator"
+ expunge = true
+}`
+
+const testAccCloudStackInstance_scaleUp = `
+resource "cloudstack_network" "foo" {
+ name = "terraform-network"
+ display_text = "terraform-network"
+ cidr = "10.1.1.0/24"
+ network_offering = "DefaultIsolatedNetworkOfferingWithSourceNatService"
+ zone = "Sandbox-simulator"
+}
+
+resource "cloudstack_instance" "foobar" {
+ name = "terraform-test"
+ display_name = "terraform-test"
+ service_offering = "Medium Instance"
+ network_id = cloudstack_network.foo.id
+ template = "CentOS 5.6 (64-bit) no GUI (Simulator)"
+ zone = "Sandbox-simulator"
+ expunge = true
+}`
Review Comment:
```suggestion
}`
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#discussion_r3805221255
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -704,234 +705,335 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
"Error stopping instance %s before making changes: %s", name, err)
}
- // Check if the name has changed and if so, update the name
- if d.HasChange("name") {
- log.Printf("[DEBUG] Name for %s changed to %s, starting update", d.Id(), name)
+ // Apply each attribute change that requires the VM to be stopped.
+ // Each helper is a no-op unless its own attribute changed.
+ if err := updateInstanceName(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateServiceOffering(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateComputeDetails(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateAffinityGroupIds(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateAffinityGroupNames(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateKeypair(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateUserData(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateUserdataId(cs, d, name); err != nil {
+ return err
+ }
+ if err := updateUserdataDetails(cs, d, name); err != nil {
+ return err
+ }
- // Create a new parameter struct
- p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
+ // Start the virtual machine again
+ _, err = cs.VirtualMachine.StartVirtualMachine(
+ cs.VirtualMachine.NewStartVirtualMachineParams(d.Id()))
+ if err != nil {
+ return fmt.Errorf(
+ "Error starting instance %s after making changes", name)
+ }
+ }
- // Set the new name
- p.SetName(name)
+ // Check if the tags have changed and if so, update the tags
+ if d.HasChange("tags") {
+ if err := updateTags(cs, d, "UserVm"); err != nil {
+ return fmt.Errorf("Error updating tags on instance %s: %s", name, err)
+ }
+ }
- // Update the display name
- _, err := cs.VirtualMachine.UpdateVirtualMachine(p)
- if err != nil {
- return fmt.Errorf(
- "Error updating the name for instance %s: %s", name, err)
- }
+ // Check if the delete protection has changed and if so, update the deleteprotection
+ if d.HasChange("delete_protection") {
+ p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
+ p.SetDeleteprotection(d.Get("delete_protection").(bool))
+ _, err := cs.VirtualMachine.UpdateVirtualMachine(p)
+ if err != nil {
+ return fmt.Errorf(
+ "Error updating the delete protection for instance %s: %s", name, err)
}
+ }
- // Check if the service offering is changed and if so, update the offering
- if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ return resourceCloudStackInstanceRead(d, meta)
+}
- // Retrieve the zone ID first (needed for service_offering lookup)
- zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
- if e != nil {
- return e.Error()
- }
+// updateInstanceName renames the (stopped) VM when the name attribute changed.
+func updateInstanceName(cs *cloudstack.CloudStackClient, d *schema.ResourceData, name string) error {
+ if !d.HasChange("name") {
+ return nil
+ }
- // Retrieve the service_offering ID (filtered by zone)
- serviceofferingid, e := retrieveServiceOfferingID(cs, zoneid, d.Get("service_offering").(string))
- if e != nil {
- return e.Error()
- }
+ log.Printf("[DEBUG] Name for %s changed to %s, starting update", d.Id(), name)
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ p := cs.VirtualMachine.NewUpdateVirtualMachineParams(d.Id())
+ p.SetName(name)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
- if err != nil {
- return fmt.Errorf(
- "Error changing the service offering for instance %s: %s", name, err)
- }
- }
+ if _, err := cs.VirtualMachine.UpdateVirtualMachine(p); err != nil {
+ return fmt.Errorf(
+ "Error updating the name for instance %s: %s", name, err)
+ }
- // Check if the affinity group IDs have changed and if so, update the IDs
- if d.HasChange("affinity_group_ids") {
- p := cs.AffinityGroup.NewUpdateVMAffinityGroupParams(d.Id())
- groups := []string{}
+ return nil
+}
- if agIDs := d.Get("affinity_group_ids").(*schema.Set); agIDs.Len() > 0 {
- for _, group := range agIDs.List() {
- groups = append(groups, group.(string))
- }
- }
+// updateServiceOffering scales the (stopped) VM to a new service offering.
+func updateServiceOffering(cs *cloudstack.CloudStackClient, d *schema.ResourceData, name string) error {
+ if !d.HasChange("service_offering") {
+ return nil
+ }
- // Set the new groups
- p.SetAffinitygroupids(groups)
+ oldOffering, newOffering := d.GetChange("service_offering")
+ log.Printf("[DEBUG] Service offering changed for %s from %s to %s, starting scale", name, oldOffering, newOffering)
- // Update the affinity groups
- _, err = cs.AffinityGroup.UpdateVMAffinityGroup(p)
- if err != nil {
- return fmt.Errorf(
- "Error updating the affinity groups for instance %s: %s", name, err)
- }
- }
+ // Retrieve the zone ID first (needed for service_offering lookup)
+ zoneid, e := retrieveID(cs, "zone", d.Get("zone").(string))
+ if e != nil {
+ return e.Error()
+ }
- // Check if the affinity group names have changed and if so, update the names
- if d.HasChange("affinity_group_names") {
- p := cs.AffinityGroup.NewUpdateVMAffinityGroupParams(d.Id())
- groups := []string{}
+ // Retrieve the service_offering ID (filtered by zone)
+ serviceofferingid, e := retrieveServiceOfferingID(cs, zoneid, d.Get("service_offering").(string))
+ if e != nil {
+ return e.Error()
+ }
- if agNames := d.Get("affinity_group_names").(*schema.Set); agNames.Len() > 0 {
- for _, group := range agNames.List() {
- groups = append(groups, group.(string))
- }
- }
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
+ if _, err := cs.VirtualMachine.ScaleVirtualMachine(p); err != nil {
+ return fmt.Errorf(
+ "Error scaling VM %s from %s to %s: %s", name, oldOffering, newOffering, err)
+ }
+
+ return nil
+}
+
+// updateComputeDetails scales the (stopped) VM when the compute-related details
+// (cpuNumber, cpuSpeed, memory) changed, keeping the current service offering.
+func updateComputeDetails(cs *cloudstack.CloudStackClient, d *schema.ResourceData, name string) error {
+ if !d.HasChange("details") {
+ return nil
+ }
- // Set the new groups
- p.SetAffinitygroupnames(groups)
+ oldDetails, newDetails := d.GetChange("details")
- // Update the affinity groups
- _, err = cs.AffinityGroup.UpdateVMAffinityGroup(p)
- if err != nil {
- return fmt.Errorf(
- "Error updating the affinity groups for instance %s: %s", name, err)
- }
+ // Safely coerce details, treating nil as empty map
+ var oldDetailsMap, newDetailsMap map[string]interface{}
+ if oldDetails != nil {
+ oldDetailsMap = oldDetails.(map[string]interface{})
+ } else {
+ oldDetailsMap = make(map[string]interface{})
+ }
+ if newDetails != nil {
+ newDetailsMap = newDetails.(map[string]interface{})
+ } else {
+ newDetailsMap = make(map[string]interface{})
+ }
+
+ // Check if any compute-related details changed (cpuNumber, cpuSpeed, memory)
+ computeDetailsChanged := false
+ for _, key := range []string{"cpuNumber", "cpuSpeed", "memory"} {
+ if oldDetailsMap[key] != newDetailsMap[key] {
+ computeDetailsChanged = true
+ break
}
+ }
+
+ if !computeDetailsChanged {
+ return nil
+ }
- // Check if the keypair has changed and if so, update the keypair
- if d.HasChange("keypair") || d.HasChange("keypairs") {
- log.Printf("[DEBUG] SSH keypair(s) changed for %s, starting update", name)
+ log.Printf("[DEBUG] Compute details changed for %s, scaling VM", name)
- p := cs.SSH.NewResetSSHKeyForVirtualMachineParams(d.Id())
+ // Convert details map for API call, safely stringifying values
+ detailsForAPI := make(map[string]string)
+ for k, v := range newDetailsMap {
+ detailsForAPI[k] = fmt.Sprintf("%v", v)
+ }
- if keypair, ok := d.GetOk("keypair"); ok {
- p.SetKeypair(keypair.(string))
- }
+ // Get current service offering ID for details-only scaling
+ currentServiceOfferingID, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
+ if e != nil {
+ return e.Error()
+ }
- if keypairs, ok := d.GetOk("keypairs"); ok {
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), currentServiceOfferingID)
+ p.SetDetails(detailsForAPI)
Review Comment:
`details` changes that *don’t* touch `cpuNumber`, `cpuSpeed`, or `memory` are now silently ignored (the function returns early). Previously, `details` was applied via `UpdateVirtualMachine`, so this is a functional regression. Consider: (1) if `details` changed but compute keys did not, call `UpdateVirtualMachine` with the updated `details`; and (2) if compute keys changed, perform `ScaleVirtualMachine` for compute keys and still apply any remaining non-compute detail changes via `UpdateVirtualMachine`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#discussion_r3795914216
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -681,24 +681,24 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
- // Check if the service offering is changed and if so, update the offering
+ // Check if the service offering is changed and if so, scale the VM
if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ log.Printf("[DEBUG] Service offering changed for %s, starting scale", name)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ // Create a new parameter struct for scaling
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
+ // Scale the VM to the new service offering
+ _, err = cs.VirtualMachine.ScaleVirtualMachine(p)
if err != nil {
return fmt.Errorf(
- "Error changing the service offering for instance %s: %s", name, err)
+ "Error scaling the service offering for instance %s: %s", name, err)
Review Comment:
The new error message reads like the *service offering* is being scaled, but the operation is scaling the VM to a different service offering. Including the target service offering (name/id) will make failures easier to debug.
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -681,24 +681,24 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
- // Check if the service offering is changed and if so, update the offering
+ // Check if the service offering is changed and if so, scale the VM
if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ log.Printf("[DEBUG] Service offering changed for %s, starting scale", name)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ // Create a new parameter struct for scaling
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
+ // Scale the VM to the new service offering
+ _, err = cs.VirtualMachine.ScaleVirtualMachine(p)
Review Comment:
This change scales only when `service_offering` changes, but issue #273 also calls out dynamic scaling when compute-related VM details change (e.g., `details.cpuNumber`, `details.cpuSpeed`, `details.memory`). As written, `details` updates are still handled later via `UpdateVirtualMachine`, which won’t apply CPU/memory scaling; consider detecting those detail key changes and invoking `ScaleVirtualMachine` (with `details` populated) even when the service offering name/id itself is unchanged.
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -681,24 +681,24 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
- // Check if the service offering is changed and if so, update the offering
+ // Check if the service offering is changed and if so, scale the VM
if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ log.Printf("[DEBUG] Service offering changed for %s, starting scale", name)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ // Create a new parameter struct for scaling
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
+ // Scale the VM to the new service offering
+ _, err = cs.VirtualMachine.ScaleVirtualMachine(p)
Review Comment:
Current acceptance coverage for instance resize appears to assert only that `service_offering` / `Serviceofferingname` changes (e.g., `resource_cloudstack_instance_test.go:testAccCheckCloudStackInstanceRenamedAndResized`), which would have passed with the previous `ChangeServiceForVirtualMachine` call as well. To prevent regressions, consider extending the update test to assert the VM’s actual CPU/memory values (or another observable effect) after the service offering update so it specifically validates `ScaleVirtualMachine` behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "sudo87 (via GitHub)" <gi...@apache.org>.
sudo87 commented on PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#issuecomment-5323647627
The panic/nil-safety fixes look good, thanks. But the core issue is still open: `d.HasChange("details")` isn't in the outer "requires reboot" condition (line ~692), so changing only `cpuNumber`/`cpuSpeed`/`memory` still skips `ScaleVirtualMachine` and falls through to the old metadata-only `UpdateVirtualMachine` path — this is the exact bug #273 reports, and it's been flagged in the last few review passes. Can `details` be added to that condition? Also, no test covers a `details`-only change, and the CPU/memory assertions (`<= 0`) would pass even without scaling.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#discussion_r3796347629
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -681,24 +681,60 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
- // Check if the service offering is changed and if so, update the offering
+ // Check if the service offering is changed and if so, scale the VM
if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ oldOffering, newOffering := d.GetChange("service_offering")
+ log.Printf("[DEBUG] Service offering changed for %s from %s to %s, starting scale", name, oldOffering, newOffering)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ // Create a new parameter struct for scaling
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
+ // Scale the VM to the new service offering
+ _, err = cs.VirtualMachine.ScaleVirtualMachine(p)
if err != nil {
return fmt.Errorf(
- "Error changing the service offering for instance %s: %s", name, err)
+ "Error scaling instance %s to service offering %s: %s", name, newOffering, err)
+ }
+ }
+
+ // Check if compute-related details have changed and scale the VM
+ if d.HasChange("details") {
+ oldDetails, newDetails := d.GetChange("details")
+ oldDetailsMap := oldDetails.(map[string]interface{})
+ newDetailsMap := newDetails.(map[string]interface{})
Review Comment:
`d.GetChange("details")` can return `nil` for the old/new value (e.g., when the map is added/removed). The direct type assertions to `map[string]interface{}` will panic in that case. Coerce the values safely and treat `nil` as an empty map.
This issue also appears on line 725 of the same file.
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -681,24 +681,60 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
- // Check if the service offering is changed and if so, update the offering
+ // Check if the service offering is changed and if so, scale the VM
if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ oldOffering, newOffering := d.GetChange("service_offering")
+ log.Printf("[DEBUG] Service offering changed for %s from %s to %s, starting scale", name, oldOffering, newOffering)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ // Create a new parameter struct for scaling
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
+ // Scale the VM to the new service offering
+ _, err = cs.VirtualMachine.ScaleVirtualMachine(p)
if err != nil {
return fmt.Errorf(
- "Error changing the service offering for instance %s: %s", name, err)
+ "Error scaling instance %s to service offering %s: %s", name, newOffering, err)
+ }
+ }
+
+ // Check if compute-related details have changed and scale the VM
+ if d.HasChange("details") {
+ oldDetails, newDetails := d.GetChange("details")
+ oldDetailsMap := oldDetails.(map[string]interface{})
+ newDetailsMap := newDetails.(map[string]interface{})
+
+ // Check if any compute-related details changed (cpuNumber, cpuSpeed, memory)
+ computeDetailsChanged := false
+ for _, key := range []string{"cpuNumber", "cpuSpeed", "memory"} {
+ if oldDetailsMap[key] != newDetailsMap[key] {
+ computeDetailsChanged = true
+ break
+ }
+ }
+
+ if computeDetailsChanged {
+ log.Printf("[DEBUG] Compute details changed for %s, scaling VM", name)
+
+ // Convert details map for API call
+ detailsForAPI := make(map[string]string)
+ for k, v := range newDetailsMap {
+ detailsForAPI[k] = v.(string)
+ }
+
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), "")
+ p.SetDetails(detailsForAPI)
Review Comment:
This scaling call constructs params with an empty service offering ID (`NewScaleVirtualMachineParams(d.Id(), "")`). In the CloudStack API/client this parameter is required, so this will likely fail validation or behave unexpectedly. Resolve the current service offering ID (or reuse the one from the service_offering change) and pass it into the ScaleVirtualMachine params.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "sudo87 (via GitHub)" <gi...@apache.org>.
sudo87 commented on PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#issuecomment-5315759093
The ScaleVirtualMachine swap for service_offering looks correct, but I don't think this closes [#273](https://github.com/apache/cloudstack-terraform-provider/issues/273). The issue is specifically about the details map (cpuNumber/cpuSpeed/memory) — that update path (resourceCloudStackInstanceUpdate, d.HasChange("details") block) is untouched and still calls plain UpdateVirtualMachine, which only updates metadata without resizing the VM. Can this be extended to call ScaleVirtualMachine there too? Also, no tests were added for either path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix VM scaling: use ScaleVirtualMachine instead of ChangeServiceForVirtualMachine [cloudstack-terraform-provider]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #323:
URL: https://github.com/apache/cloudstack-terraform-provider/pull/323#discussion_r3796757142
##########
cloudstack/resource_cloudstack_instance.go:
##########
@@ -681,24 +681,60 @@ func resourceCloudStackInstanceUpdate(d *schema.ResourceData, meta interface{})
}
- // Check if the service offering is changed and if so, update the offering
+ // Check if the service offering is changed and if so, scale the VM
if d.HasChange("service_offering") {
- log.Printf("[DEBUG] Service offering changed for %s, starting update", name)
+ oldOffering, newOffering := d.GetChange("service_offering")
+ log.Printf("[DEBUG] Service offering changed for %s from %s to %s, starting scale", name, oldOffering, newOffering)
// Retrieve the service_offering ID
serviceofferingid, e := retrieveID(cs, "service_offering", d.Get("service_offering").(string))
if e != nil {
return e.Error()
}
- // Create a new parameter struct
- p := cs.VirtualMachine.NewChangeServiceForVirtualMachineParams(d.Id(), serviceofferingid)
+ // Create a new parameter struct for scaling
+ p := cs.VirtualMachine.NewScaleVirtualMachineParams(d.Id(), serviceofferingid)
- // Change the service offering
- _, err = cs.VirtualMachine.ChangeServiceForVirtualMachine(p)
+ // Scale the VM to the new service offering
+ _, err = cs.VirtualMachine.ScaleVirtualMachine(p)
if err != nil {
return fmt.Errorf(
- "Error changing the service offering for instance %s: %s", name, err)
+ "Error scaling instance %s to service offering %s: %s", name, newOffering, err)
+ }
+ }
+
+ // Check if compute-related details have changed and scale the VM
+ if d.HasChange("details") {
+ oldDetails, newDetails := d.GetChange("details")
+ oldDetailsMap := oldDetails.(map[string]interface{})
+ newDetailsMap := newDetails.(map[string]interface{})
+
+ // Check if any compute-related details changed (cpuNumber, cpuSpeed, memory)
+ computeDetailsChanged := false
+ for _, key := range []string{"cpuNumber", "cpuSpeed", "memory"} {
+ if oldDetailsMap[key] != newDetailsMap[key] {
+ computeDetailsChanged = true
+ break
+ }
+ }
+
+ if computeDetailsChanged {
+ log.Printf("[DEBUG] Compute details changed for %s, scaling VM", name)
+
+ // Convert details map for API call
+ detailsForAPI := make(map[string]string)
+ for k, v := range newDetailsMap {
+ detailsForAPI[k] = v.(string)
+ }
Review Comment:
Casting detail values with `v.(string)` can panic when the user supplies numeric values (e.g., `memory = 2048`) or when a key is removed (nil). For API calls, stringifying is safer and matches the existing API expectation of `map[string]string`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@cloudstack.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org