Skip to content

Commit

Permalink
F #300: allow host attributes update
Browse files Browse the repository at this point in the history
  • Loading branch information
treywelsh committed Nov 29, 2022
1 parent 4a4ca11 commit cd7e228
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions opennebula/resource_opennebula_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func resourceOpennebulaHost() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Type of the new host: kvm, qemu, lxd, lxc, firecracker, custom",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) {
value := strings.ToUpper(v.(string))
Expand All @@ -65,11 +66,13 @@ func resourceOpennebulaHost() *schema.Resource {
"virtualization": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Virtualization driver",
},
"information": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Information driver",
},
},
Expand Down Expand Up @@ -393,6 +396,8 @@ func resourceOpennebulaHostRead(ctx context.Context, d *schema.ResourceData, met
func resourceOpennebulaHostUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {

var diags diag.Diagnostics
config := meta.(*Configuration)
controller := config.Controller

hc, err := getHostController(d, meta)
if err != nil {
Expand Down Expand Up @@ -427,6 +432,20 @@ func resourceOpennebulaHostUpdate(ctx context.Context, d *schema.ResourceData, m
log.Printf("[INFO] Successfully updated name for host %s\n", hostInfos.Name)
}

if d.HasChange("cluster_id") {
clusterID := d.Get("cluster_id").(int)

err := controller.Cluster(clusterID).AddHost(hc.ID)
if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "Failed to add host to it's new cluster",
Detail: fmt.Sprintf("host (ID: %s) cluster (ID: %d): %s", d.Id(), clusterID, err),
})
return diags
}
}

update := false
newTpl := hostInfos.Template

Expand Down

0 comments on commit cd7e228

Please sign in to comment.