Skip to content

Commit

Permalink
Merge pull request #36009 from bschaatsbergen/migrate-service-catalog…
Browse files Browse the repository at this point in the history
…-to-v2

Tech debt: Migrate servicecatalog resources to AWS SDK for Go v2
  • Loading branch information
ewbankkit authored Aug 8, 2024
2 parents 5791076 + c43102e commit 0f98773
Show file tree
Hide file tree
Showing 55 changed files with 1,539 additions and 1,528 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/securityhub v1.51.3
github.com/aws/aws-sdk-go-v2/service/securitylake v1.16.3
github.com/aws/aws-sdk-go-v2/service/serverlessapplicationrepository v1.22.3
github.com/aws/aws-sdk-go-v2/service/servicecatalog v1.30.3
github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry v1.28.3
github.com/aws/aws-sdk-go-v2/service/servicediscovery v1.31.3
github.com/aws/aws-sdk-go-v2/service/servicequotas v1.23.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ github.com/aws/aws-sdk-go-v2/service/securitylake v1.16.3 h1:7isk2tSNmVbm2f8epPf
github.com/aws/aws-sdk-go-v2/service/securitylake v1.16.3/go.mod h1:X5rHkguK4jCvFOM74tkme3oLUOaR++APKgwhNcIdOW0=
github.com/aws/aws-sdk-go-v2/service/serverlessapplicationrepository v1.22.3 h1:E4NzUkgPrKmlbC9OxVUEQnTdPRg3MTTiDwmq5dJfH9U=
github.com/aws/aws-sdk-go-v2/service/serverlessapplicationrepository v1.22.3/go.mod h1:/nzQOH+tOGrQVv5QbVN+88HoNYc15s8aKsJmOT9MPJI=
github.com/aws/aws-sdk-go-v2/service/servicecatalog v1.30.3 h1:JwZUGB3DE7Wr+Cp4ak7dkgneOJ0FIjXAle1XqkZmQ1Y=
github.com/aws/aws-sdk-go-v2/service/servicecatalog v1.30.3/go.mod h1:Wfm5srkIuPtidLcAWql6ibqifGEIg28EWK6A14Fei6A=
github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry v1.28.3 h1:l19QC3al5lqQydnJRz1cpduAoL0YoEeSxI5Wb5NUEis=
github.com/aws/aws-sdk-go-v2/service/servicecatalogappregistry v1.28.3/go.mod h1:0Em81iN4ZnER1M0XDirgcbsZK3jNghA0YlY2Xw2BDOQ=
github.com/aws/aws-sdk-go-v2/service/servicediscovery v1.31.3 h1:EthA93BNgTnk36FoI9DCKtv4S0m63WzdGDYlBp/CvHQ=
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.

2 changes: 1 addition & 1 deletion internal/service/servicecatalog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ This area is primarily for AWS provider contributors and maintainers. For inform
* [Find out about contributing](https://hashicorp.github.io/terraform-provider-aws/#contribute) to the AWS provider!
* AWS Provider Docs: [Home](https://registry.terraform.io/providers/hashicorp/aws/latest/docs)
* AWS Provider Docs: [One of the ServiceCatalog resources](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/servicecatalog_budget_resource_association)
* AWS Docs: [AWS SDK for Go ServiceCatalog](https://docs.aws.amazon.com/sdk-for-go/api/service/servicecatalog/)
* Service API Guide: [Service Catalog API Reference](https://docs.aws.amazon.com/servicecatalog/latest/dg/service-catalog-api-overview.html)
37 changes: 19 additions & 18 deletions internal/service/servicecatalog/budget_resource_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,21 @@ 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"
awstypes "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"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_servicecatalog_budget_resource_association")
func ResourceBudgetResourceAssociation() *schema.Resource {
// @SDKResource("aws_servicecatalog_budget_resource_association", name="Budget Resource Association")
func resourceBudgetResourceAssociation() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceBudgetResourceAssociationCreate,
ReadWithoutTimeout: resourceBudgetResourceAssociationRead,
Expand Down Expand Up @@ -52,7 +53,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 @@ -63,9 +64,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.IsAErrorMessageContains[*awstypes.InvalidParametersException](err, "profile does not exist") {
return retry.RetryableError(err)
}

Expand All @@ -77,7 +78,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 @@ -88,22 +89,22 @@ func resourceBudgetResourceAssociationCreate(ctx context.Context, d *schema.Reso
return sdkdiag.AppendErrorf(diags, "creating Service Catalog Budget Resource Association: empty response")
}

d.SetId(BudgetResourceAssociationID(d.Get("budget_name").(string), d.Get(names.AttrResourceID).(string)))
d.SetId(budgetResourceAssociationID(d.Get("budget_name").(string), d.Get(names.AttrResourceID).(string)))

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

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())
budgetName, resourceID, err := budgetResourceAssociationParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "could not parse ID (%s): %s", d.Id(), err)
}

output, err := WaitBudgetResourceAssociationReady(ctx, conn, budgetName, resourceID, d.Timeout(schema.TimeoutRead))
output, err := waitBudgetResourceAssociationReady(ctx, conn, budgetName, resourceID, d.Timeout(schema.TimeoutRead))

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Service Catalog Budget Resource Association (%s) not found, removing from state", d.Id())
Expand All @@ -127,9 +128,9 @@ 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())
budgetName, resourceID, err := budgetResourceAssociationParseID(d.Id())

if err != nil {
return sdkdiag.AppendErrorf(diags, "could not parse ID (%s): %s", d.Id(), err)
Expand All @@ -140,17 +141,17 @@ 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[*awstypes.ResourceNotFoundException](err) {
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "disassociating Service Catalog Budget from Resource (%s): %s", d.Id(), err)
}

err = WaitBudgetResourceAssociationDeleted(ctx, conn, budgetName, resourceID, d.Timeout(schema.TimeoutDelete))
err = waitBudgetResourceAssociationDeleted(ctx, conn, budgetName, resourceID, d.Timeout(schema.TimeoutDelete))

if err != nil && !tfresource.NotFound(err) {
return sdkdiag.AppendErrorf(diags, "waiting for Service Catalog Budget Resource Disassociation (%s): %s", d.Id(), err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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"
Expand All @@ -28,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 @@ -56,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 @@ -74,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 @@ -116,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
51 changes: 26 additions & 25 deletions internal/service/servicecatalog/constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@ 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"
awstypes "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"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_servicecatalog_constraint")
func ResourceConstraint() *schema.Resource {
// @SDKResource("aws_servicecatalog_constraint", name="Constraint")
func resourceConstraint() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceConstraintCreate,
ReadWithoutTimeout: resourceConstraintRead,
Expand All @@ -44,8 +45,8 @@ func ResourceConstraint() *schema.Resource {
"accept_language": {
Type: schema.TypeString,
Optional: true,
Default: AcceptLanguageEnglish,
ValidateFunc: validation.StringInSlice(AcceptLanguage_Values(), false),
Default: acceptLanguageEnglish,
ValidateFunc: validation.StringInSlice(acceptLanguage_Values(), false),
},
names.AttrDescription: {
Type: schema.TypeString,
Expand Down Expand Up @@ -80,15 +81,15 @@ func ResourceConstraint() *schema.Resource {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(ConstraintType_Values(), false),
ValidateFunc: validation.StringInSlice(constraintType_Values(), false),
},
},
}
}

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 @@ -110,13 +111,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.IsAErrorMessageContains[*awstypes.InvalidParametersException](err, "profile does not exist") {
return retry.RetryableError(err)
}

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

Expand All @@ -128,7 +129,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 @@ -139,16 +140,16 @@ 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))
output, err := waitConstraintReady(ctx, conn, d.Get("accept_language").(string), d.Id(), d.Timeout(schema.TimeoutRead))

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] Service Catalog Constraint (%s) not found, removing from state", d.Id())
Expand All @@ -167,7 +168,7 @@ func resourceConstraintRead(ctx context.Context, d *schema.ResourceData, meta in
acceptLanguage := d.Get("accept_language").(string)

if acceptLanguage == "" {
acceptLanguage = AcceptLanguageEnglish
acceptLanguage = acceptLanguageEnglish
}

d.Set("accept_language", acceptLanguage)
Expand All @@ -188,7 +189,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 @@ -207,9 +208,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.IsAErrorMessageContains[*awstypes.InvalidParametersException](err, "profile does not exist") {
return retry.RetryableError(err)
}

Expand All @@ -221,7 +222,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 @@ -233,7 +234,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 @@ -243,17 +244,17 @@ 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[*awstypes.ResourceNotFoundException](err) {
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting Service Catalog Constraint (%s): %s", d.Id(), err)
}

err = WaitConstraintDeleted(ctx, conn, d.Get("accept_language").(string), d.Id(), d.Timeout(schema.TimeoutDelete))
err = waitConstraintDeleted(ctx, conn, d.Get("accept_language").(string), d.Id(), d.Timeout(schema.TimeoutDelete))

if err != nil && !tfresource.NotFound(err) {
return sdkdiag.AppendErrorf(diags, "waiting for Service Catalog Constraint (%s) to be deleted: %s", d.Id(), err)
Expand Down
Loading

0 comments on commit 0f98773

Please sign in to comment.