Skip to content

Commit

Permalink
chore: migrating servicecatalog to aws-sdk-v2 go
Browse files Browse the repository at this point in the history
  • Loading branch information
bschaatsbergen committed Feb 29, 2024
1 parent c71d8ec commit 6d8029d
Show file tree
Hide file tree
Showing 47 changed files with 728 additions and 680 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.28.1
github.com/aws/aws-sdk-go-v2/service/securityhub v1.46.1
github.com/aws/aws-sdk-go-v2/service/securitylake v1.12.1
github.com/aws/aws-sdk-go-v2/service/servicecatalog v1.28.1
github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry v1.26.1
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.1
github.com/aws/aws-sdk-go-v2/service/sesv2 v1.26.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@ github.com/aws/aws-sdk-go-v2/service/securityhub v1.46.1 h1:CUson/hpTaec48tUCTEg
github.com/aws/aws-sdk-go-v2/service/securityhub v1.46.1/go.mod h1:hFXlWyDLL1Ievsv3pAwkJqzONiR85iGysUIWvxBEwmk=
github.com/aws/aws-sdk-go-v2/service/securitylake v1.12.1 h1:a/mL3NLHcBh7wURStJeRVbtciozEtR216qz2AoeOFBk=
github.com/aws/aws-sdk-go-v2/service/securitylake v1.12.1/go.mod h1:fgRd6X93zDcfeYrHKpjvo3X7ldsgYVoJbMq8JhufF0w=
github.com/aws/aws-sdk-go-v2/service/servicecatalog v1.28.1 h1:BoRDIpHBVt6uzg+//PvB/xJJHNi1v/c2hDO4ny9jCvA=
github.com/aws/aws-sdk-go-v2/service/servicecatalog v1.28.1/go.mod h1:YuQ2m2Re0mGbzCJCoifqOq/BMw8oB4/wQoMlbsIGJ64=
github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry v1.26.1 h1:4YbfYPoo1jAcAuSleWtORagDvRekoTlFKTeCa7+YPj8=
github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry v1.26.1/go.mod h1:PkxHhIOe6pN44wsGNLg7ILyNZ7n6NepiJXFCbOt3ecc=
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.21.1 h1:CCd+AWX79LVGzTXkgW9fBaPRFiC+J67zGuMcsER8Q1g=
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.

23 changes: 12 additions & 11 deletions internal/service/servicecatalog/budget_resource_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"context"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/servicecatalog"
"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/servicecatalog"
"github.com/aws/aws-sdk-go-v2/service/servicecatalog/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/errs"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
)
Expand Down Expand Up @@ -51,7 +52,7 @@ func ResourceBudgetResourceAssociation() *schema.Resource {

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

input := &servicecatalog.AssociateBudgetWithResourceInput{
BudgetName: aws.String(d.Get("budget_name").(string)),
Expand All @@ -62,9 +63,9 @@ func resourceBudgetResourceAssociationCreate(ctx context.Context, d *schema.Reso
err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError {
var err error

output, err = conn.AssociateBudgetWithResourceWithContext(ctx, input)
output, err = conn.AssociateBudgetWithResource(ctx, input)

if tfawserr.ErrMessageContains(err, servicecatalog.ErrCodeInvalidParametersException, "profile does not exist") {
if errs.Contains(err, "profile does not exist") {
return retry.RetryableError(err)
}

Expand All @@ -76,7 +77,7 @@ func resourceBudgetResourceAssociationCreate(ctx context.Context, d *schema.Reso
})

if tfresource.TimedOut(err) {
output, err = conn.AssociateBudgetWithResourceWithContext(ctx, input)
output, err = conn.AssociateBudgetWithResource(ctx, input)
}

if err != nil {
Expand All @@ -94,7 +95,7 @@ func resourceBudgetResourceAssociationCreate(ctx context.Context, d *schema.Reso

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

budgetName, resourceID, err := BudgetResourceAssociationParseID(d.Id())

Expand Down Expand Up @@ -126,7 +127,7 @@ func resourceBudgetResourceAssociationRead(ctx context.Context, d *schema.Resour

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

budgetName, resourceID, err := BudgetResourceAssociationParseID(d.Id())

Expand All @@ -139,9 +140,9 @@ func resourceBudgetResourceAssociationDelete(ctx context.Context, d *schema.Reso
BudgetName: aws.String(budgetName),
}

_, err = conn.DisassociateBudgetFromResourceWithContext(ctx, input)
_, err = conn.DisassociateBudgetFromResource(ctx, input)

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
if errs.IsA[*types.ResourceNotFoundException](err) {
return diags
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/service/servicecatalog"
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"
tfservicecatalog "github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalog"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

// add sweeper to delete known test servicecat budget resource associations
Expand All @@ -27,7 +27,7 @@ func TestAccServiceCatalogBudgetResourceAssociation_basic(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, "budgets") },
ErrorCheck: acctest.ErrorCheck(t, servicecatalog.EndpointsID, "budgets"),
ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogEndpointID, "budgets"),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckBudgetResourceAssociationDestroy(ctx),
Steps: []resource.TestStep{
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestAccServiceCatalogBudgetResourceAssociation_disappears(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, "budgets") },
ErrorCheck: acctest.ErrorCheck(t, servicecatalog.EndpointsID, "budgets"),
ErrorCheck: acctest.ErrorCheck(t, names.ServiceCatalogEndpointID, "budgets"),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckBudgetResourceAssociationDestroy(ctx),
Steps: []resource.TestStep{
Expand All @@ -73,7 +73,7 @@ func TestAccServiceCatalogBudgetResourceAssociation_disappears(t *testing.T) {

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

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_servicecatalog_budget_resource_association" {
Expand Down Expand Up @@ -115,7 +115,7 @@ func testAccCheckBudgetResourceAssociationExists(ctx context.Context, resourceNa
return fmt.Errorf("could not parse ID (%s): %w", rs.Primary.ID, err)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).ServiceCatalogConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).ServiceCatalogClient(ctx)

_, err = tfservicecatalog.WaitBudgetResourceAssociationReady(ctx, conn, budgetName, resourceID, tfservicecatalog.BudgetResourceAssociationReadyTimeout)

Expand Down
35 changes: 18 additions & 17 deletions internal/service/servicecatalog/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"context"
"log"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/servicecatalog"
"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/servicecatalog"
"github.com/aws/aws-sdk-go-v2/service/servicecatalog/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"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"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
Expand Down Expand Up @@ -87,7 +88,7 @@ func ResourceConstraint() *schema.Resource {

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

input := &servicecatalog.CreateConstraintInput{
IdempotencyToken: aws.String(id.UniqueId()),
Expand All @@ -109,13 +110,13 @@ func resourceConstraintCreate(ctx context.Context, d *schema.ResourceData, meta
err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutCreate), func() *retry.RetryError {
var err error

output, err = conn.CreateConstraintWithContext(ctx, input)
output, err = conn.CreateConstraint(ctx, input)

if tfawserr.ErrMessageContains(err, servicecatalog.ErrCodeInvalidParametersException, "profile does not exist") {
if errs.Contains(err, "profile does not exist") {
return retry.RetryableError(err)
}

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
if errs.IsA[*types.ResourceNotFoundException](err) {
return retry.RetryableError(err)
}

Expand All @@ -127,7 +128,7 @@ func resourceConstraintCreate(ctx context.Context, d *schema.ResourceData, meta
})

if tfresource.TimedOut(err) {
output, err = conn.CreateConstraintWithContext(ctx, input)
output, err = conn.CreateConstraint(ctx, input)
}

if err != nil {
Expand All @@ -138,14 +139,14 @@ func resourceConstraintCreate(ctx context.Context, d *schema.ResourceData, meta
return sdkdiag.AppendErrorf(diags, "creating Service Catalog Constraint: empty response")
}

d.SetId(aws.StringValue(output.ConstraintDetail.ConstraintId))
d.SetId(aws.ToString(output.ConstraintDetail.ConstraintId))

return append(diags, resourceConstraintRead(ctx, d, meta)...)
}

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

output, err := WaitConstraintReady(ctx, conn, d.Get("accept_language").(string), d.Id(), d.Timeout(schema.TimeoutRead))

Expand Down Expand Up @@ -187,7 +188,7 @@ func resourceConstraintRead(ctx context.Context, d *schema.ResourceData, meta in

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

input := &servicecatalog.UpdateConstraintInput{
Id: aws.String(d.Id()),
Expand All @@ -206,9 +207,9 @@ func resourceConstraintUpdate(ctx context.Context, d *schema.ResourceData, meta
}

err := retry.RetryContext(ctx, d.Timeout(schema.TimeoutUpdate), func() *retry.RetryError {
_, err := conn.UpdateConstraintWithContext(ctx, input)
_, err := conn.UpdateConstraint(ctx, input)

if tfawserr.ErrMessageContains(err, servicecatalog.ErrCodeInvalidParametersException, "profile does not exist") {
if errs.Contains(err, "profile does not exist") {
return retry.RetryableError(err)
}

Expand All @@ -220,7 +221,7 @@ func resourceConstraintUpdate(ctx context.Context, d *schema.ResourceData, meta
})

if tfresource.TimedOut(err) {
_, err = conn.UpdateConstraintWithContext(ctx, input)
_, err = conn.UpdateConstraint(ctx, input)
}

if err != nil {
Expand All @@ -232,7 +233,7 @@ func resourceConstraintUpdate(ctx context.Context, d *schema.ResourceData, meta

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

input := &servicecatalog.DeleteConstraintInput{
Id: aws.String(d.Id()),
Expand All @@ -242,9 +243,9 @@ func resourceConstraintDelete(ctx context.Context, d *schema.ResourceData, meta
input.AcceptLanguage = aws.String(v.(string))
}

_, err := conn.DeleteConstraintWithContext(ctx, input)
_, err := conn.DeleteConstraint(ctx, input)

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
if errs.IsA[*types.ResourceNotFoundException](err) {
return diags
}

Expand Down
6 changes: 3 additions & 3 deletions internal/service/servicecatalog/constraint_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package servicecatalog
import (
"context"

"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 @@ -69,7 +69,7 @@ func DataSourceConstraint() *schema.Resource {

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

output, err := WaitConstraintReady(ctx, conn, d.Get("accept_language").(string), d.Get("id").(string), d.Timeout(schema.TimeoutRead))

Expand Down Expand Up @@ -100,7 +100,7 @@ func dataSourceConstraintRead(ctx context.Context, d *schema.ResourceData, meta
d.Set("product_id", detail.ProductId)
d.Set("type", detail.Type)

d.SetId(aws.StringValue(detail.ConstraintId))
d.SetId(aws.ToString(detail.ConstraintId))

return diags
}
17 changes: 9 additions & 8 deletions internal/service/servicecatalog/constraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import (
"fmt"
"testing"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/servicecatalog"
"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/servicecatalog"
"github.com/aws/aws-sdk-go-v2/service/servicecatalog/types"
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"
"github.com/hashicorp/terraform-provider-aws/internal/errs"
tfservicecatalog "github.com/hashicorp/terraform-provider-aws/internal/service/servicecatalog"
"github.com/hashicorp/terraform-provider-aws/names"
)
Expand Down Expand Up @@ -109,7 +110,7 @@ func TestAccServiceCatalogConstraint_update(t *testing.T) {

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

for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_servicecatalog_constraint" {
Expand All @@ -120,9 +121,9 @@ func testAccCheckConstraintDestroy(ctx context.Context) resource.TestCheckFunc {
Id: aws.String(rs.Primary.ID),
}

output, err := conn.DescribeConstraintWithContext(ctx, input)
output, err := conn.DescribeConstraint(ctx, input)

if tfawserr.ErrCodeEquals(err, servicecatalog.ErrCodeResourceNotFoundException) {
if errs.IsA[*types.ResourceNotFoundException](err) {
continue
}

Expand All @@ -147,13 +148,13 @@ func testAccCheckConstraintExists(ctx context.Context, resourceName string) reso
return fmt.Errorf("resource not found: %s", resourceName)
}

conn := acctest.Provider.Meta().(*conns.AWSClient).ServiceCatalogConn(ctx)
conn := acctest.Provider.Meta().(*conns.AWSClient).ServiceCatalogClient(ctx)

input := &servicecatalog.DescribeConstraintInput{
Id: aws.String(rs.Primary.ID),
}

_, err := conn.DescribeConstraintWithContext(ctx, input)
_, err := conn.DescribeConstraint(ctx, input)

if err != nil {
return fmt.Errorf("error describing Service Catalog Constraint (%s): %w", rs.Primary.ID, err)
Expand Down
Loading

0 comments on commit 6d8029d

Please sign in to comment.