Skip to content

Commit

Permalink
dms: Migrate to AWS SDK v2
Browse files Browse the repository at this point in the history
  • Loading branch information
mattburgess committed May 30, 2024
1 parent 106be6c commit 5aed8f9
Show file tree
Hide file tree
Showing 30 changed files with 955 additions and 1,014 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ require (
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7 // indirect
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.38.8 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.9 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.8 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.8 h1:XVlsnRZ4kZ98E
github.com/aws/aws-sdk-go-v2/service/costoptimizationhub v1.4.8/go.mod h1:dD0mbm64tfE2DRlIVEKg0dXb9qyf+qZtNitsR8CvMVM=
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.8 h1:BvsWFUlh8VBYhXgBs7gbeNcw4JfhZAkWW/7D3l7pBP0=
github.com/aws/aws-sdk-go-v2/service/customerprofiles v1.36.8/go.mod h1:yIWo4Up9onICLJevCusWbIxXU2n+oXQppg+idBufjWM=
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.38.8 h1:NzIt3rr0vr24K6G22AgV9dRlgk8A/8UL7iUxPKk0KRU=
github.com/aws/aws-sdk-go-v2/service/databasemigrationservice v1.38.8/go.mod h1:vWHsM18ZKqVgj2Vy0zt20fxmfC+0JN1XiLSdiMcVHoU=
github.com/aws/aws-sdk-go-v2/service/datasync v1.38.2 h1:n6QlscDIxkYGE2jteCMYXK/rK/jM6XbZ+Wd7s7Ev7Wo=
github.com/aws/aws-sdk-go-v2/service/datasync v1.38.2/go.mod h1:DZzNE9VYDGOLbfUltCiM4SwJA3D92qyMT2+7N/KDIso=
github.com/aws/aws-sdk-go-v2/service/datazone v1.8.4 h1:IbBQebbyGS5vdbp0ufmv8T+nD+Wnsl4CCt1rzpjod5o=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

68 changes: 32 additions & 36 deletions internal/service/dms/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"log"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
dms "github.com/aws/aws-sdk-go/service/databasemigrationservice"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/aws/aws-sdk-go-v2/aws"
dms "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice"
awstypes "github.com/aws/aws-sdk-go-v2/service/databasemigrationservice/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-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
itypes "github.com/hashicorp/terraform-provider-aws/internal/types"
Expand Down Expand Up @@ -77,7 +79,7 @@ func ResourceCertificate() *schema.Resource {

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

certificateID := d.Get("certificate_id").(string)
input := &dms.ImportCertificateInput{
Expand All @@ -97,7 +99,7 @@ func resourceCertificateCreate(ctx context.Context, d *schema.ResourceData, meta
input.CertificateWallet = v
}

_, err := conn.ImportCertificateWithContext(ctx, input)
_, err := conn.ImportCertificate(ctx, input)

if err != nil {
return sdkdiag.AppendErrorf(diags, "creating DMS Certificate (%s): %s", certificateID, err)
Expand All @@ -110,7 +112,7 @@ func resourceCertificateCreate(ctx context.Context, d *schema.ResourceData, meta

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

certificate, err := FindCertificateByID(ctx, conn, d.Id())

Expand Down Expand Up @@ -139,14 +141,14 @@ func resourceCertificateUpdate(ctx context.Context, d *schema.ResourceData, meta

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

log.Printf("[DEBUG] Deleting DMS Certificate: %s", d.Id())
_, err := conn.DeleteCertificateWithContext(ctx, &dms.DeleteCertificateInput{
_, err := conn.DeleteCertificate(ctx, &dms.DeleteCertificateInput{
CertificateArn: aws.String(d.Get(names.AttrCertificateARN).(string)),
})

if tfawserr.ErrCodeEquals(err, dms.ErrCodeResourceNotFoundFault) {
if errs.IsA[*awstypes.ResourceNotFoundFault](err) {
return diags
}

Expand All @@ -157,34 +159,34 @@ func resourceCertificateDelete(ctx context.Context, d *schema.ResourceData, meta
return diags
}

func resourceCertificateSetState(d *schema.ResourceData, cert *dms.Certificate) {
d.SetId(aws.StringValue(cert.CertificateIdentifier))
func resourceCertificateSetState(d *schema.ResourceData, cert *awstypes.Certificate) {
d.SetId(aws.ToString(cert.CertificateIdentifier))

d.Set("certificate_id", cert.CertificateIdentifier)
d.Set(names.AttrCertificateARN, cert.CertificateArn)

if aws.StringValue(cert.CertificatePem) != "" {
if aws.ToString(cert.CertificatePem) != "" {
d.Set("certificate_pem", cert.CertificatePem)
}
if cert.CertificateWallet != nil && len(cert.CertificateWallet) != 0 {
d.Set("certificate_wallet", itypes.Base64EncodeOnce(cert.CertificateWallet))
}
}

func FindCertificateByID(ctx context.Context, conn *dms.DatabaseMigrationService, id string) (*dms.Certificate, error) {
func FindCertificateByID(ctx context.Context, conn *dms.Client, id string) (*awstypes.Certificate, error) {
input := &dms.DescribeCertificatesInput{
Filters: []*dms.Filter{
Filters: []awstypes.Filter{
{
Name: aws.String("certificate-id"),
Values: []*string{aws.String(id)},
Values: []string{id},
},
},
}

return findCertificate(ctx, conn, input)
}

func findCertificate(ctx context.Context, conn *dms.DatabaseMigrationService, input *dms.DescribeCertificatesInput) (*dms.Certificate, error) {
func findCertificate(ctx context.Context, conn *dms.Client, input *dms.DescribeCertificatesInput) (*awstypes.Certificate, error) {
output, err := findCertificates(ctx, conn, input)

if err != nil {
Expand All @@ -194,33 +196,27 @@ func findCertificate(ctx context.Context, conn *dms.DatabaseMigrationService, in
return tfresource.AssertSinglePtrResult(output)
}

func findCertificates(ctx context.Context, conn *dms.DatabaseMigrationService, input *dms.DescribeCertificatesInput) ([]*dms.Certificate, error) {
var output []*dms.Certificate
func findCertificates(ctx context.Context, conn *dms.Client, input *dms.DescribeCertificatesInput) ([]*awstypes.Certificate, error) {
var output []awstypes.Certificate

err := conn.DescribeCertificatesPagesWithContext(ctx, input, func(page *dms.DescribeCertificatesOutput, lastPage bool) bool {
if page == nil {
return !lastPage
}
pages := dms.NewDescribeCertificatesPaginator(conn, input)

for pages.HasMorePages() {
page, err := pages.NextPage(ctx)

for _, v := range page.Certificates {
if v != nil {
output = append(output, v)
if errs.IsA[*awstypes.ResourceNotFoundFault](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
}
}

return !lastPage
})

if tfawserr.ErrCodeEquals(err, dms.ErrCodeResourceNotFoundFault) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
if err != nil {
return nil, err
}
}

if err != nil {
return nil, err
output = append(output, page.Certificates...)
}

return output, nil
return tfslices.ToPointers(output), nil
}
8 changes: 4 additions & 4 deletions internal/service/dms/certificate_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -79,7 +79,7 @@ func DataSourceCertificate() *schema.Resource {

func dataSourceCertificateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).DMSConn(ctx)
conn := meta.(*conns.AWSClient).DMSClient(ctx)
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

Expand All @@ -90,8 +90,8 @@ func dataSourceCertificateRead(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "reading DMS Certificate (%s): %s", certificateID, err)
}

d.SetId(aws.StringValue(out.CertificateIdentifier))
arn := aws.StringValue(out.CertificateArn)
d.SetId(aws.ToString(out.CertificateIdentifier))
arn := aws.ToString(out.CertificateArn)
d.Set(names.AttrCertificateARN, arn)
d.Set("certificate_id", out.CertificateIdentifier)
d.Set("certificate_pem", out.CertificatePem)
Expand Down
4 changes: 2 additions & 2 deletions internal/service/dms/certificate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func testAccCheckCertificateDestroy(ctx context.Context) resource.TestCheckFunc
continue
}

conn := acctest.Provider.Meta().(*conns.AWSClient).DMSConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).DMSClient(ctx)

_, err := tfdms.FindCertificateByID(ctx, conn, rs.Primary.ID)

Expand All @@ -173,7 +173,7 @@ func testAccCertificateExists(ctx context.Context, n string) resource.TestCheckF
return fmt.Errorf("Not found: %s", n)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).DMSConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).DMSClient(ctx)

_, err := tfdms.FindCertificateByID(ctx, conn, rs.Primary.ID)

Expand Down
Loading

0 comments on commit 5aed8f9

Please sign in to comment.