Skip to content

Commit

Permalink
Switch resource state change to use retry package (#456)
Browse files Browse the repository at this point in the history
* Bare metal
* Block storage
* Database
* Instance
* ISO
* Kubernetes
* Object storage
* Snapshot
  • Loading branch information
OpenGLShaders authored Feb 22, 2024
1 parent 948d8e0 commit afa6484
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 36 deletions.
6 changes: 3 additions & 3 deletions vultr/resource_vultr_bare_metal_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vultr/govultr/v3"
)
Expand Down Expand Up @@ -461,7 +461,7 @@ func bareMetalServerOSCheck(options map[string]bool) (string, error) {
func waitForBareMetalServerActiveStatus(ctx context.Context, d *schema.ResourceData, meta interface{}) (interface{}, error) {
log.Printf("[INFO] Waiting for bare metal server (%s) to have status of active", d.Id())

stateConf := &resource.StateChangeConf{ //nolint:all
stateConf := &retry.StateChangeConf{ //nolint:all
Pending: []string{"pending"},
Target: []string{"active"},
Refresh: newBareMetalServerStatusStateRefresh(ctx, d, meta),
Expand All @@ -475,7 +475,7 @@ func waitForBareMetalServerActiveStatus(ctx context.Context, d *schema.ResourceD
return stateConf.WaitForStateContext(ctx)
}

func newBareMetalServerStatusStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc { //nolint:all
func newBareMetalServerStatusStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}) retry.StateRefreshFunc { //nolint:all
client := meta.(*Client).govultrClient()

return func() (interface{}, string, error) {
Expand Down
6 changes: 3 additions & 3 deletions vultr/resource_vultr_block_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/vultr/govultr/v3"
Expand Down Expand Up @@ -248,7 +248,7 @@ func waitForBlockAvailable(ctx context.Context, d *schema.ResourceData, target s
"[INFO] Waiting for Server (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ //nolint:all
stateConf := &retry.StateChangeConf{ //nolint:all
Pending: pending,
Target: []string{target},
Refresh: newBlockStateRefresh(ctx, d, meta, attribute),
Expand All @@ -261,7 +261,7 @@ func waitForBlockAvailable(ctx context.Context, d *schema.ResourceData, target s
return stateConf.WaitForStateContext(ctx)
}

func newBlockStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { //nolint:all
func newBlockStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { //nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {

Expand Down
6 changes: 3 additions & 3 deletions vultr/resource_vultr_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/vultr/govultr/v3"
Expand Down Expand Up @@ -590,7 +590,7 @@ func waitForDatabaseAvailable(ctx context.Context, d *schema.ResourceData, targe
"[INFO] Waiting for Managed Database (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newDatabaseStateRefresh(ctx, d, meta, attribute),
Expand All @@ -603,7 +603,7 @@ func waitForDatabaseAvailable(ctx context.Context, d *schema.ResourceData, targe
return stateConf.WaitForStateContext(ctx)
}

func newDatabaseStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newDatabaseStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {
log.Printf("[INFO] Creating Database")
Expand Down
10 changes: 5 additions & 5 deletions vultr/resource_vultr_database_replica.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vultr/govultr/v3"
)
Expand Down Expand Up @@ -279,7 +279,7 @@ func waitForDatabaseReplicaAvailable(ctx context.Context, d *schema.ResourceData
"[INFO] Waiting for Managed Database read replica (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newDatabaseReplicaStateRefresh(ctx, d, meta, attribute),
Expand All @@ -292,7 +292,7 @@ func waitForDatabaseReplicaAvailable(ctx context.Context, d *schema.ResourceData
return stateConf.WaitForStateContext(ctx)
}

func newDatabaseReplicaStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newDatabaseReplicaStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {
log.Printf("[INFO] Creating Database read replica")
Expand All @@ -316,7 +316,7 @@ func waitForParentBackupAvailable(ctx context.Context, d *schema.ResourceData, t
"[INFO] Waiting for parent Managed Database (%s) to have %s of %s",
d.Get("database_id").(string), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: parentDatabaseRefresh(ctx, d, meta, attribute),
Expand All @@ -329,7 +329,7 @@ func waitForParentBackupAvailable(ctx context.Context, d *schema.ResourceData, t
return stateConf.WaitForStateContext(ctx)
}

func parentDatabaseRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func parentDatabaseRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {
log.Printf("[INFO] Waiting for parent Managed Database backup status")
Expand Down
9 changes: 4 additions & 5 deletions vultr/resource_vultr_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -809,7 +808,7 @@ func waitForServerAvailable(ctx context.Context, d *schema.ResourceData, target
"[INFO] Waiting for Server (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newServerStateRefresh(ctx, d, meta, attribute),
Expand All @@ -822,7 +821,7 @@ func waitForServerAvailable(ctx context.Context, d *schema.ResourceData, target
return stateConf.WaitForStateContext(ctx)
}

func newServerStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newServerStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {

Expand All @@ -849,7 +848,7 @@ func waitForUpgrade(ctx context.Context, d *schema.ResourceData, target string,
"[INFO] Waiting for instance (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newInstancePlanRefresh(ctx, d, meta, attribute),
Expand All @@ -862,7 +861,7 @@ func waitForUpgrade(ctx context.Context, d *schema.ResourceData, target string,
return stateConf.WaitForStateContext(ctx)
}

func newInstancePlanRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newInstancePlanRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {
log.Printf("[INFO] Upgrading instance")
Expand Down
10 changes: 5 additions & 5 deletions vultr/resource_vultr_iso_private.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/vultr/govultr/v3"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -183,7 +183,7 @@ func waitForIsoAvailable(ctx context.Context, d *schema.ResourceData, target str
"[INFO] Waiting for ISO (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newIsoStateRefresh(ctx, d, meta),
Expand All @@ -198,7 +198,7 @@ func waitForIsoAvailable(ctx context.Context, d *schema.ResourceData, target str
}

func newIsoStateRefresh(ctx context.Context,
d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc { // nolint:all
d *schema.ResourceData, meta interface{}) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()

return func() (interface{}, string, error) {
Expand All @@ -219,7 +219,7 @@ func waitForIsoDetached(ctx context.Context, instanceID string, target string, p
"[INFO] Waiting for ISO to detach from %s",
instanceID)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: isoDetachStateRefresh(ctx, instanceID, meta, attribute),
Expand All @@ -232,7 +232,7 @@ func waitForIsoDetached(ctx context.Context, instanceID string, target string, p
return stateConf.WaitForStateContext(ctx)
}

func isoDetachStateRefresh(ctx context.Context, instanceID string, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func isoDetachStateRefresh(ctx context.Context, instanceID string, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {

Expand Down
6 changes: 3 additions & 3 deletions vultr/resource_vultr_kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vultr/govultr/v3"
)
Expand Down Expand Up @@ -342,7 +342,7 @@ func waitForVKEAvailable(ctx context.Context, d *schema.ResourceData, target str
"[INFO] Waiting for kubernetes cluster (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newVKEStateRefresh(ctx, d, meta, attribute),
Expand All @@ -355,7 +355,7 @@ func waitForVKEAvailable(ctx context.Context, d *schema.ResourceData, target str
return stateConf.WaitForStateContext(ctx)
}

func newVKEStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newVKEStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {

Expand Down
6 changes: 3 additions & 3 deletions vultr/resource_vultr_kubernetes_nodepools.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vultr/govultr/v3"
)
Expand Down Expand Up @@ -159,7 +159,7 @@ func waitForNodePoolAvailable(ctx context.Context, d *schema.ResourceData, targe
"[INFO] Waiting for node pool (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newNodePoolStateRefresh(ctx, d, meta, attribute),
Expand All @@ -172,7 +172,7 @@ func waitForNodePoolAvailable(ctx context.Context, d *schema.ResourceData, targe
return stateConf.WaitForStateContext(ctx)
}

func newNodePoolStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newNodePoolStateRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {

Expand Down
6 changes: 3 additions & 3 deletions vultr/resource_vultr_object_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

Expand Down Expand Up @@ -153,7 +153,7 @@ func waitForObjAvailable(ctx context.Context, d *schema.ResourceData, target str
"[INFO] Waiting for Object Storage (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newServerObjRefresh(ctx, d, meta, attribute),
Expand All @@ -166,7 +166,7 @@ func waitForObjAvailable(ctx context.Context, d *schema.ResourceData, target str
return stateConf.WaitForStateContext(ctx)
}

func newServerObjRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) resource.StateRefreshFunc { // nolint:all
func newServerObjRefresh(ctx context.Context, d *schema.ResourceData, meta interface{}, attr string) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {
log.Printf("[INFO] Creating Object Storage")
Expand Down
6 changes: 3 additions & 3 deletions vultr/resource_vultr_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/vultr/govultr/v3"
)
Expand Down Expand Up @@ -135,7 +135,7 @@ func waitForSnapshot(ctx context.Context, d *schema.ResourceData, target string,
"[INFO] Waiting for Snapshot (%s) to have %s of %s",
d.Id(), attribute, target)

stateConf := &resource.StateChangeConf{ // nolint:all
stateConf := &retry.StateChangeConf{ // nolint:all
Pending: pending,
Target: []string{target},
Refresh: newSnapStateRefresh(d, meta),
Expand All @@ -148,7 +148,7 @@ func waitForSnapshot(ctx context.Context, d *schema.ResourceData, target string,
return stateConf.WaitForStateContext(ctx)
}

func newSnapStateRefresh(d *schema.ResourceData, meta interface{}) resource.StateRefreshFunc { // nolint:all
func newSnapStateRefresh(d *schema.ResourceData, meta interface{}) retry.StateRefreshFunc { // nolint:all
client := meta.(*Client).govultrClient()
return func() (interface{}, string, error) {

Expand Down

0 comments on commit afa6484

Please sign in to comment.