From 10f0f9ab77aaa3392c24c66208ec82d6e2444f66 Mon Sep 17 00:00:00 2001 From: Anna Lushnikova Date: Tue, 5 Nov 2024 09:44:28 -0500 Subject: [PATCH] update godo --- digitalocean/droplet/resource_droplet.go | 12 +++--- digitalocean/droplet/resource_droplet_test.go | 4 +- go.mod | 2 +- go.sum | 4 +- .../digitalocean/godo/droplet_actions.go | 37 +++++++++++++++++-- .../github.com/digitalocean/godo/droplets.go | 2 +- vendor/modules.txt | 2 +- 7 files changed, 47 insertions(+), 16 deletions(-) diff --git a/digitalocean/droplet/resource_droplet.go b/digitalocean/droplet/resource_droplet.go index c764d118e..c636aa92e 100644 --- a/digitalocean/droplet/resource_droplet.go +++ b/digitalocean/droplet/resource_droplet.go @@ -391,7 +391,7 @@ func resourceDigitalOceanDropletCreate(ctx context.Context, d *schema.ResourceDa if !ok { return diag.FromErr(errors.New("backup_policy hour is not an int")) } - opts.BackupPolicy.Hour = hour + opts.BackupPolicy.Hour = &hour } } @@ -653,22 +653,22 @@ func resourceDigitalOceanDropletUpdate(ctx context.Context, d *schema.ResourceDa } if d.HasChange("backup_policy") { - var newPolicy map[string]interface{} + var newPolicy godo.DropletBackupPolicyRequest bp, ok := d.GetOk("backup_policy") if ok && bp != nil { // backup_policy must be set. _, new := d.GetChange("backup_policy") if newList, ok := new.([]interface{}); ok && len(newList) != 0 { - newPolicy = new.([]interface{})[0].(map[string]interface{}) + newPolicy = new.([]interface{})[0].(godo.DropletBackupPolicyRequest) } - action, _, err := client.DropletActions.EnableBackupsWithPolicy(context.Background(), id, newPolicy) + action, _, err := client.DropletActions.ChangeBackupPolicy(context.Background(), id, &newPolicy) if err != nil { return diag.Errorf( - "Error enabling backups with policy on droplet (%s): %s", d.Id(), err) + "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 backups to be enabled with policy for droplet (%s): %s", d.Id(), err) + return diag.Errorf("Error waiting for backup policy to be changed for droplet (%s): %s", d.Id(), err) } } } diff --git a/digitalocean/droplet/resource_droplet_test.go b/digitalocean/droplet/resource_droplet_test.go index 813535b17..80130ca2e 100644 --- a/digitalocean/droplet/resource_droplet_test.go +++ b/digitalocean/droplet/resource_droplet_test.go @@ -487,7 +487,7 @@ func TestAccDigitalOceanDroplet_ChangeBackupPolicy(t *testing.T) { CheckDestroy: acceptance.TestAccCheckDigitalOceanDropletDestroy, Steps: []resource.TestStep{ { - Config: testAccCheckDigitalOceanDropletConfig_EnableBackupsWithPolicy(name), + Config: testAccCheckDigitalOceanDropletConfig_ChangeBackupPolicy(name), Check: resource.ComposeTestCheckFunc( acceptance.TestAccCheckDigitalOceanDropletExists("digitalocean_droplet.foobar", &droplet), resource.TestCheckResourceAttr( @@ -1053,7 +1053,7 @@ resource "digitalocean_droplet" "foobar" { }`, name, defaultSize, defaultImage) } -func testAccCheckDigitalOceanDropletConfig_EnableBackupsWithPolicy(name string) string { +func testAccCheckDigitalOceanDropletConfig_ChangeBackupPolicy(name string) string { return fmt.Sprintf(` resource "digitalocean_droplet" "foobar" { name = "%s" diff --git a/go.mod b/go.mod index 2b5a02e68..ab4300cfb 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean require ( github.com/aws/aws-sdk-go v1.42.18 - github.com/digitalocean/godo v1.128.1-0.20241101193706-e886602c9e0c + github.com/digitalocean/godo v1.128.1-0.20241105142035-a379869c286c github.com/hashicorp/awspolicyequivalence v1.5.0 github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320 github.com/hashicorp/go-uuid v1.0.3 diff --git a/go.sum b/go.sum index 30b03a293..5817dd108 100644 --- a/go.sum +++ b/go.sum @@ -25,8 +25,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/digitalocean/godo v1.128.1-0.20241101193706-e886602c9e0c h1:701F+MG+3bwyBCEez9q8OKpgQ9fmkOVPrXTRIoI/MZI= -github.com/digitalocean/godo v1.128.1-0.20241101193706-e886602c9e0c/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc= +github.com/digitalocean/godo v1.128.1-0.20241105142035-a379869c286c h1:Z1Osn3VmAR5FtPgrdi2VTxa069CnKc/DCXX1U2qpNpM= +github.com/digitalocean/godo v1.128.1-0.20241105142035-a379869c286c/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= diff --git a/vendor/github.com/digitalocean/godo/droplet_actions.go b/vendor/github.com/digitalocean/godo/droplet_actions.go index ba5019ed3..ed0f583c9 100644 --- a/vendor/github.com/digitalocean/godo/droplet_actions.go +++ b/vendor/github.com/digitalocean/godo/droplet_actions.go @@ -30,7 +30,8 @@ type DropletActionsService interface { SnapshotByTag(context.Context, string, string) ([]Action, *Response, error) EnableBackups(context.Context, int) (*Action, *Response, error) EnableBackupsByTag(context.Context, string) ([]Action, *Response, error) - EnableBackupsWithPolicy(context.Context, int, map[string]interface{}) (*Action, *Response, error) + EnableBackupsWithPolicy(context.Context, int, *DropletBackupPolicyRequest) (*Action, *Response, error) + ChangeBackupPolicy(context.Context, int, *DropletBackupPolicyRequest) (*Action, *Response, error) DisableBackups(context.Context, int) (*Action, *Response, error) DisableBackupsByTag(context.Context, string) ([]Action, *Response, error) PasswordReset(context.Context, int) (*Action, *Response, error) @@ -171,8 +172,38 @@ func (s *DropletActionsServiceOp) EnableBackupsByTag(ctx context.Context, tag st } // EnableBackupsWithPolicy enables droplet's backup with a backup policy applied. -func (s *DropletActionsServiceOp) EnableBackupsWithPolicy(ctx context.Context, id int, policy map[string]interface{}) (*Action, *Response, error) { - request := &ActionRequest{"type": "change_backup_policy", "backup_policy": policy} +func (s *DropletActionsServiceOp) EnableBackupsWithPolicy(ctx context.Context, id int, policy *DropletBackupPolicyRequest) (*Action, *Response, error) { + if policy == nil { + return nil, nil, NewArgError("policy", "policy can't be nil") + } + + policyMap := map[string]interface{}{ + "plan": policy.Plan, + "weekday": policy.Weekday, + } + if policy.Hour != nil { + policyMap["hour"] = policy.Hour + } + + request := &ActionRequest{"type": "enable_backups", "backup_policy": policyMap} + return s.doAction(ctx, id, request) +} + +// ChangeBackupPolicy updates a backup policy when backups are enabled. +func (s *DropletActionsServiceOp) ChangeBackupPolicy(ctx context.Context, id int, policy *DropletBackupPolicyRequest) (*Action, *Response, error) { + if policy == nil { + return nil, nil, NewArgError("policy", "policy can't be nil") + } + + policyMap := map[string]interface{}{ + "plan": policy.Plan, + "weekday": policy.Weekday, + } + if policy.Hour != nil { + policyMap["hour"] = policy.Hour + } + + request := &ActionRequest{"type": "change_backup_policy", "backup_policy": policyMap} return s.doAction(ctx, id, request) } diff --git a/vendor/github.com/digitalocean/godo/droplets.go b/vendor/github.com/digitalocean/godo/droplets.go index 0366da7ab..2ddd7d6b7 100644 --- a/vendor/github.com/digitalocean/godo/droplets.go +++ b/vendor/github.com/digitalocean/godo/droplets.go @@ -260,7 +260,7 @@ type DropletMultiCreateRequest struct { type DropletBackupPolicyRequest struct { Plan string `json:"plan,omitempty"` Weekday string `json:"weekday,omitempty"` - Hour int `json:"hour"` // Avoid using omitempty to ensure zero values are included in the JSON output. + Hour *int `json:"hour,omitempty"` } func (d DropletCreateRequest) String() string { diff --git a/vendor/modules.txt b/vendor/modules.txt index 34ae1e286..eace93273 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -58,7 +58,7 @@ github.com/aws/aws-sdk-go/service/sts/stsiface # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/digitalocean/godo v1.128.1-0.20241101193706-e886602c9e0c +# github.com/digitalocean/godo v1.128.1-0.20241105142035-a379869c286c ## explicit; go 1.22 github.com/digitalocean/godo github.com/digitalocean/godo/metrics