Skip to content

Commit

Permalink
Allow updating Hostname
Browse files Browse the repository at this point in the history
  • Loading branch information
uzaxirr committed Jun 19, 2024
1 parent 69adb21 commit 4a63050
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions civo/instances/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func ResourceInstance() *schema.Resource {
Optional: true,
Computed: true,
Description: "A fully qualified domain name that should be set as the instance's hostname",
ForceNew: true,
ValidateFunc: utils.ValidateNameSize,
},
"reverse_dns": {
Expand Down Expand Up @@ -365,7 +364,7 @@ func resourceInstanceRead(_ context.Context, d *schema.ResourceData, m interface
d.Set("initial_password", resp.InitialPassword)
d.Set("source_type", resp.SourceType)
d.Set("source_id", resp.SourceID)
d.Set("sshkey_id", resp.SSHKey)
d.Set("sshkey_id", resp.SSHKeyID)
d.Set("tags", resp.Tags)
d.Set("private_ip", resp.PrivateIP)
d.Set("public_ip", resp.PublicIP)
Expand Down Expand Up @@ -431,25 +430,32 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
}
}

// if has note we add to the instance
if d.HasChange("notes") {
// if notes or hostname have changed, add them to the instance
if d.HasChange("notes") || d.HasChange("hostname") {
notes := d.Get("notes").(string)
hostname := d.Get("hostname").(string)

instance, err := apiClient.GetInstance(d.Id())
if err != nil {
// check if the instance no longer exists.
return diag.Errorf("[ERR] instance %s not found", d.Id())
}

instance.Notes = notes
if d.HasChange("notes") {
instance.Notes = notes
}
if d.HasChange("hostname") {
instance.Hostname = hostname
}

log.Printf("[INFO] adding notes to the instance %s", d.Id())
log.Printf("[INFO] updating instance %s", d.Id())
_, err = apiClient.UpdateInstance(instance)
if err != nil {
return diag.Errorf("[ERR] an error occurred while adding a note to the instance %s", d.Id())
return diag.Errorf("[ERR] an error occurred while updating notes or hostname of the instance %s", d.Id())
}
}

// if a firewall is declare we update the instance
// if a firewall is declared we update the instance
if d.HasChange("firewall_id") {
firewallID := d.Get("firewall_id").(string)

Expand Down

0 comments on commit 4a63050

Please sign in to comment.