Skip to content

Commit 87fd5cf

Browse files
authored
Merge pull request #44431 from hashicorp/td-tfresource.Options-use-internal/retry
Technical debt: Use `internal/retry.StateChangeConf` with `tfresource.Options`
2 parents 033da72 + f070a06 commit 87fd5cf

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

internal/service/rds/cluster_instance.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"github.com/aws/aws-sdk-go-v2/service/rds"
1616
"github.com/aws/aws-sdk-go-v2/service/rds/types"
1717
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
18-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1918
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2019
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2120
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2221
"github.com/hashicorp/terraform-provider-aws/internal/create"
2322
"github.com/hashicorp/terraform-provider-aws/internal/errs"
2423
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
24+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
2525
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
2626
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2727
"github.com/hashicorp/terraform-provider-aws/internal/verify"
@@ -593,7 +593,7 @@ func waitDBClusterInstanceAvailable(ctx context.Context, conn *rds.Client, id st
593593
instanceStatusUpgrading,
594594
},
595595
Target: []string{instanceStatusAvailable, instanceStatusStorageOptimization},
596-
Refresh: statusDBInstance(ctx, conn, id),
596+
Refresh: statusDBInstance(conn, id),
597597
Timeout: timeout,
598598
MinTimeout: 10 * time.Second,
599599
Delay: 30 * time.Second,
@@ -617,7 +617,7 @@ func waitDBClusterInstanceDeleted(ctx context.Context, conn *rds.Client, id stri
617617
instanceStatusModifying,
618618
},
619619
Target: []string{},
620-
Refresh: statusDBInstance(ctx, conn, id),
620+
Refresh: statusDBInstance(conn, id),
621621
Timeout: timeout,
622622
MinTimeout: 10 * time.Second,
623623
Delay: 30 * time.Second,

internal/service/rds/instance.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"github.com/hashicorp/terraform-plugin-log/tflog"
2424
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2525
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
26-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
26+
sdkretry "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
2727
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2828
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2929
"github.com/hashicorp/terraform-provider-aws/internal/conns"
@@ -32,6 +32,7 @@ import (
3232
"github.com/hashicorp/terraform-provider-aws/internal/errs"
3333
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
3434
"github.com/hashicorp/terraform-provider-aws/internal/flex"
35+
"github.com/hashicorp/terraform-provider-aws/internal/retry"
3536
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
3637
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
3738
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
@@ -2851,7 +2852,7 @@ func findDBInstances(ctx context.Context, conn *rds.Client, input *rds.DescribeD
28512852
page, err := pages.NextPage(ctx, optFns...)
28522853

28532854
if errs.IsA[*types.DBInstanceNotFoundFault](err) {
2854-
return nil, &retry.NotFoundError{
2855+
return nil, &sdkretry.NotFoundError{
28552856
LastError: err,
28562857
LastRequest: input,
28572858
}
@@ -2871,8 +2872,8 @@ func findDBInstances(ctx context.Context, conn *rds.Client, input *rds.DescribeD
28712872
return output, nil
28722873
}
28732874

2874-
func statusDBInstance(ctx context.Context, conn *rds.Client, id string, optFns ...func(*rds.Options)) retry.StateRefreshFunc {
2875-
return func() (any, string, error) {
2875+
func statusDBInstance(conn *rds.Client, id string, optFns ...func(*rds.Options)) retry.StateRefreshFunc {
2876+
return func(ctx context.Context) (any, string, error) {
28762877
output, err := findDBInstanceByID(ctx, conn, id, optFns...)
28772878

28782879
if tfresource.NotFound(err) {
@@ -2916,7 +2917,7 @@ func waitDBInstanceAvailable(ctx context.Context, conn *rds.Client, id string, t
29162917
instanceStatusUpgrading,
29172918
},
29182919
Target: []string{instanceStatusAvailable, instanceStatusStorageOptimization},
2919-
Refresh: statusDBInstance(ctx, conn, id),
2920+
Refresh: statusDBInstance(conn, id),
29202921
Timeout: timeout,
29212922
}
29222923
options.Apply(stateConf)
@@ -2950,7 +2951,7 @@ func waitDBInstanceStopped(ctx context.Context, conn *rds.Client, id string, tim
29502951
instanceStatusUpgrading,
29512952
},
29522953
Target: []string{instanceStatusStopped},
2953-
Refresh: statusDBInstance(ctx, conn, id),
2954+
Refresh: statusDBInstance(conn, id),
29542955
Timeout: timeout,
29552956
ContinuousTargetOccurence: 2,
29562957
Delay: 10 * time.Second,
@@ -2994,7 +2995,7 @@ func waitDBInstanceDeleted(ctx context.Context, conn *rds.Client, id string, tim
29942995
instanceStatusStorageOptimization,
29952996
},
29962997
Target: []string{},
2997-
Refresh: statusDBInstance(ctx, conn, id),
2998+
Refresh: statusDBInstance(conn, id),
29982999
Timeout: timeout,
29993000
}
30003001
options.Apply(stateConf)
@@ -3021,7 +3022,7 @@ func findBlueGreenDeploymentByID(ctx context.Context, conn *rds.Client, id strin
30213022

30223023
// Eventual consistency check.
30233024
if aws.ToString(output.BlueGreenDeploymentIdentifier) != id {
3024-
return nil, &retry.NotFoundError{
3025+
return nil, &sdkretry.NotFoundError{
30253026
LastRequest: input,
30263027
}
30273028
}
@@ -3047,7 +3048,7 @@ func findBlueGreenDeployments(ctx context.Context, conn *rds.Client, input *rds.
30473048
page, err := pages.NextPage(ctx)
30483049

30493050
if errs.IsA[*types.BlueGreenDeploymentNotFoundFault](err) {
3050-
return nil, &retry.NotFoundError{
3051+
return nil, &sdkretry.NotFoundError{
30513052
LastError: err,
30523053
LastRequest: input,
30533054
}
@@ -3067,8 +3068,8 @@ func findBlueGreenDeployments(ctx context.Context, conn *rds.Client, input *rds.
30673068
return output, nil
30683069
}
30693070

3070-
func statusBlueGreenDeployment(ctx context.Context, conn *rds.Client, id string) retry.StateRefreshFunc {
3071-
return func() (any, string, error) {
3071+
func statusBlueGreenDeployment(conn *rds.Client, id string) retry.StateRefreshFunc {
3072+
return func(ctx context.Context) (any, string, error) {
30723073
output, err := findBlueGreenDeploymentByID(ctx, conn, id)
30733074

30743075
if tfresource.NotFound(err) {
@@ -3094,7 +3095,7 @@ func waitBlueGreenDeploymentAvailable(ctx context.Context, conn *rds.Client, id
30943095
stateConf := &retry.StateChangeConf{
30953096
Pending: []string{"PROVISIONING"},
30963097
Target: []string{"AVAILABLE"},
3097-
Refresh: statusBlueGreenDeployment(ctx, conn, id),
3098+
Refresh: statusBlueGreenDeployment(conn, id),
30983099
Timeout: timeout,
30993100
}
31003101
options.Apply(stateConf)
@@ -3120,7 +3121,7 @@ func waitBlueGreenDeploymentSwitchoverCompleted(ctx context.Context, conn *rds.C
31203121
stateConf := &retry.StateChangeConf{
31213122
Pending: []string{"AVAILABLE", "SWITCHOVER_IN_PROGRESS"},
31223123
Target: []string{"SWITCHOVER_COMPLETED"},
3123-
Refresh: statusBlueGreenDeployment(ctx, conn, id),
3124+
Refresh: statusBlueGreenDeployment(conn, id),
31243125
Timeout: timeout,
31253126
}
31263127
options.Apply(stateConf)
@@ -3150,7 +3151,7 @@ func waitBlueGreenDeploymentDeleted(ctx context.Context, conn *rds.Client, id st
31503151
stateConf := &retry.StateChangeConf{
31513152
Pending: []string{"PROVISIONING", "AVAILABLE", "SWITCHOVER_IN_PROGRESS", "SWITCHOVER_COMPLETED", "INVALID_CONFIGURATION", "SWITCHOVER_FAILED", "DELETING"},
31523153
Target: []string{},
3153-
Refresh: statusBlueGreenDeployment(ctx, conn, id),
3154+
Refresh: statusBlueGreenDeployment(conn, id),
31543155
Timeout: timeout,
31553156
}
31563157
options.Apply(stateConf)

internal/service/rds/instance_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3065,7 +3065,6 @@ func TestAccRDSInstance_ReplicateSourceDB_mssqlDomain(t *testing.T) {
30653065
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
30663066
sourceResourceName := "aws_db_instance.source"
30673067
resourceName := "aws_db_instance.test"
3068-
30693068
domain := acctest.RandomDomain().String()
30703069

30713070
resource.ParallelTest(t, resource.TestCase{
@@ -11112,11 +11111,10 @@ resource "aws_security_group_rule" "test" {
1111211111
}
1111311112

1111411113
resource "aws_directory_service_directory" "directory" {
11115-
name = %[2]q
11116-
password_wo = ephemeral.aws_secretsmanager_random_password.test.random_password
11117-
password_wo_version = 1
11118-
type = "MicrosoftAD"
11119-
edition = "Standard"
11114+
name = %[2]q
11115+
password = "SuperSecretPassw0rd"
11116+
type = "MicrosoftAD"
11117+
edition = "Standard"
1112011118

1112111119
vpc_settings {
1112211120
vpc_id = aws_vpc.test.id

internal/tfresource/retry.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"time"
1111

1212
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
13-
sdkretry "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1413
"github.com/hashicorp/terraform-provider-aws/internal/backoff"
1514
"github.com/hashicorp/terraform-provider-aws/internal/errs"
1615
"github.com/hashicorp/terraform-provider-aws/internal/retry"
@@ -158,7 +157,7 @@ type Options struct {
158157
ContinuousTargetOccurence int // Number of times the Target state has to occur continuously
159158
}
160159

161-
func (o Options) Apply(c *sdkretry.StateChangeConf) {
160+
func (o Options) Apply(c *retry.StateChangeConf) {
162161
if o.Delay > 0 {
163162
c.Delay = o.Delay
164163
}

internal/tfresource/retry_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"testing"
1212
"time"
1313

14-
sdkretry "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1514
"github.com/hashicorp/terraform-provider-aws/internal/retry"
1615
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
1716
)
@@ -479,7 +478,7 @@ func TestOptionsApply(t *testing.T) {
479478
t.Run(name, func(t *testing.T) {
480479
t.Parallel()
481480

482-
conf := sdkretry.StateChangeConf{}
481+
conf := retry.StateChangeConf{}
483482

484483
testCase.options.Apply(&conf)
485484

0 commit comments

Comments
 (0)