Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tech debt: Migrate swf resources to AWS SDK for Go v2 #31776

Merged
merged 8 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/ssm v1.36.4
github.com/aws/aws-sdk-go-v2/service/ssmcontacts v1.15.4
github.com/aws/aws-sdk-go-v2/service/ssmincidents v1.21.4
github.com/aws/aws-sdk-go-v2/service/swf v1.15.0
github.com/aws/aws-sdk-go-v2/service/transcribe v1.26.6
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.0.5
github.com/aws/aws-sdk-go-v2/service/xray v1.16.11
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 h1:PkHIIJs8qvq0e5QybnZoG1K
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10/go.mod h1:AFvkxc8xfBe8XA+5St5XIHHrQQtkxqrRincx4hmMHOk=
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 h1:2DQLAKDteoEDI8zpCzqBMaZlJuoE9iTYD0gFmXVax9E=
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0/go.mod h1:BgQOMsg8av8jset59jelyPW7NoZcZXLVpDsXunGDrk8=
github.com/aws/aws-sdk-go-v2/service/swf v1.15.0 h1:ZcQ8IYzUhmiVZ7lV4E0lttk+Tei/RZk/Oko8+G34cWI=
github.com/aws/aws-sdk-go-v2/service/swf v1.15.0/go.mod h1:p5K3luEySutRPjMsXcmoc9dumbUus6ZOj4XBYC3XMII=
github.com/aws/aws-sdk-go-v2/service/transcribe v1.26.6 h1:I2Y2Y8V+uq2ZoD+yTxjKYuPOTtScHMXUWdbuCdjNZy4=
github.com/aws/aws-sdk-go-v2/service/transcribe v1.26.6/go.mod h1:VgAk4W80KzgqmBdm1jk+FjqiD5VgAz0FGvqECq7q79I=
github.com/aws/aws-sdk-go-v2/service/vpclattice v1.0.5 h1:ZQizySv5AeKbYYtkDiUcxSnwTqAJ4URIxdoLWfZ7rhw=
Expand Down
8 changes: 4 additions & 4 deletions internal/conns/awsclient_gen.go

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

8 changes: 6 additions & 2 deletions internal/conns/config_gen.go

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

53 changes: 29 additions & 24 deletions internal/service/swf/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import (
"log"
"strconv"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/swf"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/swf"
"github.com/aws/aws-sdk-go-v2/service/swf/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/create"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand All @@ -22,7 +24,7 @@ import (

// @SDKResource("aws_swf_domain", name="Domain")
// @Tags(identifierAttribute="arn")
func ResourceDomain() *schema.Resource {
func resourceDomain() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceDomainCreate,
ReadWithoutTimeout: resourceDomainRead,
Expand Down Expand Up @@ -79,7 +81,8 @@ func ResourceDomain() *schema.Resource {
}

func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).SWFConn()
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SWFClient()

name := create.Name(d.Get("name").(string), d.Get("name_prefix").(string))
input := &swf.RegisterDomainInput{
Expand All @@ -92,10 +95,10 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
input.Description = aws.String(v.(string))
}

_, err := conn.RegisterDomainWithContext(ctx, input)
_, err := conn.RegisterDomain(ctx, input)

if err != nil {
return diag.Errorf("creating SWF Domain (%s): %s", name, err)
return sdkdiag.AppendErrorf(diags, "creating SWF Domain (%s): %s", name, err)
}

d.SetId(name)
Expand All @@ -104,9 +107,10 @@ func resourceDomainCreate(ctx context.Context, d *schema.ResourceData, meta inte
}

func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).SWFConn()
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SWFClient()

output, err := FindDomainByName(ctx, conn, d.Id())
output, err := findDomainByName(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] SWF Domain (%s) not found, removing from state", d.Id())
Expand All @@ -115,17 +119,17 @@ func resourceDomainRead(ctx context.Context, d *schema.ResourceData, meta interf
}

if err != nil {
return diag.Errorf("reading SWF Domain (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "reading SWF Domain (%s): %s", d.Id(), err)
}

arn := aws.StringValue(output.DomainInfo.Arn)
arn := aws.ToString(output.DomainInfo.Arn)
d.Set("arn", arn)
d.Set("description", output.DomainInfo.Description)
d.Set("name", output.DomainInfo.Name)
d.Set("name_prefix", create.NamePrefixFromName(aws.StringValue(output.DomainInfo.Name)))
d.Set("name_prefix", create.NamePrefixFromName(aws.ToString(output.DomainInfo.Name)))
d.Set("workflow_execution_retention_period_in_days", output.Configuration.WorkflowExecutionRetentionPeriodInDays)

return nil
return diags
}

func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand All @@ -134,31 +138,32 @@ func resourceDomainUpdate(ctx context.Context, d *schema.ResourceData, meta inte
}

func resourceDomainDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).SWFConn()
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).SWFClient()

_, err := conn.DeprecateDomainWithContext(ctx, &swf.DeprecateDomainInput{
_, err := conn.DeprecateDomain(ctx, &swf.DeprecateDomainInput{
Name: aws.String(d.Get("name").(string)),
})

if tfawserr.ErrCodeEquals(err, swf.ErrCodeDomainDeprecatedFault, swf.ErrCodeUnknownResourceFault) {
return nil
if errs.IsA[*types.DomainDeprecatedFault](err) || errs.IsA[*types.UnknownResourceFault](err) {
return diags
}

if err != nil {
return diag.Errorf("deleting SWF Domain (%s): %s", d.Id(), err)
return sdkdiag.AppendErrorf(diags, "deleting SWF Domain (%s): %s", d.Id(), err)
}

return nil
return diags
}

func FindDomainByName(ctx context.Context, conn *swf.SWF, name string) (*swf.DescribeDomainOutput, error) {
func findDomainByName(ctx context.Context, conn *swf.Client, name string) (*swf.DescribeDomainOutput, error) {
input := &swf.DescribeDomainInput{
Name: aws.String(name),
}

output, err := conn.DescribeDomainWithContext(ctx, input)
output, err := conn.DescribeDomain(ctx, input)

if tfawserr.ErrCodeEquals(err, swf.ErrCodeUnknownResourceFault) {
if errs.IsA[*types.UnknownResourceFault](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
Expand All @@ -173,9 +178,9 @@ func FindDomainByName(ctx context.Context, conn *swf.SWF, name string) (*swf.Des
return nil, tfresource.NewEmptyResultError(input)
}

if status := aws.StringValue(output.DomainInfo.Status); status == swf.RegistrationStatusDeprecated {
if status := output.DomainInfo.Status; status == types.RegistrationStatusDeprecated {
return nil, &retry.NotFoundError{
Message: status,
Message: string(status),
LastRequest: input,
}
}
Expand Down
57 changes: 36 additions & 21 deletions internal/service/swf/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import (
"testing"
"time"

"github.com/aws/aws-sdk-go/service/swf"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfswf "github.com/hashicorp/terraform-provider-aws/internal/service/swf"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

func testAccPreCheckDomainTestingEnabled(t *testing.T) {
Expand All @@ -39,7 +38,7 @@ func TestAccSWFDomain_basic(t *testing.T) {
acctest.PreCheck(ctx, t)
testAccPreCheckDomainTestingEnabled(t)
},
ErrorCheck: acctest.ErrorCheck(t, swf.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.SWFEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -64,6 +63,32 @@ func TestAccSWFDomain_basic(t *testing.T) {
})
}

func TestAccSWFDomain_disappears(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_swf_domain.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
testAccPreCheckDomainTestingEnabled(t)
},
ErrorCheck: acctest.ErrorCheck(t, names.SWFEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccDomainConfig_basic(rName),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckDomainExists(ctx, resourceName),
acctest.CheckResourceDisappears(ctx, acctest.Provider, tfswf.ResourceDomain(), resourceName),
),
ExpectNonEmptyPlan: true,
},
},
})
}

func TestAccSWFDomain_nameGenerated(t *testing.T) {
ctx := acctest.Context(t)
resourceName := "aws_swf_domain.test"
Expand All @@ -73,7 +98,7 @@ func TestAccSWFDomain_nameGenerated(t *testing.T) {
acctest.PreCheck(ctx, t)
testAccPreCheckDomainTestingEnabled(t)
},
ErrorCheck: acctest.ErrorCheck(t, swf.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.SWFEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -103,7 +128,7 @@ func TestAccSWFDomain_namePrefix(t *testing.T) {
acctest.PreCheck(ctx, t)
testAccPreCheckDomainTestingEnabled(t)
},
ErrorCheck: acctest.ErrorCheck(t, swf.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.SWFEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -134,7 +159,7 @@ func TestAccSWFDomain_tags(t *testing.T) {
acctest.PreCheck(ctx, t)
testAccPreCheckDomainTestingEnabled(t)
},
ErrorCheck: acctest.ErrorCheck(t, swf.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.SWFEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -182,7 +207,7 @@ func TestAccSWFDomain_description(t *testing.T) {
acctest.PreCheck(ctx, t)
testAccPreCheckDomainTestingEnabled(t)
},
ErrorCheck: acctest.ErrorCheck(t, swf.EndpointsID),
ErrorCheck: acctest.ErrorCheck(t, names.SWFEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckDomainDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -204,26 +229,16 @@ func TestAccSWFDomain_description(t *testing.T) {

func testAccCheckDomainDestroy(ctx context.Context) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acctest.Provider.Meta().(*conns.AWSClient).SWFConn()
conn := acctest.Provider.Meta().(*conns.AWSClient).SWFClient()

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_swf_domain" {
continue
}

// Retrying as Read after Delete is not always consistent.
err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError {
_, err := tfswf.FindDomainByName(ctx, conn, rs.Primary.ID)

if tfresource.NotFound(err) {
return nil
}

if err != nil {
return retry.NonRetryableError(err)
}

return retry.RetryableError(fmt.Errorf("SWF Domain still exists: %s", rs.Primary.ID))
_, err := tfresource.RetryUntilNotFound(ctx, 2*time.Minute, func() (interface{}, error) {
return tfswf.FindDomainByName(ctx, conn, rs.Primary.ID)
})

return err
Expand All @@ -244,7 +259,7 @@ func testAccCheckDomainExists(ctx context.Context, n string) resource.TestCheckF
return fmt.Errorf("No SWF Domain ID is set")
}

conn := acctest.Provider.Meta().(*conns.AWSClient).SWFConn()
conn := acctest.Provider.Meta().(*conns.AWSClient).SWFClient()

_, err := tfswf.FindDomainByName(ctx, conn, rs.Primary.ID)

Expand Down
8 changes: 8 additions & 0 deletions internal/service/swf/exports_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package swf

// Exports for use in tests only.
var (
FindDomainByName = findDomainByName

ResourceDomain = resourceDomain
)
2 changes: 1 addition & 1 deletion internal/service/swf/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate go run ../../generate/tags/main.go -ListTags -ServiceTagsSlice -TagType=ResourceTag -UpdateTags
//go:generate go run ../../generate/tags/main.go -AWSSDKVersion=2 -ListTags -ServiceTagsSlice -TagType=ResourceTag -UpdateTags
// ONLY generate directives and package declaration! Do not add anything else to this file.

package swf
2 changes: 1 addition & 1 deletion internal/service/swf/service_package_gen.go

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

Loading