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

Refact update methods #96

Merged
merged 2 commits into from
Feb 24, 2021
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
2 changes: 1 addition & 1 deletion opennebula/resource_opennebula_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func resourceOpennebulaImageUpdate(d *schema.ResourceData, meta interface{}) err
}
}

return nil
return resourceOpennebulaImageRead(d, meta)
}

func resourceOpennebulaImageDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
10 changes: 1 addition & 9 deletions opennebula/resource_opennebula_security_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,6 @@ func resourceOpennebulaSecurityGroupCreate(d *schema.ResourceData, meta interfac

func resourceOpennebulaSecurityGroupUpdate(d *schema.ResourceData, meta interface{}) error {

// Enable partial state mode
d.Partial(true)

//Get Security Group
sgc, err := getSecurityGroupController(d, meta)
if err != nil {
Expand Down Expand Up @@ -420,7 +417,6 @@ func resourceOpennebulaSecurityGroupUpdate(d *schema.ResourceData, meta interfac
return err
}
}
d.SetPartial("permissions")
log.Printf("[INFO] Successfully updated Permissions Security Group %s\n", securitygroup.Name)
}

Expand All @@ -432,11 +428,7 @@ func resourceOpennebulaSecurityGroupUpdate(d *schema.ResourceData, meta interfac
log.Printf("[INFO] Successfully updated group for Security Group %s\n", securitygroup.Name)
}

// We succeeded, disable partial mode. This causes Terraform to save
// save all fields again.
d.Partial(false)

return nil
return resourceOpennebulaSecurityGroupRead(d, meta)
}

func resourceOpennebulaSecurityGroupDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
19 changes: 1 addition & 18 deletions opennebula/resource_opennebula_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ func resourceOpennebulaServiceExists(d *schema.ResourceData, meta interface{}) (
func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) error {
controller := meta.(*goca.Controller)

// Enable partial state mode
d.Partial(true)

//Get Service controller
sc, err := getServiceController(d, meta)
if err != nil {
Expand All @@ -319,7 +316,6 @@ func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) e
}

service, err := sc.Info()
d.SetPartial("name")
log.Printf("[INFO] Successfully updated name (%s) for Service ID %x\n", service.Name, service.ID)
}

Expand All @@ -330,7 +326,6 @@ func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) e
return err
}
}
d.SetPartial("permissions")
log.Printf("[INFO] Successfully updated Permissions for Service %s\n", service.Name)
}

Expand All @@ -345,8 +340,6 @@ func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) e
}

d.Set("gname", group.Name)
d.SetPartial("gname")
d.SetPartial("gid")
log.Printf("[INFO] Successfully updated group for Service %s\n", service.Name)
} else if d.HasChange("gname") {
gid, err := controller.Groups().ByName(d.Get("gname").(string))
Expand All @@ -359,8 +352,6 @@ func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) e
}

d.Set("gid", gid)
d.SetPartial("gid")
d.SetPartial("gname")
log.Printf("[INFO] Successfully updated group for Service %s\n", service.Name)
}

Expand All @@ -375,8 +366,6 @@ func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) e
}

d.Set("uname", user.Name)
d.SetPartial("uname")
d.SetPartial("uid")
log.Printf("[INFO] Successfully updated owner for Service %s\n", service.Name)
} else if d.HasChange("uname") {
uid, err := controller.Users().ByName(d.Get("uname").(string))
Expand All @@ -389,16 +378,10 @@ func resourceOpennebulaServiceUpdate(d *schema.ResourceData, meta interface{}) e
}

d.Set("uid", uid)
d.SetPartial("uid")
d.SetPartial("uname")
log.Printf("[INFO] Successfully updated owner for Service %s\n", service.Name)
}

// We succeeded, disable partial mode. This causes Terraform to save
// save all fields again.
d.Partial(false)

return nil
return resourceOpennebulaServiceRead(d, meta)
}

// Helpers
Expand Down
19 changes: 1 addition & 18 deletions opennebula/resource_opennebula_service_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,6 @@ func resourceOpennebulaServiceTemplateExists(d *schema.ResourceData, meta interf
func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interface{}) error {
controller := meta.(*goca.Controller)

// Enable partial state mode
d.Partial(true)

//Get Service controller
stc, err := getServiceTemplateController(d, meta)
if err != nil {
Expand All @@ -230,7 +227,6 @@ func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interf
}

stemplate, err := stc.Info()
d.SetPartial("name")
log.Printf("[INFO] Successfully updated name (%s) for service template ID %x\n", stemplate.Name, stemplate.ID)
}

Expand All @@ -241,7 +237,6 @@ func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interf
return err
}
}
d.SetPartial("permissions")
log.Printf("[INFO] Successfully updated Permissions for service template %s\n", stemplate.Name)
}

Expand All @@ -256,8 +251,6 @@ func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interf
}

d.Set("gname", group.Name)
d.SetPartial("gname")
d.SetPartial("gid")
log.Printf("[INFO] Successfully updated group for service template %s\n", stemplate.Name)
} else if d.HasChange("gname") {
gid, err := controller.Groups().ByName(d.Get("gname").(string))
Expand All @@ -270,8 +263,6 @@ func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interf
}

d.Set("gid", gid)
d.SetPartial("gid")
d.SetPartial("gname")
log.Printf("[INFO] Successfully updated group for service template %s\n", stemplate.Name)
}

Expand All @@ -286,8 +277,6 @@ func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interf
}

d.Set("uname", user.Name)
d.SetPartial("uname")
d.SetPartial("uid")
log.Printf("[INFO] Successfully updated owner for service template %s\n", stemplate.Name)
} else if d.HasChange("uname") {
uid, err := controller.Users().ByName(d.Get("uname").(string))
Expand All @@ -300,16 +289,10 @@ func resourceOpennebulaServiceTemplateUpdate(d *schema.ResourceData, meta interf
}

d.Set("uid", uid)
d.SetPartial("uid")
d.SetPartial("uname")
log.Printf("[INFO] Successfully updated owner for service template %s\n", stemplate.Name)
}

// We succeeded, disable partial mode. This causes Terraform to save
// save all fields again.
d.Partial(false)

return nil
return resourceOpennebulaServiceTemplateRead(d, meta)
}

// Helpers
Expand Down
2 changes: 1 addition & 1 deletion opennebula/resource_opennebula_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func resourceOpennebulaTemplateUpdate(d *schema.ResourceData, meta interface{})
}
}

return nil
return resourceOpennebulaTemplateRead(d, meta)
}

func resourceOpennebulaTemplateDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion opennebula/resource_opennebula_template_vm_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ func resourceOpennebulaVMGroupUpdate(d *schema.ResourceData, meta interface{}) e
log.Printf("[INFO] Successfully updated Virtual Machine Group %s\n", d.Id())
}

return nil
return resourceOpennebulaVMGroupRead(d, meta)
}

func resourceOpennebulaVMGroupDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down
2 changes: 1 addition & 1 deletion opennebula/resource_opennebula_virtual_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ func resourceOpennebulaVirtualNetworkUpdate(d *schema.ResourceData, meta interfa
}
}

return nil
return resourceOpennebulaVirtualNetworkRead(d, meta)
}

func resourceOpennebulaVirtualNetworkDelete(d *schema.ResourceData, meta interface{}) error {
Expand Down