in cloudstack/resource_cloudstack_network_offering.go [85:174]
func resourceCloudStackNetworkOfferingUpdate(d *schema.ResourceData, meta interface{}) error {
cs := meta.(*cloudstack.CloudStackClient)
d.Partial(true)
name := d.Get("name").(string)
// Check if the name is changed and if so, update the network offering
if d.HasChange("name") {
log.Printf("[DEBUG] Name changed for %s, starting update", name)
// Create a new parameter struct
p := cs.NetworkOffering.NewUpdateNetworkOfferingParams()
// Set the new name
p.SetName(d.Get("name").(string))
// Update the name
_, err := cs.NetworkOffering.UpdateNetworkOffering(p)
if err != nil {
return fmt.Errorf(
"Error updating the name for network offering %s: %s", name, err)
}
d.SetPartial("name")
}
// Check if the display text is changed and if so, update the virtual machine
if d.HasChange("display_text") {
log.Printf("[DEBUG] Display text changed for %s, starting update", name)
// Create a new parameter struct
p := cs.NetworkOffering.NewUpdateNetworkOfferingParams()
// Set the new display text
p.SetName(d.Get("display_text").(string))
// Update the display text
_, err := cs.NetworkOffering.UpdateNetworkOffering(p)
if err != nil {
return fmt.Errorf(
"Error updating the display text for network offering %s: %s", name, err)
}
d.SetPartial("display_text")
}
// Check if the guest ip type is changed and if so, update the virtual machine
if d.HasChange("guest_ip_type") {
log.Printf("[DEBUG] Guest ip type changed for %s, starting update", name)
// Create a new parameter struct
p := cs.NetworkOffering.NewUpdateNetworkOfferingParams()
// Set the new guest ip type
p.SetName(d.Get("guest_ip_type").(string))
// Update the guest ip type
_, err := cs.NetworkOffering.UpdateNetworkOffering(p)
if err != nil {
return fmt.Errorf(
"Error updating the guest ip type for network offering %s: %s", name, err)
}
d.SetPartial("guest_ip_type")
}
// Check if the traffic type is changed and if so, update the virtual machine
if d.HasChange("traffic_type") {
log.Printf("[DEBUG] Traffic type changed for %s, starting update", name)
// Create a new parameter struct
p := cs.NetworkOffering.NewUpdateNetworkOfferingParams()
// Set the new traffic type
p.SetName(d.Get("traffic_type").(string))
// Update the traffic type
_, err := cs.NetworkOffering.UpdateNetworkOffering(p)
if err != nil {
return fmt.Errorf(
"Error updating the traffic type for network offering %s: %s", name, err)
}
d.SetPartial("traffic_type")
}
d.Partial(false)
return resourceCloudStackInstanceRead(d, meta)
}