Skip to content

Commit

Permalink
update godo version with fixes; rewrite getting backup policy on create
Browse files Browse the repository at this point in the history
  • Loading branch information
loosla committed Nov 1, 2024
1 parent 73fca2f commit 7dd569f
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 42 deletions.
59 changes: 28 additions & 31 deletions digitalocean/droplet/resource_droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package droplet

import (
"context"
"errors"
"fmt"
"log"
"net"
Expand Down Expand Up @@ -355,46 +356,42 @@ func resourceDigitalOceanDropletCreate(ctx context.Context, d *schema.ResourceDa

// Get configured backup_policy
if policy, ok := d.GetOk("backup_policy"); ok {
objectList := policy.([]interface{})
for _, rawObject := range objectList {
objectMap, ok := rawObject.(map[string]interface{})
policyList := policy.([]interface{})
for _, rawPolicy := range policyList {
policyMap, ok := rawPolicy.(map[string]interface{})
if !ok {
return diag.FromErr(err)
}

if planValue, exists := objectMap["plan"]; exists {
if plan, ok := planValue.(string); ok {
opts.BackupPolicy.Plan = plan
} else {
log.Println(">>> Error: plan is not a string")
}
} else {
log.Println(">>> Error: plan key does not exist")
planVal, exists := policyMap["plan"]
if !exists {
return diag.FromErr(errors.New("backup_policy plan key does not exist"))
}

if weekdayValue, exists := objectMap["weekday"]; exists {
if weekday, ok := weekdayValue.(string); ok {
fmt.Println("Weekday:", weekday)
opts.BackupPolicy.Weekday = weekday
} else {
log.Println(">>> Error: weekday is not a string")
}
} else {
log.Println(">>> Error: weekday key does not exist")
plan, ok := planVal.(string)
if !ok {
return diag.FromErr(errors.New("backup_policy plan is not a string"))
}
opts.BackupPolicy.Plan = plan

if hourValue, exists := objectMap["hour"]; exists {
if hour, ok := hourValue.(int); ok {
fmt.Println("Hour:", hour)
opts.BackupPolicy.Hour = hour
} else {
log.Println(">>> Error: hour is not a float64")
}
} else {
log.Println(">>> Error: hour key does not exist")
weekdayVal, exists := policyMap["weekday"]
if !exists {
return diag.FromErr(errors.New("backup_policy weekday key does not exist"))
}
weekday, ok := weekdayVal.(string)
if !ok {
return diag.FromErr(errors.New("backup_policy weekday is not a string"))
}
opts.BackupPolicy.Weekday = weekday

log.Println(">>> opts.BackupPolicy: ", opts.BackupPolicy)
hourVal, exists := policyMap["hour"]
if !exists {
return diag.FromErr(errors.New("backup_policy hour key does not exist"))
}
hour, ok := hourVal.(int)
if !ok {
return diag.FromErr(errors.New("backup_policy hour is not an int"))
}
opts.BackupPolicy.Hour = hour
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20241031134431-3a7bfd290da0
github.com/digitalocean/godo v1.128.1-0.20241101193706-e886602c9e0c
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20241031134431-3a7bfd290da0 h1:WlqeI3UYtmkg10jNJYr/JwIfnWMomgIycRmhYqqaLB8=
github.com/digitalocean/godo v1.128.1-0.20241031134431-3a7bfd290da0/go.mod h1:PU8JB6I1XYkQIdHFop8lLAY9ojp6M0XcU0TWaQSxbrc=
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/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=
Expand Down
7 changes: 7 additions & 0 deletions vendor/github.com/digitalocean/godo/droplet_actions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/digitalocean/godo/droplets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/digitalocean/godo/godo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

120 changes: 120 additions & 0 deletions vendor/github.com/digitalocean/godo/registry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.20241031134431-3a7bfd290da0
# github.com/digitalocean/godo v1.128.1-0.20241101193706-e886602c9e0c
## explicit; go 1.22
github.com/digitalocean/godo
github.com/digitalocean/godo/metrics
Expand Down

0 comments on commit 7dd569f

Please sign in to comment.