Skip to content

Commit

Permalink
check backups enabled and run ChangeBackupPolicy only if there is bac…
Browse files Browse the repository at this point in the history
…kup_policy specified
  • Loading branch information
loosla committed Nov 6, 2024
1 parent c5d0d34 commit d35f6e0
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions digitalocean/droplet/resource_droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,24 +652,27 @@ func resourceDigitalOceanDropletUpdate(ctx context.Context, d *schema.ResourceDa
}

if d.HasChange("backup_policy") {
if !d.Get("backups").(bool) {
return diag.FromErr(errDropletBackupPolicy)
}
_, ok := d.GetOk("backup_policy")
if ok {
if !d.Get("backups").(bool) {
return diag.FromErr(errDropletBackupPolicy)
}

_, new := d.GetChange("backup_policy")
newPolicy, err := expandBackupPolicy(new)
if err != nil {
return diag.FromErr(err)
}
_, new := d.GetChange("backup_policy")
newPolicy, err := expandBackupPolicy(new)
if err != nil {
return diag.FromErr(err)
}

action, _, err := client.DropletActions.ChangeBackupPolicy(context.Background(), id, newPolicy)
if err != nil {
return diag.Errorf(
"error changing backup policy on droplet (%s): %s", d.Id(), err)
}
action, _, err := client.DropletActions.ChangeBackupPolicy(context.Background(), id, newPolicy)
if err != nil {
return diag.Errorf(
"error changing backup policy on droplet (%s): %s", d.Id(), err)
}

if err := util.WaitForAction(client, action); err != nil {
return diag.Errorf("error waiting for backup policy to be changed for droplet (%s): %s", d.Id(), err)
if err := util.WaitForAction(client, action); err != nil {
return diag.Errorf("error waiting for backup policy to be changed for droplet (%s): %s", d.Id(), err)
}
}
}

Expand Down

0 comments on commit d35f6e0

Please sign in to comment.