diff --git a/go.mod b/go.mod index 2bdfa234851..8c4104edb79 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/account v1.16.2 github.com/aws/aws-sdk-go-v2/service/acm v1.25.2 github.com/aws/aws-sdk-go-v2/service/amp v1.25.2 + github.com/aws/aws-sdk-go-v2/service/apigateway v1.23.4 github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.0 github.com/aws/aws-sdk-go-v2/service/appfabric v1.7.2 github.com/aws/aws-sdk-go-v2/service/appflow v1.41.2 diff --git a/go.sum b/go.sum index c47f55440f7..a8e4d4fbd74 100644 --- a/go.sum +++ b/go.sum @@ -52,6 +52,8 @@ github.com/aws/aws-sdk-go-v2/service/acm v1.25.2 h1:5oS1s5fZ4VyWj0tVSF7ihpE1lkaj github.com/aws/aws-sdk-go-v2/service/acm v1.25.2/go.mod h1:hGHCrWRY/be0yX4017aNZc0fpjMyBM2NNT5BgDrk4+o= github.com/aws/aws-sdk-go-v2/service/amp v1.25.2 h1:XXrduSuT8w94c3dG2dvNQioa7ZunXHXC7xwKeRzy87A= github.com/aws/aws-sdk-go-v2/service/amp v1.25.2/go.mod h1:scSghJ8LpkHW0Uge1p2Qpu7zmZ10yIKs0ylLk+XkPas= +github.com/aws/aws-sdk-go-v2/service/apigateway v1.23.4 h1:ftJ/AYiHiPMjKF3mt9TRfCHsrZsVuhxKnF2YJw/DVfw= +github.com/aws/aws-sdk-go-v2/service/apigateway v1.23.4/go.mod h1:gMxPkuoIOoHhgsbQHmZ6CCgvKLbG7a9M71U8t7oOJc4= github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.0 h1:kFSKQPVszQU+r2++ugfrwCchdRKaFmLhc2yMTdE5lls= github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.0/go.mod h1:rzi8EH52dX8O8xG+CnwS4nb47IGVRGkg7LJn7DzjUAs= github.com/aws/aws-sdk-go-v2/service/appfabric v1.7.2 h1:FUjonDjo+7YH51llB+UupHszcr/1HCCrMUX6FbdPpLc= diff --git a/internal/conns/awsclient_gen.go b/internal/conns/awsclient_gen.go index c4e8d9ef0dc..69ab3cb69c4 100644 --- a/internal/conns/awsclient_gen.go +++ b/internal/conns/awsclient_gen.go @@ -8,6 +8,7 @@ import ( account_sdkv2 "github.com/aws/aws-sdk-go-v2/service/account" acm_sdkv2 "github.com/aws/aws-sdk-go-v2/service/acm" amp_sdkv2 "github.com/aws/aws-sdk-go-v2/service/amp" + apigateway_sdkv2 "github.com/aws/aws-sdk-go-v2/service/apigateway" appconfig_sdkv2 "github.com/aws/aws-sdk-go-v2/service/appconfig" appfabric_sdkv2 "github.com/aws/aws-sdk-go-v2/service/appfabric" appflow_sdkv2 "github.com/aws/aws-sdk-go-v2/service/appflow" @@ -144,7 +145,6 @@ import ( xray_sdkv2 "github.com/aws/aws-sdk-go-v2/service/xray" acmpca_sdkv1 "github.com/aws/aws-sdk-go/service/acmpca" amplify_sdkv1 "github.com/aws/aws-sdk-go/service/amplify" - apigateway_sdkv1 "github.com/aws/aws-sdk-go/service/apigateway" apigatewayv2_sdkv1 "github.com/aws/aws-sdk-go/service/apigatewayv2" appconfig_sdkv1 "github.com/aws/aws-sdk-go/service/appconfig" appintegrationsservice_sdkv1 "github.com/aws/aws-sdk-go/service/appintegrationsservice" @@ -264,8 +264,8 @@ func (c *AWSClient) AMPClient(ctx context.Context) *amp_sdkv2.Client { return errs.Must(client[*amp_sdkv2.Client](ctx, c, names.AMP, make(map[string]any))) } -func (c *AWSClient) APIGatewayConn(ctx context.Context) *apigateway_sdkv1.APIGateway { - return errs.Must(conn[*apigateway_sdkv1.APIGateway](ctx, c, names.APIGateway, make(map[string]any))) +func (c *AWSClient) APIGatewayClient(ctx context.Context) *apigateway_sdkv2.Client { + return errs.Must(client[*apigateway_sdkv2.Client](ctx, c, names.APIGateway, make(map[string]any))) } func (c *AWSClient) APIGatewayV2Conn(ctx context.Context) *apigatewayv2_sdkv1.ApiGatewayV2 { diff --git a/internal/service/apigateway/account.go b/internal/service/apigateway/account.go index d2cddddb3ec..a7ae8795dbe 100644 --- a/internal/service/apigateway/account.go +++ b/internal/service/apigateway/account.go @@ -6,14 +6,14 @@ package apigateway import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/internal/verify" ) @@ -67,19 +67,19 @@ func ResourceAccount() *schema.Resource { func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.UpdateAccountInput{} if v, ok := d.GetOk("cloudwatch_role_arn"); ok { - input.PatchOperations = []*apigateway.PatchOperation{{ - Op: aws.String(apigateway.OpReplace), + input.PatchOperations = []awstypes.PatchOperation{{ + Op: awstypes.OpReplace, Path: aws.String("/cloudwatchRoleArn"), Value: aws.String(v.(string)), }} } else { - input.PatchOperations = []*apigateway.PatchOperation{{ - Op: aws.String(apigateway.OpReplace), + input.PatchOperations = []awstypes.PatchOperation{{ + Op: awstypes.OpReplace, Path: aws.String("/cloudwatchRoleArn"), Value: aws.String(""), }} @@ -87,14 +87,14 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, meta int _, err := tfresource.RetryWhen(ctx, propagationTimeout, func() (interface{}, error) { - return conn.UpdateAccountWithContext(ctx, input) + return conn.UpdateAccount(ctx, input) }, func(err error) (bool, error) { - if tfawserr.ErrMessageContains(err, apigateway.ErrCodeBadRequestException, "The role ARN does not have required permissions") { + if errs.IsAErrorMessageContains[*awstypes.BadRequestException](err, "The role ARN does not have required permissions") { return true, err } - if tfawserr.ErrMessageContains(err, apigateway.ErrCodeBadRequestException, "API Gateway could not successfully write to CloudWatch Logs using the ARN specified") { + if errs.IsAErrorMessageContains[*awstypes.BadRequestException](err, "API Gateway could not successfully write to CloudWatch Logs using the ARN specified") { return true, err } @@ -115,9 +115,9 @@ func resourceAccountUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceAccountRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - account, err := conn.GetAccountWithContext(ctx, &apigateway.GetAccountInput{}) + account, err := conn.GetAccount(ctx, &apigateway.GetAccountInput{}) if err != nil { return sdkdiag.AppendErrorf(diags, "reading API Gateway Account: %s", err) @@ -125,7 +125,7 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("api_key_version", account.ApiKeyVersion) d.Set("cloudwatch_role_arn", account.CloudwatchRoleArn) - d.Set("features", flex.FlattenStringSet(account.Features)) + d.Set("features", account.Features) if err := d.Set("throttle_settings", flattenThrottleSettings(account.ThrottleSettings)); err != nil { return sdkdiag.AppendErrorf(diags, "setting throttle_settings: %s", err) } diff --git a/internal/service/apigateway/api_key.go b/internal/service/apigateway/api_key.go index a9bc1cc418c..0e89b7efabd 100644 --- a/internal/service/apigateway/api_key.go +++ b/internal/service/apigateway/api_key.go @@ -9,15 +9,16 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -86,12 +87,12 @@ func ResourceAPIKey() *schema.Resource { func resourceAPIKeyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) name := d.Get("name").(string) input := &apigateway.CreateApiKeyInput{ Description: aws.String(d.Get("description").(string)), - Enabled: aws.Bool(d.Get("enabled").(bool)), + Enabled: d.Get("enabled").(bool), Name: aws.String(name), Tags: getTagsIn(ctx), Value: aws.String(d.Get("value").(string)), @@ -101,20 +102,20 @@ func resourceAPIKeyCreate(ctx context.Context, d *schema.ResourceData, meta inte input.CustomerId = aws.String(v.(string)) } - apiKey, err := conn.CreateApiKeyWithContext(ctx, input) + apiKey, err := conn.CreateApiKey(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway API Key (%s): %s", name, err) } - d.SetId(aws.StringValue(apiKey.Id)) + d.SetId(aws.ToString(apiKey.Id)) return append(diags, resourceAPIKeyRead(ctx, d, meta)...) } func resourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) apiKey, err := FindAPIKeyByID(ctx, conn, d.Id()) @@ -148,40 +149,40 @@ func resourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta interf return diags } -func resourceAPIKeyUpdateOperations(d *schema.ResourceData) []*apigateway.PatchOperation { - operations := make([]*apigateway.PatchOperation, 0) +func resourceAPIKeyUpdateOperations(d *schema.ResourceData) []awstypes.PatchOperation { + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("enabled") { isEnabled := "false" if d.Get("enabled").(bool) { isEnabled = "true" } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/enabled"), Value: aws.String(isEnabled), }) } if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) } if d.HasChange("name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/name"), Value: aws.String(d.Get("name").(string)), }) } if d.HasChange("customer_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/customerId"), Value: aws.String(d.Get("customer_id").(string)), }) @@ -192,10 +193,10 @@ func resourceAPIKeyUpdateOperations(d *schema.ResourceData) []*apigateway.PatchO func resourceAPIKeyUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) if d.HasChangesExcept("tags", "tags_all") { - _, err := conn.UpdateApiKeyWithContext(ctx, &apigateway.UpdateApiKeyInput{ + _, err := conn.UpdateApiKey(ctx, &apigateway.UpdateApiKeyInput{ ApiKey: aws.String(d.Id()), PatchOperations: resourceAPIKeyUpdateOperations(d), }) @@ -210,14 +211,14 @@ func resourceAPIKeyUpdate(ctx context.Context, d *schema.ResourceData, meta inte func resourceAPIKeyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway API Key: %s", d.Id()) - _, err := conn.DeleteApiKeyWithContext(ctx, &apigateway.DeleteApiKeyInput{ + _, err := conn.DeleteApiKey(ctx, &apigateway.DeleteApiKeyInput{ ApiKey: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -228,15 +229,15 @@ func resourceAPIKeyDelete(ctx context.Context, d *schema.ResourceData, meta inte return diags } -func FindAPIKeyByID(ctx context.Context, conn *apigateway.APIGateway, id string) (*apigateway.ApiKey, error) { +func FindAPIKeyByID(ctx context.Context, conn *apigateway.Client, id string) (*apigateway.GetApiKeyOutput, error) { input := &apigateway.GetApiKeyInput{ ApiKey: aws.String(id), IncludeValue: aws.Bool(true), } - output, err := conn.GetApiKeyWithContext(ctx, input) + output, err := conn.GetApiKey(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/api_key_data_source.go b/internal/service/apigateway/api_key_data_source.go index 289919d6ea8..4656353d43f 100644 --- a/internal/service/apigateway/api_key_data_source.go +++ b/internal/service/apigateway/api_key_data_source.go @@ -7,7 +7,7 @@ import ( "context" "time" - "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-provider-aws/internal/conns" @@ -61,7 +61,7 @@ func DataSourceAPIKey() *schema.Resource { func dataSourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig id := d.Get("id").(string) @@ -71,12 +71,12 @@ func dataSourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta inte return sdkdiag.AppendErrorf(diags, "reading API Gateway API Key (%s): %s", id, err) } - d.SetId(aws.StringValue(apiKey.Id)) - d.Set("created_date", aws.TimeValue(apiKey.CreatedDate).Format(time.RFC3339)) + d.SetId(aws.ToString(apiKey.Id)) + d.Set("created_date", aws.ToTime(apiKey.CreatedDate).Format(time.RFC3339)) d.Set("customer_id", apiKey.CustomerId) d.Set("description", apiKey.Description) d.Set("enabled", apiKey.Enabled) - d.Set("last_updated_date", aws.TimeValue(apiKey.LastUpdatedDate).Format(time.RFC3339)) + d.Set("last_updated_date", aws.ToTime(apiKey.LastUpdatedDate).Format(time.RFC3339)) d.Set("name", apiKey.Name) d.Set("value", apiKey.Value) diff --git a/internal/service/apigateway/api_key_test.go b/internal/service/apigateway/api_key_test.go index f6efc1bb0c1..36083f17956 100644 --- a/internal/service/apigateway/api_key_test.go +++ b/internal/service/apigateway/api_key_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,7 +23,7 @@ import ( func TestAccAPIGatewayAPIKey_basic(t *testing.T) { ctx := acctest.Context(t) - var apiKey1, apiKey2 apigateway.ApiKey + var apiKey1, apiKey2 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rNameUpdated := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -73,7 +73,7 @@ func TestAccAPIGatewayAPIKey_basic(t *testing.T) { func TestAccAPIGatewayAPIKey_tags(t *testing.T) { ctx := acctest.Context(t) - var apiKey1 apigateway.ApiKey + var apiKey1 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -119,7 +119,7 @@ func TestAccAPIGatewayAPIKey_tags(t *testing.T) { func TestAccAPIGatewayAPIKey_customerID(t *testing.T) { ctx := acctest.Context(t) - var apiKey1, apiKey2 apigateway.ApiKey + var apiKey1, apiKey2 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -155,7 +155,7 @@ func TestAccAPIGatewayAPIKey_customerID(t *testing.T) { func TestAccAPIGatewayAPIKey_description(t *testing.T) { ctx := acctest.Context(t) - var apiKey1, apiKey2 apigateway.ApiKey + var apiKey1, apiKey2 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -191,7 +191,7 @@ func TestAccAPIGatewayAPIKey_description(t *testing.T) { func TestAccAPIGatewayAPIKey_enabled(t *testing.T) { ctx := acctest.Context(t) - var apiKey1, apiKey2 apigateway.ApiKey + var apiKey1, apiKey2 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -227,7 +227,7 @@ func TestAccAPIGatewayAPIKey_enabled(t *testing.T) { func TestAccAPIGatewayAPIKey_value(t *testing.T) { ctx := acctest.Context(t) - var apiKey1 apigateway.ApiKey + var apiKey1 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -255,7 +255,7 @@ func TestAccAPIGatewayAPIKey_value(t *testing.T) { func TestAccAPIGatewayAPIKey_disappears(t *testing.T) { ctx := acctest.Context(t) - var apiKey1 apigateway.ApiKey + var apiKey1 apigateway.GetApiKeyOutput resourceName := "aws_api_gateway_api_key.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -277,7 +277,7 @@ func TestAccAPIGatewayAPIKey_disappears(t *testing.T) { }) } -func testAccCheckAPIKeyExists(ctx context.Context, n string, v *apigateway.ApiKey) resource.TestCheckFunc { +func testAccCheckAPIKeyExists(ctx context.Context, n string, v *apigateway.GetApiKeyOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -288,7 +288,7 @@ func testAccCheckAPIKeyExists(ctx context.Context, n string, v *apigateway.ApiKe return fmt.Errorf("No API Gateway API Key ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindAPIKeyByID(ctx, conn, rs.Primary.ID) @@ -304,7 +304,7 @@ func testAccCheckAPIKeyExists(ctx context.Context, n string, v *apigateway.ApiKe func testAccCheckAPIKeyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_api_key" { @@ -328,9 +328,9 @@ func testAccCheckAPIKeyDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckAPIKeyNotRecreated(i, j *apigateway.ApiKey) resource.TestCheckFunc { +func testAccCheckAPIKeyNotRecreated(i, j *apigateway.GetApiKeyOutput) resource.TestCheckFunc { return func(s *terraform.State) error { - if !aws.TimeValue(i.CreatedDate).Equal(aws.TimeValue(j.CreatedDate)) { + if !aws.ToTime(i.CreatedDate).Equal(aws.ToTime(j.CreatedDate)) { return fmt.Errorf("API Gateway API Key recreated") } diff --git a/internal/service/apigateway/authorizer.go b/internal/service/apigateway/authorizer.go index 497a97f1ee7..468ced03be4 100644 --- a/internal/service/apigateway/authorizer.go +++ b/internal/service/apigateway/authorizer.go @@ -9,15 +9,17 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -96,10 +98,10 @@ func ResourceAuthorizer() *schema.Resource { ForceNew: true, }, "type": { - Type: schema.TypeString, - Optional: true, - Default: apigateway.AuthorizerTypeToken, - ValidateFunc: validation.StringInSlice(apigateway.AuthorizerType_Values(), false), + Type: schema.TypeString, + Optional: true, + Default: awstypes.AuthorizerTypeToken, + ValidateDiagFunc: enum.Validate[awstypes.AuthorizerType](), }, }, } @@ -107,20 +109,20 @@ func ResourceAuthorizer() *schema.Resource { func resourceAuthorizerCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) if err := validateAuthorizerType(d); err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Authorizer: %s", err) } - var postCreateOps []*apigateway.PatchOperation + var postCreateOps []awstypes.PatchOperation name := d.Get("name").(string) input := &apigateway.CreateAuthorizerInput{ IdentitySource: aws.String(d.Get("identity_source").(string)), Name: aws.String(name), RestApiId: aws.String(d.Get("rest_api_id").(string)), - Type: aws.String(d.Get("type").(string)), - AuthorizerResultTtlInSeconds: aws.Int64(int64(d.Get("authorizer_result_ttl_in_seconds").(int))), + Type: awstypes.AuthorizerType(d.Get("type").(string)), + AuthorizerResultTtlInSeconds: aws.Int32(int32(d.Get("authorizer_result_ttl_in_seconds").(int))), } if v, ok := d.GetOk("authorizer_uri"); ok { @@ -132,11 +134,11 @@ func resourceAuthorizerCreate(ctx context.Context, d *schema.ResourceData, meta // regardless of authorizer Type, the API ignores this setting if the authorizer // is of Type "COGNITO_USER_POOLS"; thus, a PatchOperation is used as an alternative. // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/16613 - if aws.StringValue(input.Type) != apigateway.AuthorizerTypeCognitoUserPools { + if input.Type != awstypes.AuthorizerTypeCognitoUserPools { input.AuthorizerCredentials = aws.String(v.(string)) } else { - postCreateOps = append(postCreateOps, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + postCreateOps = append(postCreateOps, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/authorizerCredentials"), Value: aws.String(v.(string)), }) @@ -148,16 +150,16 @@ func resourceAuthorizerCreate(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk("provider_arns"); ok { - input.ProviderARNs = flex.ExpandStringSet(v.(*schema.Set)) + input.ProviderARNs = flex.ExpandStringValueSet(v.(*schema.Set)) } - output, err := conn.CreateAuthorizerWithContext(ctx, input) + output, err := conn.CreateAuthorizer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Authorizer (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) if postCreateOps != nil { input := &apigateway.UpdateAuthorizerInput{ @@ -166,7 +168,7 @@ func resourceAuthorizerCreate(ctx context.Context, d *schema.ResourceData, meta RestApiId: input.RestApiId, } - _, err := conn.UpdateAuthorizerWithContext(ctx, input) + _, err := conn.UpdateAuthorizer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Authorizer (%s): %s", d.Id(), err) @@ -178,7 +180,7 @@ func resourceAuthorizerCreate(ctx context.Context, d *schema.ResourceData, meta func resourceAuthorizerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) apiID := d.Get("rest_api_id").(string) authorizer, err := FindAuthorizerByTwoPartKey(ctx, conn, d.Id(), apiID) @@ -204,7 +206,7 @@ func resourceAuthorizerRead(ctx context.Context, d *schema.ResourceData, meta in d.Set("identity_source", authorizer.IdentitySource) d.Set("identity_validation_expression", authorizer.IdentityValidationExpression) d.Set("name", authorizer.Name) - d.Set("provider_arns", aws.StringValueSlice(authorizer.ProviderARNs)) + d.Set("provider_arns", authorizer.ProviderARNs) d.Set("type", authorizer.Type) return diags @@ -212,55 +214,55 @@ func resourceAuthorizerRead(ctx context.Context, d *schema.ResourceData, meta in func resourceAuthorizerUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("authorizer_uri") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/authorizerUri"), Value: aws.String(d.Get("authorizer_uri").(string)), }) } if d.HasChange("identity_source") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/identitySource"), Value: aws.String(d.Get("identity_source").(string)), }) } if d.HasChange("name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/name"), Value: aws.String(d.Get("name").(string)), }) } if d.HasChange("type") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/type"), Value: aws.String(d.Get("type").(string)), }) } if d.HasChange("authorizer_credentials") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/authorizerCredentials"), Value: aws.String(d.Get("authorizer_credentials").(string)), }) } if d.HasChange("authorizer_result_ttl_in_seconds") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/authorizerResultTtlInSeconds"), Value: aws.String(fmt.Sprintf("%d", d.Get("authorizer_result_ttl_in_seconds").(int))), }) } if d.HasChange("identity_validation_expression") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/identityValidationExpression"), Value: aws.String(d.Get("identity_validation_expression").(string)), }) @@ -272,16 +274,16 @@ func resourceAuthorizerUpdate(ctx context.Context, d *schema.ResourceData, meta // providerARNs can't be empty, so add first and then remove additionList := ns.Difference(os) for _, v := range additionList.List() { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/providerARNs"), Value: aws.String(v.(string)), }) } removalList := os.Difference(ns) for _, v := range removalList.List() { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/providerARNs"), Value: aws.String(v.(string)), }) @@ -294,7 +296,7 @@ func resourceAuthorizerUpdate(ctx context.Context, d *schema.ResourceData, meta RestApiId: aws.String(d.Get("rest_api_id").(string)), } - _, err := conn.UpdateAuthorizerWithContext(ctx, input) + _, err := conn.UpdateAuthorizer(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Authorizer (%s): %s", d.Id(), err) @@ -305,10 +307,10 @@ func resourceAuthorizerUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceAuthorizerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[INFO] Deleting API Gateway Authorizer: %s", d.Id()) - _, err := conn.DeleteAuthorizerWithContext(ctx, &apigateway.DeleteAuthorizerInput{ + _, err := conn.DeleteAuthorizer(ctx, &apigateway.DeleteAuthorizerInput{ AuthorizerId: aws.String(d.Id()), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) @@ -316,7 +318,7 @@ func resourceAuthorizerDelete(ctx context.Context, d *schema.ResourceData, meta if err != nil { // XXX: Figure out a way to delete the method that depends on the authorizer first // otherwise the authorizer will be dangling until the API is deleted - if !strings.Contains(err.Error(), apigateway.ErrCodeConflictException) { + if errs.IsA[*awstypes.ConflictException](err) { return sdkdiag.AppendErrorf(diags, "deleting API Gateway Authorizer failed: %s", err) } } @@ -328,7 +330,7 @@ func resourceAuthorizerCustomizeDiff(_ context.Context, diff *schema.ResourceDif // switch type between COGNITO_USER_POOLS and TOKEN/REQUEST will create new resource. if diff.HasChange("type") { o, n := diff.GetChange("type") - if o.(string) == apigateway.AuthorizerTypeCognitoUserPools || n.(string) == apigateway.AuthorizerTypeCognitoUserPools { + if o.(string) == string(awstypes.AuthorizerTypeCognitoUserPools) || n.(string) == string(awstypes.AuthorizerTypeCognitoUserPools) { if err := diff.ForceNew("type"); err != nil { return err } @@ -339,15 +341,15 @@ func resourceAuthorizerCustomizeDiff(_ context.Context, diff *schema.ResourceDif } func validateAuthorizerType(d *schema.ResourceData) error { - authType := d.Get("type").(string) + authType := awstypes.AuthorizerType(d.Get("type").(string)) // authorizer_uri is required for authorizer TOKEN/REQUEST - if authType == apigateway.AuthorizerTypeRequest || authType == apigateway.AuthorizerTypeToken { + if authType == awstypes.AuthorizerTypeRequest || authType == awstypes.AuthorizerTypeToken { if v, ok := d.GetOk("authorizer_uri"); !ok || v.(string) == "" { return fmt.Errorf("authorizer_uri must be set non-empty when authorizer type is %s", authType) } } // provider_arns is required for authorizer COGNITO_USER_POOLS. - if authType == apigateway.AuthorizerTypeCognitoUserPools { + if authType == awstypes.AuthorizerTypeCognitoUserPools { if v, ok := d.GetOk("provider_arns"); !ok || v.(*schema.Set).Len() == 0 { return fmt.Errorf("provider_arns must be set non-empty when authorizer type is %s", authType) } @@ -356,15 +358,15 @@ func validateAuthorizerType(d *schema.ResourceData) error { return nil } -func FindAuthorizerByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, authorizerID, apiID string) (*apigateway.Authorizer, error) { +func FindAuthorizerByTwoPartKey(ctx context.Context, conn *apigateway.Client, authorizerID, apiID string) (*apigateway.GetAuthorizerOutput, error) { input := &apigateway.GetAuthorizerInput{ AuthorizerId: aws.String(authorizerID), RestApiId: aws.String(apiID), } - output, err := conn.GetAuthorizerWithContext(ctx, input) + output, err := conn.GetAuthorizer(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/authorizer_data_source.go b/internal/service/apigateway/authorizer_data_source.go index 70e6780fb58..907a7fcae1c 100644 --- a/internal/service/apigateway/authorizer_data_source.go +++ b/internal/service/apigateway/authorizer_data_source.go @@ -6,7 +6,6 @@ package apigateway import ( "context" - "github.com/aws/aws-sdk-go/aws" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -70,7 +69,7 @@ func DataSourceAuthorizer() *schema.Resource { func dataSourceAuthorizerRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) authorizerID := d.Get("authorizer_id").(string) apiID := d.Get("rest_api_id").(string) @@ -92,7 +91,7 @@ func dataSourceAuthorizerRead(ctx context.Context, d *schema.ResourceData, meta d.Set("identity_source", authorizer.IdentitySource) d.Set("identity_validation_expression", authorizer.IdentityValidationExpression) d.Set("name", authorizer.Name) - d.Set("provider_arns", aws.StringValueSlice(authorizer.ProviderARNs)) + d.Set("provider_arns", authorizer.ProviderARNs) d.Set("type", authorizer.Type) return diags diff --git a/internal/service/apigateway/authorizer_test.go b/internal/service/apigateway/authorizer_test.go index e906235faed..dcb37b53967 100644 --- a/internal/service/apigateway/authorizer_test.go +++ b/internal/service/apigateway/authorizer_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,7 +23,7 @@ import ( func TestAccAPIGatewayAuthorizer_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Authorizer + var conf apigateway.GetAuthorizerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_authorizer.test" lambdaResourceName := "aws_lambda_function.test" @@ -192,7 +192,7 @@ func TestAccAPIGatewayAuthorizer_switchAuthType(t *testing.T) { func TestAccAPIGatewayAuthorizer_switchAuthorizerTTL(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Authorizer + var conf apigateway.GetAuthorizerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_authorizer.test" @@ -268,7 +268,7 @@ func TestAccAPIGatewayAuthorizer_authTypeValidation(t *testing.T) { func TestAccAPIGatewayAuthorizer_Zero_ttl(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Authorizer + var conf apigateway.GetAuthorizerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_authorizer.test" @@ -297,7 +297,7 @@ func TestAccAPIGatewayAuthorizer_Zero_ttl(t *testing.T) { func TestAccAPIGatewayAuthorizer_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Authorizer + var conf apigateway.GetAuthorizerOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_authorizer.test" @@ -319,7 +319,7 @@ func TestAccAPIGatewayAuthorizer_disappears(t *testing.T) { }) } -func testAccCheckAuthorizerExists(ctx context.Context, n string, v *apigateway.Authorizer) resource.TestCheckFunc { +func testAccCheckAuthorizerExists(ctx context.Context, n string, v *apigateway.GetAuthorizerOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -330,7 +330,7 @@ func testAccCheckAuthorizerExists(ctx context.Context, n string, v *apigateway.A return fmt.Errorf("No API Gateway Authorizer ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindAuthorizerByTwoPartKey(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["rest_api_id"]) @@ -346,7 +346,7 @@ func testAccCheckAuthorizerExists(ctx context.Context, n string, v *apigateway.A func testAccCheckAuthorizerDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_authorizer" { diff --git a/internal/service/apigateway/authorizers_data_source.go b/internal/service/apigateway/authorizers_data_source.go index 5e9afe580bd..fac4e7a0747 100644 --- a/internal/service/apigateway/authorizers_data_source.go +++ b/internal/service/apigateway/authorizers_data_source.go @@ -6,8 +6,8 @@ package apigateway import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -35,7 +35,7 @@ func DataSourceAuthorizers() *schema.Resource { func dataSourceAuthorizersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) apiID := d.Get("rest_api_id").(string) input := &apigateway.GetAuthorizersInput{ @@ -49,10 +49,6 @@ func dataSourceAuthorizersRead(ctx context.Context, d *schema.ResourceData, meta } for _, v := range page.Items { - if v == nil { - continue - } - ids = append(ids, v.Id) } @@ -64,7 +60,7 @@ func dataSourceAuthorizersRead(ctx context.Context, d *schema.ResourceData, meta } d.SetId(apiID) - d.Set("ids", aws.StringValueSlice(ids)) + d.Set("ids", aws.ToStringSlice(ids)) return diags } diff --git a/internal/service/apigateway/base_path_mapping.go b/internal/service/apigateway/base_path_mapping.go index 7f8f69544ce..d4ebc52c6e3 100644 --- a/internal/service/apigateway/base_path_mapping.go +++ b/internal/service/apigateway/base_path_mapping.go @@ -10,13 +10,14 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" ) @@ -58,7 +59,7 @@ func ResourceBasePathMapping() *schema.Resource { func resourceBasePathMappingCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.CreateBasePathMappingInput{ RestApiId: aws.String(d.Get("api_id").(string)), DomainName: aws.String(d.Get("domain_name").(string)), @@ -67,10 +68,10 @@ func resourceBasePathMappingCreate(ctx context.Context, d *schema.ResourceData, } err := retry.RetryContext(ctx, 30*time.Second, func() *retry.RetryError { - _, err := conn.CreateBasePathMappingWithContext(ctx, input) + _, err := conn.CreateBasePathMapping(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeBadRequestException) { + if errs.IsA[*awstypes.BadRequestException](err) { return retry.NonRetryableError(err) } @@ -81,7 +82,7 @@ func resourceBasePathMappingCreate(ctx context.Context, d *schema.ResourceData, }) if tfresource.TimedOut(err) { - _, err = conn.CreateBasePathMappingWithContext(ctx, input) + _, err = conn.CreateBasePathMapping(ctx, input) } if err != nil { @@ -96,29 +97,29 @@ func resourceBasePathMappingCreate(ctx context.Context, d *schema.ResourceData, func resourceBasePathMappingUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("stage_name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String("replace"), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.Op("replace"), Path: aws.String("/stage"), Value: aws.String(d.Get("stage_name").(string)), }) } if d.HasChange("api_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String("replace"), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.Op("replace"), Path: aws.String("/restapiId"), Value: aws.String(d.Get("api_id").(string)), }) } if d.HasChange("base_path") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String("replace"), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.Op("replace"), Path: aws.String("/basePath"), Value: aws.String(d.Get("base_path").(string)), }) @@ -135,9 +136,9 @@ func resourceBasePathMappingUpdate(ctx context.Context, d *schema.ResourceData, PatchOperations: operations, } - log.Printf("[INFO] Updating API Gateway Base Path Mapping: %s", input) + log.Printf("[INFO] Updating API Gateway Base Path Mapping: %+v", input) - _, err = conn.UpdateBasePathMappingWithContext(ctx, &input) + _, err = conn.UpdateBasePathMapping(ctx, &input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Base Path Mapping (%s): %s", d.Id(), err) @@ -155,19 +156,19 @@ func resourceBasePathMappingUpdate(ctx context.Context, d *schema.ResourceData, func resourceBasePathMappingRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) domainName, basePath, err := DecodeBasePathMappingID(d.Id()) if err != nil { return sdkdiag.AppendErrorf(diags, "reading API Gateway Base Path Mapping (%s): %s", d.Id(), err) } - mapping, err := conn.GetBasePathMappingWithContext(ctx, &apigateway.GetBasePathMappingInput{ + mapping, err := conn.GetBasePathMapping(ctx, &apigateway.GetBasePathMappingInput{ DomainName: aws.String(domainName), BasePath: aws.String(basePath), }) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] API Gateway Base Path Mapping (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -176,7 +177,7 @@ func resourceBasePathMappingRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading API Gateway Base Path Mapping (%s): %s", d.Id(), err) } - mappingBasePath := aws.StringValue(mapping.BasePath) + mappingBasePath := aws.ToString(mapping.BasePath) if mappingBasePath == EmptyBasePathMappingValue { mappingBasePath = "" @@ -192,20 +193,20 @@ func resourceBasePathMappingRead(ctx context.Context, d *schema.ResourceData, me func resourceBasePathMappingDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) domainName, basePath, err := DecodeBasePathMappingID(d.Id()) if err != nil { return sdkdiag.AppendErrorf(diags, "deleting API Gateway Base Path Mapping (%s): %s", d.Id(), err) } - _, err = conn.DeleteBasePathMappingWithContext(ctx, &apigateway.DeleteBasePathMappingInput{ + _, err = conn.DeleteBasePathMapping(ctx, &apigateway.DeleteBasePathMappingInput{ DomainName: aws.String(domainName), BasePath: aws.String(basePath), }) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } diff --git a/internal/service/apigateway/base_path_mapping_test.go b/internal/service/apigateway/base_path_mapping_test.go index a22fe5baf52..b076300ff5b 100644 --- a/internal/service/apigateway/base_path_mapping_test.go +++ b/internal/service/apigateway/base_path_mapping_test.go @@ -8,13 +8,14 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "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" tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -75,7 +76,7 @@ func TestDecodeBasePathMappingID(t *testing.T) { func TestAccAPIGatewayBasePathMapping_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.BasePathMapping + var conf apigateway.GetBasePathMappingOutput name := acctest.RandomSubdomain() @@ -106,7 +107,7 @@ func TestAccAPIGatewayBasePathMapping_basic(t *testing.T) { // https://github.com/hashicorp/terraform/issues/9212 func TestAccAPIGatewayBasePathMapping_BasePath_empty(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.BasePathMapping + var conf apigateway.GetBasePathMappingOutput name := acctest.RandomSubdomain() @@ -136,7 +137,7 @@ func TestAccAPIGatewayBasePathMapping_BasePath_empty(t *testing.T) { func TestAccAPIGatewayBasePathMapping_updates(t *testing.T) { ctx := acctest.Context(t) - var confFirst, conf apigateway.BasePathMapping + var confFirst, conf apigateway.GetBasePathMappingOutput resourceName := "aws_api_gateway_base_path_mapping.test" name := acctest.RandomSubdomain() @@ -187,7 +188,7 @@ func TestAccAPIGatewayBasePathMapping_updates(t *testing.T) { func TestAccAPIGatewayBasePathMapping_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.BasePathMapping + var conf apigateway.GetBasePathMappingOutput name := acctest.RandomSubdomain() resourceName := "aws_api_gateway_base_path_mapping.test" @@ -213,7 +214,7 @@ func TestAccAPIGatewayBasePathMapping_disappears(t *testing.T) { }) } -func testAccCheckBasePathExists(ctx context.Context, n string, res *apigateway.BasePathMapping) resource.TestCheckFunc { +func testAccCheckBasePathExists(ctx context.Context, n string, res *apigateway.GetBasePathMappingOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -224,7 +225,7 @@ func testAccCheckBasePathExists(ctx context.Context, n string, res *apigateway.B return fmt.Errorf("No API Gateway ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) domainName, basePath, err := tfapigateway.DecodeBasePathMappingID(rs.Primary.ID) if err != nil { @@ -235,7 +236,7 @@ func testAccCheckBasePathExists(ctx context.Context, n string, res *apigateway.B DomainName: aws.String(domainName), BasePath: aws.String(basePath), } - describe, err := conn.GetBasePathMappingWithContext(ctx, req) + describe, err := conn.GetBasePathMapping(ctx, req) if err != nil { return err } @@ -248,7 +249,7 @@ func testAccCheckBasePathExists(ctx context.Context, n string, res *apigateway.B func testAccCheckBasePathDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_base_path_mapping" { @@ -264,10 +265,10 @@ func testAccCheckBasePathDestroy(ctx context.Context) resource.TestCheckFunc { DomainName: aws.String(domainName), BasePath: aws.String(basePath), } - _, err = conn.GetBasePathMappingWithContext(ctx, req) + _, err = conn.GetBasePathMapping(ctx, req) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil } return err @@ -280,7 +281,7 @@ func testAccCheckBasePathDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckBasePathStageAttribute(conf *apigateway.BasePathMapping, basePath string) resource.TestCheckFunc { +func testAccCheckBasePathStageAttribute(conf *apigateway.GetBasePathMappingOutput, basePath string) resource.TestCheckFunc { return func(s *terraform.State) error { if conf.Stage == nil { return fmt.Errorf("attribute Stage should not be nil") @@ -293,7 +294,7 @@ func testAccCheckBasePathStageAttribute(conf *apigateway.BasePathMapping, basePa } } -func testAccCheckRestAPIIDAttributeHasChanged(conf *apigateway.BasePathMapping, previousConf *apigateway.BasePathMapping) resource.TestCheckFunc { +func testAccCheckRestAPIIDAttributeHasChanged(conf *apigateway.GetBasePathMappingOutput, previousConf *apigateway.GetBasePathMappingOutput) resource.TestCheckFunc { return func(s *terraform.State) error { if conf.RestApiId == nil { return fmt.Errorf("attribute RestApiId should not be nil") @@ -306,7 +307,7 @@ func testAccCheckRestAPIIDAttributeHasChanged(conf *apigateway.BasePathMapping, } } -func testAccCheckBasePathBasePathAttribute(conf *apigateway.BasePathMapping, basePath string) resource.TestCheckFunc { +func testAccCheckBasePathBasePathAttribute(conf *apigateway.GetBasePathMappingOutput, basePath string) resource.TestCheckFunc { return func(s *terraform.State) error { if conf.Stage == nil { return fmt.Errorf("attribute Stage should not be nil") diff --git a/internal/service/apigateway/client_certificate.go b/internal/service/apigateway/client_certificate.go index 51ef7d6d841..44816ab3c20 100644 --- a/internal/service/apigateway/client_certificate.go +++ b/internal/service/apigateway/client_certificate.go @@ -8,14 +8,15 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -67,7 +68,7 @@ func ResourceClientCertificate() *schema.Resource { func resourceClientCertificateCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.GenerateClientCertificateInput{ Tags: getTagsIn(ctx), @@ -77,20 +78,20 @@ func resourceClientCertificateCreate(ctx context.Context, d *schema.ResourceData input.Description = aws.String(v.(string)) } - output, err := conn.GenerateClientCertificateWithContext(ctx, input) + output, err := conn.GenerateClientCertificate(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Client Certificate: %s", err) } - d.SetId(aws.StringValue(output.ClientCertificateId)) + d.SetId(aws.ToString(output.ClientCertificateId)) return append(diags, resourceClientCertificateRead(ctx, d, meta)...) } func resourceClientCertificateRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) cert, err := FindClientCertificateByID(ctx, conn, d.Id()) @@ -123,21 +124,21 @@ func resourceClientCertificateRead(ctx context.Context, d *schema.ResourceData, func resourceClientCertificateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) if d.HasChangesExcept("tags", "tags_all") { input := &apigateway.UpdateClientCertificateInput{ ClientCertificateId: aws.String(d.Id()), - PatchOperations: []*apigateway.PatchOperation{ + PatchOperations: []awstypes.PatchOperation{ { - Op: aws.String(apigateway.OpReplace), + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }, }, } - _, err := conn.UpdateClientCertificateWithContext(ctx, input) + _, err := conn.UpdateClientCertificate(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Client Certificate (%s): %s", d.Id(), err) @@ -149,10 +150,10 @@ func resourceClientCertificateUpdate(ctx context.Context, d *schema.ResourceData func resourceClientCertificateDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Client Certificate: %s", d.Id()) - _, err := conn.DeleteClientCertificateWithContext(ctx, &apigateway.DeleteClientCertificateInput{ + _, err := conn.DeleteClientCertificate(ctx, &apigateway.DeleteClientCertificateInput{ ClientCertificateId: aws.String(d.Id()), }) @@ -163,14 +164,14 @@ func resourceClientCertificateDelete(ctx context.Context, d *schema.ResourceData return diags } -func FindClientCertificateByID(ctx context.Context, conn *apigateway.APIGateway, id string) (*apigateway.ClientCertificate, error) { +func FindClientCertificateByID(ctx context.Context, conn *apigateway.Client, id string) (*apigateway.GetClientCertificateOutput, error) { input := &apigateway.GetClientCertificateInput{ ClientCertificateId: aws.String(id), } - output, err := conn.GetClientCertificateWithContext(ctx, input) + output, err := conn.GetClientCertificate(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/client_certificate_test.go b/internal/service/apigateway/client_certificate_test.go index 4d512589b90..853fa3d1916 100644 --- a/internal/service/apigateway/client_certificate_test.go +++ b/internal/service/apigateway/client_certificate_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" "github.com/hashicorp/terraform-provider-aws/internal/acctest" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayClientCertificate_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.ClientCertificate + var conf apigateway.GetClientCertificateOutput resourceName := "aws_api_gateway_client_certificate.test" resource.ParallelTest(t, resource.TestCase{ @@ -57,7 +57,7 @@ func TestAccAPIGatewayClientCertificate_basic(t *testing.T) { func TestAccAPIGatewayClientCertificate_tags(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.ClientCertificate + var conf apigateway.GetClientCertificateOutput resourceName := "aws_api_gateway_client_certificate.test" resource.ParallelTest(t, resource.TestCase{ @@ -102,7 +102,7 @@ func TestAccAPIGatewayClientCertificate_tags(t *testing.T) { func TestAccAPIGatewayClientCertificate_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.ClientCertificate + var conf apigateway.GetClientCertificateOutput resourceName := "aws_api_gateway_client_certificate.test" resource.ParallelTest(t, resource.TestCase{ @@ -123,7 +123,7 @@ func TestAccAPIGatewayClientCertificate_disappears(t *testing.T) { }) } -func testAccCheckClientCertificateExists(ctx context.Context, n string, v *apigateway.ClientCertificate) resource.TestCheckFunc { +func testAccCheckClientCertificateExists(ctx context.Context, n string, v *apigateway.GetClientCertificateOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -134,7 +134,7 @@ func testAccCheckClientCertificateExists(ctx context.Context, n string, v *apiga return fmt.Errorf("No API Gateway Client Certificate ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindClientCertificateByID(ctx, conn, rs.Primary.ID) @@ -150,7 +150,7 @@ func testAccCheckClientCertificateExists(ctx context.Context, n string, v *apiga func testAccCheckClientCertificateDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_client_certificate" { diff --git a/internal/service/apigateway/deployment.go b/internal/service/apigateway/deployment.go index cc2166f845a..94255606ad1 100644 --- a/internal/service/apigateway/deployment.go +++ b/internal/service/apigateway/deployment.go @@ -10,14 +10,15 @@ import ( "strings" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -85,30 +86,30 @@ func ResourceDeployment() *schema.Resource { func resourceDeploymentCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.CreateDeploymentInput{ Description: aws.String(d.Get("description").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), StageDescription: aws.String(d.Get("stage_description").(string)), StageName: aws.String(d.Get("stage_name").(string)), - Variables: flex.ExpandStringMap(d.Get("variables").(map[string]interface{})), + Variables: flex.ExpandStringValueMap(d.Get("variables").(map[string]interface{})), } - deployment, err := conn.CreateDeploymentWithContext(ctx, input) + deployment, err := conn.CreateDeployment(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Deployment: %s", err) } - d.SetId(aws.StringValue(deployment.Id)) + d.SetId(aws.ToString(deployment.Id)) return append(diags, resourceDeploymentRead(ctx, d, meta)...) } func resourceDeploymentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restAPIID := d.Get("rest_api_id").(string) deployment, err := FindDeploymentByTwoPartKey(ctx, conn, restAPIID, d.Id()) @@ -141,20 +142,20 @@ func resourceDeploymentRead(ctx context.Context, d *schema.ResourceData, meta in func resourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) } if len(operations) > 0 { - _, err := conn.UpdateDeploymentWithContext(ctx, &apigateway.UpdateDeploymentInput{ + _, err := conn.UpdateDeployment(ctx, &apigateway.UpdateDeploymentInput{ DeploymentId: aws.String(d.Id()), PatchOperations: operations, RestApiId: aws.String(d.Get("rest_api_id").(string)), @@ -170,7 +171,7 @@ func resourceDeploymentUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) // If the stage has been updated to point at a different deployment, then // the stage should not be removed when this deployment is deleted. @@ -185,14 +186,14 @@ func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, meta stage, err := FindStageByTwoPartKey(ctx, conn, restAPIID, stageName) if err == nil { - shouldDeleteStage = aws.StringValue(stage.DeploymentId) == d.Id() + shouldDeleteStage = aws.ToString(stage.DeploymentId) == d.Id() } else if !tfresource.NotFound(err) { return sdkdiag.AppendErrorf(diags, "reading API Gateway Stage (%s): %s", stageName, err) } } if shouldDeleteStage { - _, err := conn.DeleteStageWithContext(ctx, &apigateway.DeleteStageInput{ + _, err := conn.DeleteStage(ctx, &apigateway.DeleteStageInput{ StageName: aws.String(stageName), RestApiId: aws.String(restAPIID), }) @@ -203,12 +204,12 @@ func resourceDeploymentDelete(ctx context.Context, d *schema.ResourceData, meta } log.Printf("[DEBUG] Deleting API Gateway Deployment: %s", d.Id()) - _, err := conn.DeleteDeploymentWithContext(ctx, &apigateway.DeleteDeploymentInput{ + _, err := conn.DeleteDeployment(ctx, &apigateway.DeleteDeploymentInput{ DeploymentId: aws.String(d.Id()), RestApiId: aws.String(restAPIID), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -234,15 +235,15 @@ func resourceDeploymentImport(_ context.Context, d *schema.ResourceData, meta in return []*schema.ResourceData{d}, nil } -func FindDeploymentByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, restAPIID, deploymentID string) (*apigateway.Deployment, error) { +func FindDeploymentByTwoPartKey(ctx context.Context, conn *apigateway.Client, restAPIID, deploymentID string) (*apigateway.GetDeploymentOutput, error) { input := &apigateway.GetDeploymentInput{ DeploymentId: aws.String(deploymentID), RestApiId: aws.String(restAPIID), } - output, err := conn.GetDeploymentWithContext(ctx, input) + output, err := conn.GetDeployment(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/deployment_test.go b/internal/service/apigateway/deployment_test.go index 29d3e96691b..352554f3979 100644 --- a/internal/service/apigateway/deployment_test.go +++ b/internal/service/apigateway/deployment_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -23,7 +23,7 @@ import ( func TestAccAPIGatewayDeployment_basic(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment + var deployment apigateway.GetDeploymentOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" restApiResourceName := "aws_api_gateway_rest_api.test" @@ -60,8 +60,8 @@ func TestAccAPIGatewayDeployment_basic(t *testing.T) { func TestAccAPIGatewayDeployment_Disappears_restAPI(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment - var restApi apigateway.RestApi + var deployment apigateway.GetDeploymentOutput + var restApi apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" restApiResourceName := "aws_api_gateway_rest_api.test" @@ -88,8 +88,8 @@ func TestAccAPIGatewayDeployment_Disappears_restAPI(t *testing.T) { func TestAccAPIGatewayDeployment_triggers(t *testing.T) { ctx := acctest.Context(t) - var deployment1, deployment2, deployment3, deployment4 apigateway.Deployment - var stage apigateway.Stage + var deployment1, deployment2, deployment3, deployment4 apigateway.GetDeploymentOutput + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" @@ -147,7 +147,7 @@ func TestAccAPIGatewayDeployment_triggers(t *testing.T) { func TestAccAPIGatewayDeployment_description(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment + var deployment apigateway.GetDeploymentOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" @@ -177,8 +177,8 @@ func TestAccAPIGatewayDeployment_description(t *testing.T) { func TestAccAPIGatewayDeployment_stageDescription(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment - var stage apigateway.Stage + var deployment apigateway.GetDeploymentOutput + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" @@ -202,8 +202,8 @@ func TestAccAPIGatewayDeployment_stageDescription(t *testing.T) { func TestAccAPIGatewayDeployment_stageName(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment - var stage apigateway.Stage + var deployment apigateway.GetDeploymentOutput + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" stageName := sdkacctest.RandomWithPrefix("tf-acc-test-deployment") @@ -238,7 +238,7 @@ func TestAccAPIGatewayDeployment_stageName(t *testing.T) { func TestAccAPIGatewayDeployment_StageName_emptyString(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment + var deployment apigateway.GetDeploymentOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" @@ -261,7 +261,7 @@ func TestAccAPIGatewayDeployment_StageName_emptyString(t *testing.T) { func TestAccAPIGatewayDeployment_variables(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment + var deployment apigateway.GetDeploymentOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_deployment.test" @@ -286,7 +286,7 @@ func TestAccAPIGatewayDeployment_variables(t *testing.T) { // https://github.com/hashicorp/terraform-provider-aws/issues/28997. func TestAccAPIGatewayDeployment_conflictingConnectionType(t *testing.T) { ctx := acctest.Context(t) - var deployment apigateway.Deployment + var deployment apigateway.GetDeploymentOutput resourceName := "aws_api_gateway_deployment.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -307,7 +307,7 @@ func TestAccAPIGatewayDeployment_conflictingConnectionType(t *testing.T) { }) } -func testAccCheckDeploymentExists(ctx context.Context, n string, v *apigateway.Deployment) resource.TestCheckFunc { +func testAccCheckDeploymentExists(ctx context.Context, n string, v *apigateway.GetDeploymentOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -318,7 +318,7 @@ func testAccCheckDeploymentExists(ctx context.Context, n string, v *apigateway.D return fmt.Errorf("No API Gateway Deployment ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindDeploymentByTwoPartKey(ctx, conn, rs.Primary.Attributes["rest_api_id"], rs.Primary.ID) @@ -334,7 +334,7 @@ func testAccCheckDeploymentExists(ctx context.Context, n string, v *apigateway.D func testAccCheckDeploymentDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_deployment" { @@ -358,9 +358,9 @@ func testAccCheckDeploymentDestroy(ctx context.Context) resource.TestCheckFunc { } } -func testAccCheckDeploymentNotRecreated(i, j *apigateway.Deployment) resource.TestCheckFunc { +func testAccCheckDeploymentNotRecreated(i, j *apigateway.GetDeploymentOutput) resource.TestCheckFunc { return func(s *terraform.State) error { - if !aws.TimeValue(i.CreatedDate).Equal(aws.TimeValue(j.CreatedDate)) { + if !aws.ToTime(i.CreatedDate).Equal(aws.ToTime(j.CreatedDate)) { return fmt.Errorf("API Gateway Deployment recreated") } @@ -368,9 +368,9 @@ func testAccCheckDeploymentNotRecreated(i, j *apigateway.Deployment) resource.Te } } -func testAccCheckDeploymentRecreated(i, j *apigateway.Deployment) resource.TestCheckFunc { +func testAccCheckDeploymentRecreated(i, j *apigateway.GetDeploymentOutput) resource.TestCheckFunc { return func(s *terraform.State) error { - if aws.TimeValue(i.CreatedDate).Equal(aws.TimeValue(j.CreatedDate)) { + if aws.ToTime(i.CreatedDate).Equal(aws.ToTime(j.CreatedDate)) { return fmt.Errorf("API Gateway Deployment not recreated") } diff --git a/internal/service/apigateway/documentation_part.go b/internal/service/apigateway/documentation_part.go index 7a9fb5eb16a..61610b54779 100644 --- a/internal/service/apigateway/documentation_part.go +++ b/internal/service/apigateway/documentation_part.go @@ -9,12 +9,13 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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" ) @@ -81,10 +82,10 @@ func ResourceDocumentationPart() *schema.Resource { func resourceDocumentationPartCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) apiId := d.Get("rest_api_id").(string) - out, err := conn.CreateDocumentationPartWithContext(ctx, &apigateway.CreateDocumentationPartInput{ + out, err := conn.CreateDocumentationPart(ctx, &apigateway.CreateDocumentationPartInput{ Location: expandDocumentationPartLocation(d.Get("location").([]interface{})), Properties: aws.String(d.Get("properties").(string)), RestApiId: aws.String(apiId), @@ -92,14 +93,14 @@ func resourceDocumentationPartCreate(ctx context.Context, d *schema.ResourceData if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Documentation Part: %s", err) } - d.SetId(apiId + "/" + aws.StringValue(out.Id)) + d.SetId(apiId + "/" + aws.ToString(out.Id)) return diags } func resourceDocumentationPartRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[INFO] Reading API Gateway Documentation Part %s", d.Id()) @@ -108,12 +109,12 @@ func resourceDocumentationPartRead(ctx context.Context, d *schema.ResourceData, return sdkdiag.AppendErrorf(diags, "reading API Gateway Documentation Part (%s): %s", d.Id(), err) } - docPart, err := conn.GetDocumentationPartWithContext(ctx, &apigateway.GetDocumentationPartInput{ + docPart, err := conn.GetDocumentationPart(ctx, &apigateway.GetDocumentationPartInput{ DocumentationPartId: aws.String(id), RestApiId: aws.String(apiId), }) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] API Gateway Documentation Part (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -130,7 +131,7 @@ func resourceDocumentationPartRead(ctx context.Context, d *schema.ResourceData, func resourceDocumentationPartUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) apiId, id, err := DecodeDocumentationPartID(d.Id()) if err != nil { @@ -141,12 +142,12 @@ func resourceDocumentationPartUpdate(ctx context.Context, d *schema.ResourceData DocumentationPartId: aws.String(id), RestApiId: aws.String(apiId), } - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("properties") { properties := d.Get("properties").(string) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/properties"), Value: aws.String(properties), }) @@ -154,7 +155,7 @@ func resourceDocumentationPartUpdate(ctx context.Context, d *schema.ResourceData input.PatchOperations = operations - if _, err := conn.UpdateDocumentationPartWithContext(ctx, &input); err != nil { + if _, err := conn.UpdateDocumentationPart(ctx, &input); err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Documentation Part (%s): %s", d.Id(), err) } @@ -163,14 +164,14 @@ func resourceDocumentationPartUpdate(ctx context.Context, d *schema.ResourceData func resourceDocumentationPartDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) apiId, id, err := DecodeDocumentationPartID(d.Id()) if err != nil { return sdkdiag.AppendErrorf(diags, "deleting API Gateway Documentation Part (%s): %s", d.Id(), err) } - _, err = conn.DeleteDocumentationPartWithContext(ctx, &apigateway.DeleteDocumentationPartInput{ + _, err = conn.DeleteDocumentationPart(ctx, &apigateway.DeleteDocumentationPartInput{ DocumentationPartId: aws.String(id), RestApiId: aws.String(apiId), }) @@ -180,13 +181,13 @@ func resourceDocumentationPartDelete(ctx context.Context, d *schema.ResourceData return diags } -func expandDocumentationPartLocation(l []interface{}) *apigateway.DocumentationPartLocation { +func expandDocumentationPartLocation(l []interface{}) *awstypes.DocumentationPartLocation { if len(l) == 0 { return nil } loc := l[0].(map[string]interface{}) - out := &apigateway.DocumentationPartLocation{ - Type: aws.String(loc["type"].(string)), + out := &awstypes.DocumentationPartLocation{ + Type: awstypes.DocumentationPartType(loc["type"].(string)), } if v, ok := loc["method"]; ok { out.Method = aws.String(v.(string)) @@ -203,7 +204,7 @@ func expandDocumentationPartLocation(l []interface{}) *apigateway.DocumentationP return out } -func flattenDocumentationPartLocation(l *apigateway.DocumentationPartLocation) []interface{} { +func flattenDocumentationPartLocation(l *awstypes.DocumentationPartLocation) []interface{} { if l == nil { return []interface{}{} } @@ -211,24 +212,22 @@ func flattenDocumentationPartLocation(l *apigateway.DocumentationPartLocation) [ m := make(map[string]interface{}) if v := l.Method; v != nil { - m["method"] = aws.StringValue(v) + m["method"] = aws.ToString(v) } if v := l.Name; v != nil { - m["name"] = aws.StringValue(v) + m["name"] = aws.ToString(v) } if v := l.Path; v != nil { - m["path"] = aws.StringValue(v) + m["path"] = aws.ToString(v) } if v := l.StatusCode; v != nil { - m["status_code"] = aws.StringValue(v) + m["status_code"] = aws.ToString(v) } - if v := l.Type; v != nil { - m["type"] = aws.StringValue(v) - } + m["type"] = string(l.Type) return []interface{}{m} } diff --git a/internal/service/apigateway/documentation_part_test.go b/internal/service/apigateway/documentation_part_test.go index 343f996e61f..595025a51f9 100644 --- a/internal/service/apigateway/documentation_part_test.go +++ b/internal/service/apigateway/documentation_part_test.go @@ -9,21 +9,22 @@ import ( "strconv" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccAPIGatewayDocumentationPart_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationPart + var conf apigateway.GetDocumentationPartOutput rString := sdkacctest.RandString(8) apiName := fmt.Sprintf("tf-acc-test_api_doc_part_basic_%s", rString) @@ -69,7 +70,7 @@ func TestAccAPIGatewayDocumentationPart_basic(t *testing.T) { func TestAccAPIGatewayDocumentationPart_method(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationPart + var conf apigateway.GetDocumentationPartOutput rString := sdkacctest.RandString(8) apiName := fmt.Sprintf("tf-acc-test_api_doc_part_method_%s", rString) @@ -119,7 +120,7 @@ func TestAccAPIGatewayDocumentationPart_method(t *testing.T) { func TestAccAPIGatewayDocumentationPart_responseHeader(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationPart + var conf apigateway.GetDocumentationPartOutput rString := sdkacctest.RandString(8) apiName := fmt.Sprintf("tf-acc-test_api_doc_part_resp_header_%s", rString) @@ -173,7 +174,7 @@ func TestAccAPIGatewayDocumentationPart_responseHeader(t *testing.T) { func TestAccAPIGatewayDocumentationPart_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationPart + var conf apigateway.GetDocumentationPartOutput rString := sdkacctest.RandString(8) apiName := fmt.Sprintf("tf-acc-test_api_doc_part_basic_%s", rString) @@ -199,7 +200,7 @@ func TestAccAPIGatewayDocumentationPart_disappears(t *testing.T) { }) } -func testAccCheckDocumentationPartExists(ctx context.Context, n string, res *apigateway.DocumentationPart) resource.TestCheckFunc { +func testAccCheckDocumentationPartExists(ctx context.Context, n string, res *apigateway.GetDocumentationPartOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -210,7 +211,7 @@ func testAccCheckDocumentationPartExists(ctx context.Context, n string, res *api return fmt.Errorf("No API Gateway Documentation Part ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) apiId, id, err := tfapigateway.DecodeDocumentationPartID(rs.Primary.ID) if err != nil { @@ -221,7 +222,7 @@ func testAccCheckDocumentationPartExists(ctx context.Context, n string, res *api DocumentationPartId: aws.String(id), RestApiId: aws.String(apiId), } - docPart, err := conn.GetDocumentationPartWithContext(ctx, req) + docPart, err := conn.GetDocumentationPart(ctx, req) if err != nil { return err } @@ -234,7 +235,7 @@ func testAccCheckDocumentationPartExists(ctx context.Context, n string, res *api func testAccCheckDocumentationPartDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_documentation_part" { @@ -250,9 +251,9 @@ func testAccCheckDocumentationPartDestroy(ctx context.Context) resource.TestChec DocumentationPartId: aws.String(id), RestApiId: aws.String(apiId), } - _, err = conn.GetDocumentationPartWithContext(ctx, req) + _, err = conn.GetDocumentationPart(ctx, req) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil } return err diff --git a/internal/service/apigateway/documentation_version.go b/internal/service/apigateway/documentation_version.go index 25dc7c06892..51bf92440da 100644 --- a/internal/service/apigateway/documentation_version.go +++ b/internal/service/apigateway/documentation_version.go @@ -9,12 +9,13 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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" ) @@ -51,7 +52,7 @@ func ResourceDocumentationVersion() *schema.Resource { func resourceDocumentationVersionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restApiId := d.Get("rest_api_id").(string) @@ -63,9 +64,9 @@ func resourceDocumentationVersionCreate(ctx context.Context, d *schema.ResourceD params.Description = aws.String(v.(string)) } - log.Printf("[DEBUG] Creating API Gateway Documentation Version: %s", params) + log.Printf("[DEBUG] Creating API Gateway Documentation Version: %+v", params) - version, err := conn.CreateDocumentationVersionWithContext(ctx, params) + version, err := conn.CreateDocumentationVersion(ctx, params) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Documentation Version: %s", err) } @@ -77,7 +78,7 @@ func resourceDocumentationVersionCreate(ctx context.Context, d *schema.ResourceD func resourceDocumentationVersionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Reading API Gateway Documentation Version %s", d.Id()) apiId, docVersion, err := DecodeDocumentationVersionID(d.Id()) @@ -85,12 +86,12 @@ func resourceDocumentationVersionRead(ctx context.Context, d *schema.ResourceDat return sdkdiag.AppendErrorf(diags, "reading API Gateway Documentation Version (%s): %s", d.Id(), err) } - version, err := conn.GetDocumentationVersionWithContext(ctx, &apigateway.GetDocumentationVersionInput{ + version, err := conn.GetDocumentationVersion(ctx, &apigateway.GetDocumentationVersionInput{ DocumentationVersion: aws.String(docVersion), RestApiId: aws.String(apiId), }) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] API Gateway Documentation Version (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -107,15 +108,15 @@ func resourceDocumentationVersionRead(ctx context.Context, d *schema.ResourceDat func resourceDocumentationVersionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Updating API Gateway Documentation Version %s", d.Id()) - _, err := conn.UpdateDocumentationVersionWithContext(ctx, &apigateway.UpdateDocumentationVersionInput{ + _, err := conn.UpdateDocumentationVersion(ctx, &apigateway.UpdateDocumentationVersionInput{ DocumentationVersion: aws.String(d.Get("version").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), - PatchOperations: []*apigateway.PatchOperation{ + PatchOperations: []awstypes.PatchOperation{ { - Op: aws.String(apigateway.OpReplace), + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }, @@ -131,10 +132,10 @@ func resourceDocumentationVersionUpdate(ctx context.Context, d *schema.ResourceD func resourceDocumentationVersionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Documentation Version: %s", d.Id()) - _, err := conn.DeleteDocumentationVersionWithContext(ctx, &apigateway.DeleteDocumentationVersionInput{ + _, err := conn.DeleteDocumentationVersion(ctx, &apigateway.DeleteDocumentationVersionInput{ DocumentationVersion: aws.String(d.Get("version").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) diff --git a/internal/service/apigateway/documentation_version_test.go b/internal/service/apigateway/documentation_version_test.go index 1aea417d5c4..3da7427494e 100644 --- a/internal/service/apigateway/documentation_version_test.go +++ b/internal/service/apigateway/documentation_version_test.go @@ -8,21 +8,22 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" "github.com/hashicorp/terraform-provider-aws/names" ) func TestAccAPIGatewayDocumentationVersion_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationVersion + var conf apigateway.GetDocumentationVersionOutput rString := sdkacctest.RandString(8) version := fmt.Sprintf("tf-acc-test_version_%s", rString) @@ -55,7 +56,7 @@ func TestAccAPIGatewayDocumentationVersion_basic(t *testing.T) { func TestAccAPIGatewayDocumentationVersion_allFields(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationVersion + var conf apigateway.GetDocumentationVersionOutput rString := sdkacctest.RandString(8) version := fmt.Sprintf("tf-acc-test_version_%s", rString) @@ -101,7 +102,7 @@ func TestAccAPIGatewayDocumentationVersion_allFields(t *testing.T) { func TestAccAPIGatewayDocumentationVersion_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.DocumentationVersion + var conf apigateway.GetDocumentationVersionOutput rString := sdkacctest.RandString(8) version := fmt.Sprintf("tf-acc-test_version_%s", rString) @@ -127,7 +128,7 @@ func TestAccAPIGatewayDocumentationVersion_disappears(t *testing.T) { }) } -func testAccCheckDocumentationVersionExists(ctx context.Context, n string, res *apigateway.DocumentationVersion) resource.TestCheckFunc { +func testAccCheckDocumentationVersionExists(ctx context.Context, n string, res *apigateway.GetDocumentationVersionOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -138,7 +139,7 @@ func testAccCheckDocumentationVersionExists(ctx context.Context, n string, res * return fmt.Errorf("No API Gateway Documentation Version ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) apiId, version, err := tfapigateway.DecodeDocumentationVersionID(rs.Primary.ID) if err != nil { @@ -149,7 +150,7 @@ func testAccCheckDocumentationVersionExists(ctx context.Context, n string, res * DocumentationVersion: aws.String(version), RestApiId: aws.String(apiId), } - docVersion, err := conn.GetDocumentationVersionWithContext(ctx, req) + docVersion, err := conn.GetDocumentationVersion(ctx, req) if err != nil { return err } @@ -162,7 +163,7 @@ func testAccCheckDocumentationVersionExists(ctx context.Context, n string, res * func testAccCheckDocumentationVersionDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_documentation_version" { @@ -178,9 +179,9 @@ func testAccCheckDocumentationVersionDestroy(ctx context.Context) resource.TestC DocumentationVersion: aws.String(version), RestApiId: aws.String(apiId), } - _, err = conn.GetDocumentationVersionWithContext(ctx, req) + _, err = conn.GetDocumentationVersion(ctx, req) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil } return err diff --git a/internal/service/apigateway/domain_name.go b/internal/service/apigateway/domain_name.go index a0b46937883..1bb8c45631c 100644 --- a/internal/service/apigateway/domain_name.go +++ b/internal/service/apigateway/domain_name.go @@ -10,15 +10,17 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/enum" + "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" @@ -108,11 +110,8 @@ func ResourceDomainName() *schema.Resource { // BadRequestException: Cannot create an api with multiple Endpoint Types MaxItems: 1, Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice([]string{ - apigateway.EndpointTypeEdge, - apigateway.EndpointTypeRegional, - }, false), + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice(enum.Slice(awstypes.EndpointTypeEdge, awstypes.EndpointTypeRegional), false), }, }, }, @@ -160,10 +159,10 @@ func ResourceDomainName() *schema.Resource { Computed: true, }, "security_policy": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(apigateway.SecurityPolicy_Values(), true), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.SecurityPolicy](), }, names.AttrTags: tftags.TagsSchema(), names.AttrTagsAll: tftags.TagsSchemaComputed(), @@ -175,7 +174,7 @@ func ResourceDomainName() *schema.Resource { func resourceDomainNameCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) domainName := d.Get("domain_name").(string) input := &apigateway.CreateDomainNameInput{ @@ -221,23 +220,23 @@ func resourceDomainNameCreate(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk("security_policy"); ok { - input.SecurityPolicy = aws.String(v.(string)) + input.SecurityPolicy = awstypes.SecurityPolicy(v.(string)) } - output, err := conn.CreateDomainNameWithContext(ctx, input) + output, err := conn.CreateDomainName(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Domain Name (%s): %s", domainName, err) } - d.SetId(aws.StringValue(output.DomainName)) + d.SetId(aws.ToString(output.DomainName)) return append(diags, resourceDomainNameRead(ctx, d, meta)...) } func resourceDomainNameRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) domainName, err := FindDomainName(ctx, conn, d.Id()) @@ -288,22 +287,22 @@ func resourceDomainNameRead(ctx context.Context, d *schema.ResourceData, meta in func resourceDomainNameUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) if d.HasChangesExcept("tags", "tags_all") { - var operations []*apigateway.PatchOperation + var operations []awstypes.PatchOperation if d.HasChange("certificate_arn") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/certificateArn"), Value: aws.String(d.Get("certificate_arn").(string)), }) } if d.HasChange("certificate_name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/certificateName"), Value: aws.String(d.Get("certificate_name").(string)), }) @@ -315,8 +314,8 @@ func resourceDomainNameUpdate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk("endpoint_configuration"); ok && len(v.([]interface{})) > 0 { m := v.([]interface{})[0].(map[string]interface{}) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/endpointConfiguration/types/0"), Value: aws.String(m["types"].([]interface{})[0].(string)), }) @@ -328,24 +327,24 @@ func resourceDomainNameUpdate(ctx context.Context, d *schema.ResourceData, meta tfMap := v.([]interface{})[0].(map[string]interface{}) if d.HasChange("mutual_tls_authentication.0.truststore_uri") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/mutualTlsAuthentication/truststoreUri"), Value: aws.String(tfMap["truststore_uri"].(string)), }) } if d.HasChange("mutual_tls_authentication.0.truststore_version") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/mutualTlsAuthentication/truststoreVersion"), Value: aws.String(tfMap["truststore_version"].(string)), }) } } else { // To disable mutual TLS for a custom domain name, remove the truststore from your custom domain name. - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/mutualTlsAuthentication/truststoreUri"), Value: aws.String(""), }) @@ -353,38 +352,38 @@ func resourceDomainNameUpdate(ctx context.Context, d *schema.ResourceData, meta } if d.HasChange("ownership_verification_certificate_arn") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/ownershipVerificationCertificateArn"), Value: aws.String(d.Get("ownership_verification_certificate_arn").(string)), }) } if d.HasChange("regional_certificate_arn") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/regionalCertificateArn"), Value: aws.String(d.Get("regional_certificate_arn").(string)), }) } if d.HasChange("regional_certificate_name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/regionalCertificateName"), Value: aws.String(d.Get("regional_certificate_name").(string)), }) } if d.HasChange("security_policy") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/securityPolicy"), Value: aws.String(d.Get("security_policy").(string)), }) } - _, err := conn.UpdateDomainNameWithContext(ctx, &apigateway.UpdateDomainNameInput{ + _, err := conn.UpdateDomainName(ctx, &apigateway.UpdateDomainNameInput{ DomainName: aws.String(d.Id()), PatchOperations: operations, }) @@ -403,14 +402,14 @@ func resourceDomainNameUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceDomainNameDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Domain Name: %s", d.Id()) - _, err := conn.DeleteDomainNameWithContext(ctx, &apigateway.DeleteDomainNameInput{ + _, err := conn.DeleteDomainName(ctx, &apigateway.DeleteDomainNameInput{ DomainName: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -421,14 +420,14 @@ func resourceDomainNameDelete(ctx context.Context, d *schema.ResourceData, meta return diags } -func FindDomainName(ctx context.Context, conn *apigateway.APIGateway, domainName string) (*apigateway.DomainName, error) { +func FindDomainName(ctx context.Context, conn *apigateway.Client, domainName string) (*apigateway.GetDomainNameOutput, error) { input := &apigateway.GetDomainNameInput{ DomainName: aws.String(domainName), } - output, err := conn.GetDomainNameWithContext(ctx, input) + output, err := conn.GetDomainName(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -446,7 +445,7 @@ func FindDomainName(ctx context.Context, conn *apigateway.APIGateway, domainName return output, nil } -func statusDomainName(ctx context.Context, conn *apigateway.APIGateway, domainName string) retry.StateRefreshFunc { +func statusDomainName(ctx context.Context, conn *apigateway.Client, domainName string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindDomainName(ctx, conn, domainName) @@ -457,17 +456,17 @@ func statusDomainName(ctx context.Context, conn *apigateway.APIGateway, domainNa return nil, "", err } - return output, aws.StringValue(output.DomainNameStatus), nil + return output, string(output.DomainNameStatus), nil } } -func waitDomainNameUpdated(ctx context.Context, conn *apigateway.APIGateway, domainName string) (*apigateway.DomainName, error) { +func waitDomainNameUpdated(ctx context.Context, conn *apigateway.Client, domainName string) (*awstypes.DomainName, error) { const ( timeout = 15 * time.Minute ) stateConf := &retry.StateChangeConf{ - Pending: []string{apigateway.DomainNameStatusUpdating}, - Target: []string{apigateway.DomainNameStatusAvailable}, + Pending: enum.Slice(awstypes.DomainNameStatusUpdating), + Target: enum.Slice(awstypes.DomainNameStatusAvailable), Refresh: statusDomainName(ctx, conn, domainName), Timeout: timeout, Delay: 1 * time.Minute, @@ -476,8 +475,8 @@ func waitDomainNameUpdated(ctx context.Context, conn *apigateway.APIGateway, dom outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*apigateway.DomainName); ok { - tfresource.SetLastError(err, errors.New(aws.StringValue(output.DomainNameStatusMessage))) + if output, ok := outputRaw.(*awstypes.DomainName); ok { + tfresource.SetLastError(err, errors.New(aws.ToString(output.DomainNameStatusMessage))) return output, err } @@ -485,14 +484,14 @@ func waitDomainNameUpdated(ctx context.Context, conn *apigateway.APIGateway, dom return nil, err } -func expandMutualTLSAuthentication(tfList []interface{}) *apigateway.MutualTlsAuthenticationInput { +func expandMutualTLSAuthentication(tfList []interface{}) *awstypes.MutualTlsAuthenticationInput { if len(tfList) == 0 || tfList[0] == nil { return nil } tfMap := tfList[0].(map[string]interface{}) - apiObject := &apigateway.MutualTlsAuthenticationInput{} + apiObject := &awstypes.MutualTlsAuthenticationInput{} if v, ok := tfMap["truststore_uri"].(string); ok && v != "" { apiObject.TruststoreUri = aws.String(v) @@ -505,7 +504,7 @@ func expandMutualTLSAuthentication(tfList []interface{}) *apigateway.MutualTlsAu return apiObject } -func flattenMutualTLSAuthentication(apiObject *apigateway.MutualTlsAuthentication) []interface{} { +func flattenMutualTLSAuthentication(apiObject *awstypes.MutualTlsAuthentication) []interface{} { if apiObject == nil { return nil } @@ -513,11 +512,11 @@ func flattenMutualTLSAuthentication(apiObject *apigateway.MutualTlsAuthenticatio tfMap := map[string]interface{}{} if v := apiObject.TruststoreUri; v != nil { - tfMap["truststore_uri"] = aws.StringValue(v) + tfMap["truststore_uri"] = aws.ToString(v) } if v := apiObject.TruststoreVersion; v != nil { - tfMap["truststore_version"] = aws.StringValue(v) + tfMap["truststore_version"] = aws.ToString(v) } return []interface{}{tfMap} diff --git a/internal/service/apigateway/domain_name_data_source.go b/internal/service/apigateway/domain_name_data_source.go index e5beefb8c41..4ffa77b9c98 100644 --- a/internal/service/apigateway/domain_name_data_source.go +++ b/internal/service/apigateway/domain_name_data_source.go @@ -8,8 +8,8 @@ import ( "fmt" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-aws/internal/conns" @@ -91,7 +91,7 @@ func DataSourceDomainName() *schema.Resource { func dataSourceDomainNameRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig domainName := d.Get("domain_name").(string) @@ -101,7 +101,7 @@ func dataSourceDomainNameRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading API Gateway Domain Name (%s): %s", domainName, err) } - d.SetId(aws.StringValue(output.DomainName)) + d.SetId(aws.ToString(output.DomainName)) arn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, diff --git a/internal/service/apigateway/domain_name_test.go b/internal/service/apigateway/domain_name_test.go index bb77d2a004a..b03baac0003 100644 --- a/internal/service/apigateway/domain_name_test.go +++ b/internal/service/apigateway/domain_name_test.go @@ -10,9 +10,9 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/aws/endpoints" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" @@ -27,12 +27,12 @@ func TestAccAPIGatewayDomainName_certificateARN(t *testing.T) { ctx := acctest.Context(t) rootDomain := acctest.ACMCertificateDomainFromEnv(t) domain := acctest.ACMCertificateRandomSubDomain(rootDomain) - var domainName apigateway.DomainName + var domainName apigateway.GetDomainNameOutput acmCertificateResourceName := "aws_acm_certificate.test" resourceName := "aws_api_gateway_domain_name.test" resource.ParallelTest(t, resource.TestCase{ - PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, endpoints.UsEast1RegionID) }, + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckRegion(t, names.USEast1RegionID) }, ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID), ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, CheckDestroy: testAccCheckDomainNameDestroy(ctx), @@ -90,7 +90,7 @@ func TestAccAPIGatewayDomainName_certificateName(t *testing.T) { "This environment variable must be set to any non-empty value " + "with a domain name acceptable for the certificate to enable the test.") } - var conf apigateway.DomainName + var conf apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" resource.ParallelTest(t, resource.TestCase{ @@ -123,7 +123,7 @@ func TestAccAPIGatewayDomainName_certificateName(t *testing.T) { func TestAccAPIGatewayDomainName_regionalCertificateARN(t *testing.T) { ctx := acctest.Context(t) - var domainName apigateway.DomainName + var domainName apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" rName := acctest.RandomSubdomain() key := acctest.TLSRSAPrivateKeyPEM(t, 2048) @@ -163,7 +163,7 @@ func TestAccAPIGatewayDomainName_regionalCertificateName(t *testing.T) { "in a region where uploading REGIONAL certificates is allowed " + "to enable the test.") } - var domainName apigateway.DomainName + var domainName apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" domain := acctest.RandomDomainName() domainWildcard := fmt.Sprintf("*.%s", domain) @@ -200,7 +200,7 @@ func TestAccAPIGatewayDomainName_regionalCertificateName(t *testing.T) { func TestAccAPIGatewayDomainName_securityPolicy(t *testing.T) { ctx := acctest.Context(t) - var domainName apigateway.DomainName + var domainName apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" rName := acctest.RandomSubdomain() key := acctest.TLSRSAPrivateKeyPEM(t, 2048) @@ -213,10 +213,10 @@ func TestAccAPIGatewayDomainName_securityPolicy(t *testing.T) { CheckDestroy: testAccCheckDomainNameDestroy(ctx), Steps: []resource.TestStep{ { - Config: testAccDomainNameConfig_securityPolicy(rName, key, certificate, apigateway.SecurityPolicyTls12), + Config: testAccDomainNameConfig_securityPolicy(rName, key, certificate, string(awstypes.SecurityPolicyTls12)), Check: resource.ComposeTestCheckFunc( testAccCheckDomainNameExists(ctx, resourceName, &domainName), - resource.TestCheckResourceAttr(resourceName, "security_policy", apigateway.SecurityPolicyTls12), + resource.TestCheckResourceAttr(resourceName, "security_policy", string(awstypes.SecurityPolicyTls12)), ), }, { @@ -230,7 +230,7 @@ func TestAccAPIGatewayDomainName_securityPolicy(t *testing.T) { func TestAccAPIGatewayDomainName_tags(t *testing.T) { ctx := acctest.Context(t) - var domainName apigateway.DomainName + var domainName apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" rName := acctest.RandomSubdomain() key := acctest.TLSRSAPrivateKeyPEM(t, 2048) @@ -278,7 +278,7 @@ func TestAccAPIGatewayDomainName_tags(t *testing.T) { func TestAccAPIGatewayDomainName_disappears(t *testing.T) { ctx := acctest.Context(t) - var domainName apigateway.DomainName + var domainName apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" rName := acctest.RandomSubdomain() key := acctest.TLSRSAPrivateKeyPEM(t, 2048) @@ -306,7 +306,7 @@ func TestAccAPIGatewayDomainName_MutualTLSAuthentication_basic(t *testing.T) { ctx := acctest.Context(t) rootDomain := acctest.ACMCertificateDomainFromEnv(t) domain := fmt.Sprintf("%s.%s", acctest.RandomSubdomain(), rootDomain) - var v apigateway.DomainName + var v apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" acmCertificateResourceName := "aws_acm_certificate.test" s3ObjectResourceName := "aws_s3_object.test" @@ -364,7 +364,7 @@ func TestAccAPIGatewayDomainName_MutualTLSAuthentication_ownership(t *testing.T) domain := fmt.Sprintf("%s.%s", acctest.RandomSubdomain(), rootDomain) key := acctest.TLSRSAPrivateKeyPEM(t, 2048) certificate := acctest.TLSRSAX509SelfSignedCertificatePEM(t, key, domain) - var v apigateway.DomainName + var v apigateway.GetDomainNameOutput resourceName := "aws_api_gateway_domain_name.test" publicAcmCertificateResourceName := "aws_acm_certificate.test" s3ObjectResourceName := "aws_s3_object.test" @@ -397,7 +397,7 @@ func TestAccAPIGatewayDomainName_MutualTLSAuthentication_ownership(t *testing.T) }) } -func testAccCheckDomainNameExists(ctx context.Context, n string, v *apigateway.DomainName) resource.TestCheckFunc { +func testAccCheckDomainNameExists(ctx context.Context, n string, v *apigateway.GetDomainNameOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -408,7 +408,7 @@ func testAccCheckDomainNameExists(ctx context.Context, n string, v *apigateway.D return fmt.Errorf("No API Gateway Domain Name ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindDomainName(ctx, conn, rs.Primary.ID) @@ -424,7 +424,7 @@ func testAccCheckDomainNameExists(ctx context.Context, n string, v *apigateway.D func testAccCheckDomainNameDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_domain_name" { diff --git a/internal/service/apigateway/export_data_source.go b/internal/service/apigateway/export_data_source.go index 87208885206..4670e3c4694 100644 --- a/internal/service/apigateway/export_data_source.go +++ b/internal/service/apigateway/export_data_source.go @@ -7,8 +7,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "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" @@ -63,7 +63,7 @@ func DataSourceExport() *schema.Resource { func dataSourceExportRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restApiId := d.Get("rest_api_id").(string) stageName := d.Get("stage_name").(string) @@ -79,12 +79,12 @@ func dataSourceExportRead(ctx context.Context, d *schema.ResourceData, meta inte } if v, ok := d.GetOk("parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.Parameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.Parameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } id := fmt.Sprintf("%s:%s", restApiId, stageName) - export, err := conn.GetExportWithContext(ctx, input) + export, err := conn.GetExport(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading API Gateway Export (%s): %s", id, err) } diff --git a/internal/service/apigateway/flex.go b/internal/service/apigateway/flex.go index 24824931833..bd02e113f7f 100644 --- a/internal/service/apigateway/flex.go +++ b/internal/service/apigateway/flex.go @@ -8,13 +8,14 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + tfmaps "github.com/hashicorp/terraform-provider-aws/internal/maps" ) -func expandMethodParametersOperations(d *schema.ResourceData, key string, prefix string) []*apigateway.PatchOperation { - operations := make([]*apigateway.PatchOperation, 0) +func expandMethodParametersOperations(d *schema.ResourceData, key string, prefix string) []awstypes.PatchOperation { + operations := make([]awstypes.PatchOperation, 0) oldParameters, newParameters := d.GetChange(key) oldParametersMap := oldParameters.(map[string]interface{}) @@ -22,8 +23,8 @@ func expandMethodParametersOperations(d *schema.ResourceData, key string, prefix for k, kV := range oldParametersMap { keyValueUnchanged := false - operation := apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operation := awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, k)), } @@ -35,7 +36,7 @@ func expandMethodParametersOperations(d *schema.ResourceData, key string, prefix } if (nK == k) && (nV != kV) { - operation.Op = aws.String(apigateway.OpReplace) + operation.Op = awstypes.OpReplace operation.Value = aws.String(strconv.FormatBool(b)) } else if (nK == k) && (nV == kV) { keyValueUnchanged = true @@ -43,7 +44,7 @@ func expandMethodParametersOperations(d *schema.ResourceData, key string, prefix } if !keyValueUnchanged { - operations = append(operations, &operation) + operations = append(operations, operation) } } @@ -60,39 +61,39 @@ func expandMethodParametersOperations(d *schema.ResourceData, key string, prefix value, _ := strconv.ParseBool(nV.(string)) b = value } - operation := apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operation := awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, nK)), Value: aws.String(strconv.FormatBool(b)), } - operations = append(operations, &operation) + operations = append(operations, operation) } } return operations } -func expandRequestResponseModelOperations(d *schema.ResourceData, key string, prefix string) []*apigateway.PatchOperation { - operations := make([]*apigateway.PatchOperation, 0) +func expandRequestResponseModelOperations(d *schema.ResourceData, key string, prefix string) []awstypes.PatchOperation { + operations := make([]awstypes.PatchOperation, 0) oldModels, newModels := d.GetChange(key) oldModelMap := oldModels.(map[string]interface{}) newModelMap := newModels.(map[string]interface{}) for k := range oldModelMap { - operation := apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operation := awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), } for nK, nV := range newModelMap { if nK == k { - operation.Op = aws.String(apigateway.OpReplace) + operation.Op = awstypes.OpReplace operation.Value = aws.String(nV.(string)) } } - operations = append(operations, &operation) + operations = append(operations, operation) } for nK, nV := range newModelMap { @@ -103,14 +104,21 @@ func expandRequestResponseModelOperations(d *schema.ResourceData, key string, pr } } if !exists { - operation := apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operation := awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(nK, "/", "~1", -1))), Value: aws.String(nV.(string)), } - operations = append(operations, &operation) + operations = append(operations, operation) } } return operations } + +// Expands a map of string to interface to a map of string to *bool +func expandBoolValueMap(m map[string]interface{}) map[string]bool { + return tfmaps.ApplyToAllValues(m, func(v any) bool { + return v.(bool) + }) +} diff --git a/internal/service/apigateway/gateway_response.go b/internal/service/apigateway/gateway_response.go index 9d52355476c..bfe700dba2a 100644 --- a/internal/service/apigateway/gateway_response.go +++ b/internal/service/apigateway/gateway_response.go @@ -9,13 +9,14 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -75,26 +76,26 @@ func ResourceGatewayResponse() *schema.Resource { func resourceGatewayResponsePut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.PutGatewayResponseInput{ - ResponseType: aws.String(d.Get("response_type").(string)), + ResponseType: awstypes.GatewayResponseType(d.Get("response_type").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), } if v, ok := d.GetOk("response_parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.ResponseParameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.ResponseParameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("response_templates"); ok && len(v.(map[string]interface{})) > 0 { - input.ResponseTemplates = flex.ExpandStringMap(v.(map[string]interface{})) + input.ResponseTemplates = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("status_code"); ok { input.StatusCode = aws.String(v.(string)) } - _, err := conn.PutGatewayResponseWithContext(ctx, input) + _, err := conn.PutGatewayResponse(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "putting API Gateway Gateway Response: %s", err) @@ -109,7 +110,7 @@ func resourceGatewayResponsePut(ctx context.Context, d *schema.ResourceData, met func resourceGatewayResponseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) gatewayResponse, err := FindGatewayResponseByTwoPartKey(ctx, conn, d.Get("response_type").(string), d.Get("rest_api_id").(string)) @@ -123,8 +124,8 @@ func resourceGatewayResponseRead(ctx context.Context, d *schema.ResourceData, me return sdkdiag.AppendErrorf(diags, "reading API Gateway Gateway Response (%s): %s", d.Id(), err) } - d.Set("response_parameters", aws.StringValueMap(gatewayResponse.ResponseParameters)) - d.Set("response_templates", aws.StringValueMap(gatewayResponse.ResponseTemplates)) + d.Set("response_parameters", gatewayResponse.ResponseParameters) + d.Set("response_templates", gatewayResponse.ResponseTemplates) d.Set("response_type", gatewayResponse.ResponseType) d.Set("status_code", gatewayResponse.StatusCode) @@ -133,15 +134,15 @@ func resourceGatewayResponseRead(ctx context.Context, d *schema.ResourceData, me func resourceGatewayResponseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Gateway Response: %s", d.Id()) - _, err := conn.DeleteGatewayResponseWithContext(ctx, &apigateway.DeleteGatewayResponseInput{ - ResponseType: aws.String(d.Get("response_type").(string)), + _, err := conn.DeleteGatewayResponse(ctx, &apigateway.DeleteGatewayResponseInput{ + ResponseType: awstypes.GatewayResponseType(d.Get("response_type").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -152,15 +153,15 @@ func resourceGatewayResponseDelete(ctx context.Context, d *schema.ResourceData, return diags } -func FindGatewayResponseByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, responseType, apiID string) (*apigateway.UpdateGatewayResponseOutput, error) { +func FindGatewayResponseByTwoPartKey(ctx context.Context, conn *apigateway.Client, responseType, apiID string) (*apigateway.GetGatewayResponseOutput, error) { input := &apigateway.GetGatewayResponseInput{ - ResponseType: aws.String(responseType), + ResponseType: awstypes.GatewayResponseType(responseType), RestApiId: aws.String(apiID), } - output, err := conn.GetGatewayResponseWithContext(ctx, input) + output, err := conn.GetGatewayResponse(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/gateway_response_test.go b/internal/service/apigateway/gateway_response_test.go index fd0282db5b9..aef371f1a8e 100644 --- a/internal/service/apigateway/gateway_response_test.go +++ b/internal/service/apigateway/gateway_response_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayGatewayResponse_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UpdateGatewayResponseOutput + var conf apigateway.GetGatewayResponseOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_gateway_response.test" @@ -63,7 +63,7 @@ func TestAccAPIGatewayGatewayResponse_basic(t *testing.T) { func TestAccAPIGatewayGatewayResponse_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UpdateGatewayResponseOutput + var conf apigateway.GetGatewayResponseOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_gateway_response.test" @@ -85,7 +85,7 @@ func TestAccAPIGatewayGatewayResponse_disappears(t *testing.T) { }) } -func testAccCheckGatewayResponseExists(ctx context.Context, n string, v *apigateway.UpdateGatewayResponseOutput) resource.TestCheckFunc { +func testAccCheckGatewayResponseExists(ctx context.Context, n string, v *apigateway.GetGatewayResponseOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -96,7 +96,7 @@ func testAccCheckGatewayResponseExists(ctx context.Context, n string, v *apigate return fmt.Errorf("No API Gateway Gateway Response ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindGatewayResponseByTwoPartKey(ctx, conn, rs.Primary.Attributes["response_type"], rs.Primary.Attributes["rest_api_id"]) @@ -112,7 +112,7 @@ func testAccCheckGatewayResponseExists(ctx context.Context, n string, v *apigate func testAccCheckGatewayResponseDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_gateway_response" { diff --git a/internal/service/apigateway/generate.go b/internal/service/apigateway/generate.go index 9762c336307..d336ca8f3f0 100644 --- a/internal/service/apigateway/generate.go +++ b/internal/service/apigateway/generate.go @@ -1,8 +1,8 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -//go:generate go run ../../generate/listpages/main.go -ListOps=GetAuthorizers -Paginator=Position -//go:generate go run ../../generate/tags/main.go -ServiceTagsMap -UpdateTags +//go:generate go run ../../generate/listpages/main.go -ListOps=GetAuthorizers -Paginator=Position -AWSSDKVersion=2 +//go:generate go run ../../generate/tags/main.go -ServiceTagsMap -UpdateTags -AWSSDKVersion=2 -KVTValues -SkipTypesImp //go:generate go run ../../generate/servicepackage/main.go // ONLY generate directives and package declaration! Do not add anything else to this file. diff --git a/internal/service/apigateway/integration.go b/internal/service/apigateway/integration.go index 3a6a5f07686..b2d5ad0a025 100644 --- a/internal/service/apigateway/integration.go +++ b/internal/service/apigateway/integration.go @@ -10,14 +10,16 @@ import ( "strconv" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -64,15 +66,15 @@ func ResourceIntegration() *schema.Resource { Optional: true, }, "connection_type": { - Type: schema.TypeString, - Optional: true, - Default: apigateway.ConnectionTypeInternet, - ValidateFunc: validation.StringInSlice(apigateway.ConnectionType_Values(), false), + Type: schema.TypeString, + Optional: true, + Default: awstypes.ConnectionTypeInternet, + ValidateDiagFunc: enum.Validate[awstypes.ConnectionType](), }, "content_handling": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validIntegrationContentHandling(), + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: validIntegrationContentHandling(), }, "credentials": { Type: schema.TypeString, @@ -142,10 +144,10 @@ func ResourceIntegration() *schema.Resource { }, }, "type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice(apigateway.IntegrationType_Values(), false), + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateDiagFunc: enum.Validate[awstypes.IntegrationType](), }, "uri": { Type: schema.TypeString, @@ -157,17 +159,17 @@ func ResourceIntegration() *schema.Resource { func resourceIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.PutIntegrationInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), - Type: aws.String(d.Get("type").(string)), + Type: awstypes.IntegrationType(d.Get("type").(string)), } if v, ok := d.GetOk("cache_key_parameters"); ok && v.(*schema.Set).Len() > 0 { - input.CacheKeyParameters = flex.ExpandStringSet(v.(*schema.Set)) + input.CacheKeyParameters = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("cache_namespace"); ok { @@ -181,11 +183,11 @@ func resourceIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk("connection_type"); ok { - input.ConnectionType = aws.String(v.(string)) + input.ConnectionType = awstypes.ConnectionType(v.(string)) } if v, ok := d.GetOk("content_handling"); ok { - input.ContentHandling = aws.String(v.(string)) + input.ContentHandling = awstypes.ContentHandlingStrategy(v.(string)) } if v, ok := d.GetOk("credentials"); ok { @@ -201,15 +203,15 @@ func resourceIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta } if v, ok := d.GetOk("request_parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.RequestParameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.RequestParameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("request_templates"); ok && len(v.(map[string]interface{})) > 0 { - input.RequestTemplates = flex.ExpandStringMap(v.(map[string]interface{})) + input.RequestTemplates = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("timeout_milliseconds"); ok { - input.TimeoutInMillis = aws.Int64(int64(v.(int))) + input.TimeoutInMillis = aws.Int32(int32(v.(int))) } if v, ok := d.GetOk("tls_config"); ok && len(v.([]interface{})) > 0 { @@ -220,7 +222,7 @@ func resourceIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta input.Uri = aws.String(v.(string)) } - _, err := conn.PutIntegrationWithContext(ctx, input) + _, err := conn.PutIntegration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Integration: %s", err) @@ -233,7 +235,7 @@ func resourceIntegrationCreate(ctx context.Context, d *schema.ResourceData, meta func resourceIntegrationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) integration, err := FindIntegrationByThreePartKey(ctx, conn, d.Get("http_method").(string), d.Get("resource_id").(string), d.Get("rest_api_id").(string)) @@ -247,22 +249,20 @@ func resourceIntegrationRead(ctx context.Context, d *schema.ResourceData, meta i return sdkdiag.AppendErrorf(diags, "reading API Gateway Integration (%s): %s", d.Id(), err) } - d.Set("cache_key_parameters", aws.StringValueSlice(integration.CacheKeyParameters)) + d.Set("cache_key_parameters", integration.CacheKeyParameters) d.Set("cache_namespace", integration.CacheNamespace) d.Set("connection_id", integration.ConnectionId) - d.Set("connection_type", apigateway.ConnectionTypeInternet) - if integration.ConnectionType != nil { // nosemgrep:ci.helper-schema-ResourceData-Set-extraneous-nil-check - d.Set("connection_type", integration.ConnectionType) - } + d.Set("connection_type", awstypes.ConnectionTypeInternet) + d.Set("connection_type", integration.ConnectionType) d.Set("content_handling", integration.ContentHandling) d.Set("credentials", integration.Credentials) d.Set("integration_http_method", integration.HttpMethod) d.Set("passthrough_behavior", integration.PassthroughBehavior) - d.Set("request_parameters", aws.StringValueMap(integration.RequestParameters)) - // We need to explicitly convert key = nil values into key = "", which aws.StringValueMap() removes + d.Set("request_parameters", integration.RequestParameters) + // We need to explicitly convert key = nil values into key = "", which aws.ToStringMap() removes requestTemplates := make(map[string]string) for k, v := range integration.RequestTemplates { - requestTemplates[k] = aws.StringValue(v) + requestTemplates[k] = v } d.Set("request_templates", requestTemplates) d.Set("timeout_milliseconds", integration.TimeoutInMillis) @@ -278,9 +278,9 @@ func resourceIntegrationRead(ctx context.Context, d *schema.ResourceData, meta i func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) // https://docs.aws.amazon.com/apigateway/api-reference/link-relation/integration-update/#remarks // According to the above documentation, only a few parts are addable / removable. @@ -294,8 +294,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta // Handle Removal for k := range os { if _, ok := ns[k]; !ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), }) } @@ -304,8 +304,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta for k, v := range ns { // Handle replaces if _, ok := os[k]; ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), Value: aws.String(v.(string)), }) @@ -313,8 +313,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta // Handle additions if _, ok := os[k]; !ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), Value: aws.String(v.(string)), }) @@ -332,8 +332,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta // Handle Removal for k := range os { if _, ok := ns[k]; !ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), }) } @@ -342,8 +342,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta for k, v := range ns { // Handle replaces if _, ok := os[k]; ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), Value: aws.String(v.(string)), }) @@ -351,8 +351,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta // Handle additions if _, ok := os[k]; !ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, strings.Replace(k, "/", "~1", -1))), Value: aws.String(v.(string)), }) @@ -368,8 +368,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta removalList := os.Difference(ns) for _, v := range removalList.List() { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/cacheKeyParameters/%s", v.(string))), Value: aws.String(""), }) @@ -377,8 +377,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta additionList := ns.Difference(os) for _, v := range additionList.List() { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/cacheKeyParameters/%s", v.(string))), Value: aws.String(""), }) @@ -386,8 +386,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta } if d.HasChange("cache_namespace") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/cacheNamespace"), Value: aws.String(d.Get("cache_namespace").(string)), }) @@ -397,40 +397,40 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta // that uri changes are only supported for non-mock types. Because the uri value is not used in mock // resources, it means that the uri can always be updated if d.HasChange("uri") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/uri"), Value: aws.String(d.Get("uri").(string)), }) } if d.HasChange("content_handling") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/contentHandling"), Value: aws.String(d.Get("content_handling").(string)), }) } if d.HasChange("connection_type") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/connectionType"), Value: aws.String(d.Get("connection_type").(string)), }) } if d.HasChange("connection_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/connectionId"), Value: aws.String(d.Get("connection_id").(string)), }) } if d.HasChange("timeout_milliseconds") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/timeoutInMillis"), Value: aws.String(strconv.Itoa(d.Get("timeout_milliseconds").(int))), }) @@ -440,8 +440,8 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta if v, ok := d.GetOk("tls_config"); ok && len(v.([]interface{})) > 0 { m := v.([]interface{})[0].(map[string]interface{}) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/tlsConfig/insecureSkipVerification"), Value: aws.String(strconv.FormatBool(m["insecure_skip_verification"].(bool))), }) @@ -455,7 +455,7 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta RestApiId: aws.String(d.Get("rest_api_id").(string)), } - _, err := conn.UpdateIntegrationWithContext(ctx, input) + _, err := conn.UpdateIntegration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Integration (%s): %s", d.Id(), err) @@ -466,16 +466,16 @@ func resourceIntegrationUpdate(ctx context.Context, d *schema.ResourceData, meta func resourceIntegrationDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Integration: %s", d.Id()) - _, err := conn.DeleteIntegrationWithContext(ctx, &apigateway.DeleteIntegrationInput{ + _, err := conn.DeleteIntegration(ctx, &apigateway.DeleteIntegrationInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -486,16 +486,16 @@ func resourceIntegrationDelete(ctx context.Context, d *schema.ResourceData, meta return diags } -func FindIntegrationByThreePartKey(ctx context.Context, conn *apigateway.APIGateway, httpMethod, resourceID, apiID string) (*apigateway.Integration, error) { +func FindIntegrationByThreePartKey(ctx context.Context, conn *apigateway.Client, httpMethod, resourceID, apiID string) (*apigateway.GetIntegrationOutput, error) { input := &apigateway.GetIntegrationInput{ HttpMethod: aws.String(httpMethod), ResourceId: aws.String(resourceID), RestApiId: aws.String(apiID), } - output, err := conn.GetIntegrationWithContext(ctx, input) + output, err := conn.GetIntegration(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -513,8 +513,8 @@ func FindIntegrationByThreePartKey(ctx context.Context, conn *apigateway.APIGate return output, nil } -func expandTLSConfig(vConfig []interface{}) *apigateway.TlsConfig { - config := &apigateway.TlsConfig{} +func expandTLSConfig(vConfig []interface{}) *awstypes.TlsConfig { + config := &awstypes.TlsConfig{} if len(vConfig) == 0 || vConfig[0] == nil { return config @@ -522,17 +522,17 @@ func expandTLSConfig(vConfig []interface{}) *apigateway.TlsConfig { mConfig := vConfig[0].(map[string]interface{}) if insecureSkipVerification, ok := mConfig["insecure_skip_verification"].(bool); ok { - config.InsecureSkipVerification = aws.Bool(insecureSkipVerification) + config.InsecureSkipVerification = insecureSkipVerification } return config } -func flattenTLSConfig(config *apigateway.TlsConfig) []interface{} { +func flattenTLSConfig(config *awstypes.TlsConfig) []interface{} { if config == nil { return nil } return []interface{}{map[string]interface{}{ - "insecure_skip_verification": aws.BoolValue(config.InsecureSkipVerification), + "insecure_skip_verification": config.InsecureSkipVerification, }} } diff --git a/internal/service/apigateway/integration_response.go b/internal/service/apigateway/integration_response.go index ed91d8fd1cd..376cc8cec56 100644 --- a/internal/service/apigateway/integration_response.go +++ b/internal/service/apigateway/integration_response.go @@ -9,13 +9,14 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -50,9 +51,9 @@ func ResourceIntegrationResponse() *schema.Resource { Schema: map[string]*schema.Schema{ "content_handling": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validIntegrationContentHandling(), + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: validIntegrationContentHandling(), }, "http_method": { Type: schema.TypeString, @@ -94,7 +95,7 @@ func ResourceIntegrationResponse() *schema.Resource { func resourceIntegrationResponsePut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.PutIntegrationResponseInput{ HttpMethod: aws.String(d.Get("http_method").(string)), @@ -104,22 +105,22 @@ func resourceIntegrationResponsePut(ctx context.Context, d *schema.ResourceData, } if v, ok := d.GetOk("content_handling"); ok { - input.ContentHandling = aws.String(v.(string)) + input.ContentHandling = awstypes.ContentHandlingStrategy(v.(string)) } if v, ok := d.GetOk("response_parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.ResponseParameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.ResponseParameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("response_templates"); ok && len(v.(map[string]interface{})) > 0 { - input.ResponseTemplates = flex.ExpandStringMap(v.(map[string]interface{})) + input.ResponseTemplates = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("selection_pattern"); ok { input.SelectionPattern = aws.String(v.(string)) } - _, err := conn.PutIntegrationResponseWithContext(ctx, input) + _, err := conn.PutIntegrationResponse(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "putting API Gateway Integration Response: %s", err) @@ -134,7 +135,7 @@ func resourceIntegrationResponsePut(ctx context.Context, d *schema.ResourceData, func resourceIntegrationResponseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) integrationResponse, err := FindIntegrationResponseByFourPartKey(ctx, conn, d.Get("http_method").(string), d.Get("resource_id").(string), d.Get("rest_api_id").(string), d.Get("status_code").(string)) @@ -149,11 +150,11 @@ func resourceIntegrationResponseRead(ctx context.Context, d *schema.ResourceData } d.Set("content_handling", integrationResponse.ContentHandling) - d.Set("response_parameters", aws.StringValueMap(integrationResponse.ResponseParameters)) + d.Set("response_parameters", integrationResponse.ResponseParameters) // We need to explicitly convert key = nil values into key = "", which aws.StringValueMap() removes. responseTemplates := make(map[string]string) for k, v := range integrationResponse.ResponseTemplates { - responseTemplates[k] = aws.StringValue(v) + responseTemplates[k] = v } d.Set("response_templates", responseTemplates) d.Set("selection_pattern", integrationResponse.SelectionPattern) @@ -163,17 +164,17 @@ func resourceIntegrationResponseRead(ctx context.Context, d *schema.ResourceData func resourceIntegrationResponseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Integration Response: %s", d.Id()) - _, err := conn.DeleteIntegrationResponseWithContext(ctx, &apigateway.DeleteIntegrationResponseInput{ + _, err := conn.DeleteIntegrationResponse(ctx, &apigateway.DeleteIntegrationResponseInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), StatusCode: aws.String(d.Get("status_code").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -184,7 +185,7 @@ func resourceIntegrationResponseDelete(ctx context.Context, d *schema.ResourceDa return diags } -func FindIntegrationResponseByFourPartKey(ctx context.Context, conn *apigateway.APIGateway, httpMethod, resourceID, apiID, statusCode string) (*apigateway.IntegrationResponse, error) { +func FindIntegrationResponseByFourPartKey(ctx context.Context, conn *apigateway.Client, httpMethod, resourceID, apiID, statusCode string) (*apigateway.GetIntegrationResponseOutput, error) { input := &apigateway.GetIntegrationResponseInput{ HttpMethod: aws.String(httpMethod), ResourceId: aws.String(resourceID), @@ -192,9 +193,9 @@ func FindIntegrationResponseByFourPartKey(ctx context.Context, conn *apigateway. StatusCode: aws.String(statusCode), } - output, err := conn.GetIntegrationResponseWithContext(ctx, input) + output, err := conn.GetIntegrationResponse(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/integration_response_test.go b/internal/service/apigateway/integration_response_test.go index a09a4844ea1..484f648f662 100644 --- a/internal/service/apigateway/integration_response_test.go +++ b/internal/service/apigateway/integration_response_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayIntegrationResponse_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.IntegrationResponse + var conf apigateway.GetIntegrationResponseOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration_response.test" @@ -70,7 +70,7 @@ func TestAccAPIGatewayIntegrationResponse_basic(t *testing.T) { func TestAccAPIGatewayIntegrationResponse_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.IntegrationResponse + var conf apigateway.GetIntegrationResponseOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration_response.test" @@ -92,7 +92,7 @@ func TestAccAPIGatewayIntegrationResponse_disappears(t *testing.T) { }) } -func testAccCheckIntegrationResponseExists(ctx context.Context, n string, v *apigateway.IntegrationResponse) resource.TestCheckFunc { +func testAccCheckIntegrationResponseExists(ctx context.Context, n string, v *apigateway.GetIntegrationResponseOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -103,7 +103,7 @@ func testAccCheckIntegrationResponseExists(ctx context.Context, n string, v *api return fmt.Errorf("No API Gateway Integration Response ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindIntegrationResponseByFourPartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes["resource_id"], rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes["status_code"]) @@ -119,7 +119,7 @@ func testAccCheckIntegrationResponseExists(ctx context.Context, n string, v *api func testAccCheckIntegrationResponseDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_integration_response" { diff --git a/internal/service/apigateway/integration_test.go b/internal/service/apigateway/integration_test.go index 77b642198ae..67d0d7064c1 100644 --- a/internal/service/apigateway/integration_test.go +++ b/internal/service/apigateway/integration_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccAPIGatewayIntegration_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -135,7 +135,7 @@ func TestAccAPIGatewayIntegration_basic(t *testing.T) { func TestAccAPIGatewayIntegration_contentHandling(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -212,7 +212,7 @@ func TestAccAPIGatewayIntegration_contentHandling(t *testing.T) { func TestAccAPIGatewayIntegration_CacheKey_parameters(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -256,7 +256,7 @@ func TestAccAPIGatewayIntegration_CacheKey_parameters(t *testing.T) { func TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -323,7 +323,7 @@ func TestAccAPIGatewayIntegration_CacheKeyUpdate_parameters(t *testing.T) { func TestAccAPIGatewayIntegration_integrationType(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -369,7 +369,7 @@ func TestAccAPIGatewayIntegration_integrationType(t *testing.T) { func TestAccAPIGatewayIntegration_TLS_insecureSkipVerification(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -407,7 +407,7 @@ func TestAccAPIGatewayIntegration_TLS_insecureSkipVerification(t *testing.T) { func TestAccAPIGatewayIntegration_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Integration + var conf apigateway.GetIntegrationOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_integration.test" @@ -429,7 +429,7 @@ func TestAccAPIGatewayIntegration_disappears(t *testing.T) { }) } -func testAccCheckIntegrationExists(ctx context.Context, n string, v *apigateway.Integration) resource.TestCheckFunc { +func testAccCheckIntegrationExists(ctx context.Context, n string, v *apigateway.GetIntegrationOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -440,7 +440,7 @@ func testAccCheckIntegrationExists(ctx context.Context, n string, v *apigateway. return fmt.Errorf("No API Gateway Integration ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindIntegrationByThreePartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes["resource_id"], rs.Primary.Attributes["rest_api_id"]) @@ -456,7 +456,7 @@ func testAccCheckIntegrationExists(ctx context.Context, n string, v *apigateway. func testAccCheckIntegrationDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_integration" { diff --git a/internal/service/apigateway/list_pages_gen.go b/internal/service/apigateway/list_pages_gen.go index 82d9d6086a7..16be643453f 100644 --- a/internal/service/apigateway/list_pages_gen.go +++ b/internal/service/apigateway/list_pages_gen.go @@ -1,23 +1,22 @@ -// Code generated by "internal/generate/listpages/main.go -ListOps=GetAuthorizers -Paginator=Position"; DO NOT EDIT. +// Code generated by "internal/generate/listpages/main.go -ListOps=GetAuthorizers -Paginator=Position -AWSSDKVersion=2"; DO NOT EDIT. package apigateway import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "github.com/aws/aws-sdk-go/service/apigateway/apigatewayiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" ) -func getAuthorizersPages(ctx context.Context, conn apigatewayiface.APIGatewayAPI, input *apigateway.GetAuthorizersInput, fn func(*apigateway.GetAuthorizersOutput, bool) bool) error { +func getAuthorizersPages(ctx context.Context, conn *apigateway.Client, input *apigateway.GetAuthorizersInput, fn func(*apigateway.GetAuthorizersOutput, bool) bool) error { for { - output, err := conn.GetAuthorizersWithContext(ctx, input) + output, err := conn.GetAuthorizers(ctx, input) if err != nil { return err } - lastPage := aws.StringValue(output.Position) == "" + lastPage := aws.ToString(output.Position) == "" if !fn(output, lastPage) || lastPage { break } diff --git a/internal/service/apigateway/method.go b/internal/service/apigateway/method.go index eb2199eb909..d87d5d85780 100644 --- a/internal/service/apigateway/method.go +++ b/internal/service/apigateway/method.go @@ -9,13 +9,14 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -105,10 +106,10 @@ func ResourceMethod() *schema.Resource { func resourceMethodCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.PutMethodInput{ - ApiKeyRequired: aws.Bool(d.Get("api_key_required").(bool)), + ApiKeyRequired: d.Get("api_key_required").(bool), AuthorizationType: aws.String(d.Get("authorization").(string)), HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), @@ -120,7 +121,7 @@ func resourceMethodCreate(ctx context.Context, d *schema.ResourceData, meta inte } if v, ok := d.GetOk("authorization_scopes"); ok { - input.AuthorizationScopes = flex.ExpandStringSet(v.(*schema.Set)) + input.AuthorizationScopes = flex.ExpandStringValueSet(v.(*schema.Set)) } if v, ok := d.GetOk("operation_name"); ok { @@ -128,18 +129,18 @@ func resourceMethodCreate(ctx context.Context, d *schema.ResourceData, meta inte } if v, ok := d.GetOk("request_models"); ok && len(v.(map[string]interface{})) > 0 { - input.RequestModels = flex.ExpandStringMap(v.(map[string]interface{})) + input.RequestModels = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("request_parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.RequestParameters = flex.ExpandBoolMap(v.(map[string]interface{})) + input.RequestParameters = expandBoolValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("request_validator_id"); ok { input.RequestValidatorId = aws.String(v.(string)) } - _, err := conn.PutMethodWithContext(ctx, input) + _, err := conn.PutMethod(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Method: %s", err) @@ -152,7 +153,7 @@ func resourceMethodCreate(ctx context.Context, d *schema.ResourceData, meta inte func resourceMethodRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) method, err := FindMethodByThreePartKey(ctx, conn, d.Get("http_method").(string), d.Get("resource_id").(string), d.Get("rest_api_id").(string)) @@ -168,11 +169,11 @@ func resourceMethodRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("api_key_required", method.ApiKeyRequired) d.Set("authorization", method.AuthorizationType) - d.Set("authorization_scopes", aws.StringValueSlice(method.AuthorizationScopes)) + d.Set("authorization_scopes", method.AuthorizationScopes) d.Set("authorizer_id", method.AuthorizerId) d.Set("operation_name", method.OperationName) - d.Set("request_models", aws.StringValueMap(method.RequestModels)) - d.Set("request_parameters", aws.BoolValueMap(method.RequestParameters)) + d.Set("request_models", method.RequestModels) + d.Set("request_parameters", method.RequestParameters) d.Set("request_validator_id", method.RequestValidatorId) return diags @@ -180,13 +181,13 @@ func resourceMethodRead(ctx context.Context, d *schema.ResourceData, meta interf func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("resource_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/resourceId"), Value: aws.String(d.Get("resource_id").(string)), }) @@ -202,16 +203,16 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.HasChange("authorization") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/authorizationType"), Value: aws.String(d.Get("authorization").(string)), }) } if d.HasChange("authorizer_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/authorizerId"), Value: aws.String(d.Get("authorizer_id").(string)), }) @@ -226,8 +227,8 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte additionList := ns.Difference(os) for _, v := range additionList.List() { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(path), Value: aws.String(v.(string)), }) @@ -235,8 +236,8 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte removalList := os.Difference(ns) for _, v := range removalList.List() { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(path), Value: aws.String(v.(string)), }) @@ -244,8 +245,8 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte } if d.HasChange("api_key_required") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/apiKeyRequired"), Value: aws.String(fmt.Sprintf("%t", d.Get("api_key_required").(bool))), }) @@ -260,8 +261,8 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte request_validator_id = &s } } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/requestValidatorId"), Value: request_validator_id, }) @@ -274,8 +275,8 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte operation_name = &s } } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/operationName"), Value: operation_name, }) @@ -288,7 +289,7 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte RestApiId: aws.String(d.Get("rest_api_id").(string)), } - _, err := conn.UpdateMethodWithContext(ctx, input) + _, err := conn.UpdateMethod(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Method (%s): %s", d.Id(), err) @@ -296,25 +297,25 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte // Get current cacheKeyParameters from integration before any request parameters are updated on method. replacedRequestParameters := []string{} - var currentCacheKeyParameters []*string + var currentCacheKeyParameters []string if integration, err := FindIntegrationByThreePartKey(ctx, conn, d.Get("http_method").(string), d.Get("resource_id").(string), d.Get("rest_api_id").(string)); err == nil { currentCacheKeyParameters = integration.CacheKeyParameters for _, operation := range operations { - if aws.StringValue(operation.Op) == apigateway.OpReplace && strings.HasPrefix(aws.StringValue(operation.Path), "/requestParameters") { - parts := strings.Split(aws.StringValue(operation.Path), "/") + if operation.Op == awstypes.OpReplace && strings.HasPrefix(aws.ToString(operation.Path), "/requestParameters") { + parts := strings.Split(aws.ToString(operation.Path), "/") replacedRequestParameters = append(replacedRequestParameters, parts[2]) } } // Update integration with cacheKeyParameters for replaced request parameters. - integrationOperations := make([]*apigateway.PatchOperation, 0) + integrationOperations := make([]awstypes.PatchOperation, 0) for _, replacedRequestParameter := range replacedRequestParameters { for _, cacheKeyParameter := range currentCacheKeyParameters { - if aws.StringValue(cacheKeyParameter) == replacedRequestParameter { - integrationOperations = append(integrationOperations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + if cacheKeyParameter == replacedRequestParameter { + integrationOperations = append(integrationOperations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/cacheKeyParameters/%s", replacedRequestParameter)), Value: aws.String(""), }) @@ -329,7 +330,7 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte RestApiId: aws.String(d.Get("rest_api_id").(string)), } - _, err = conn.UpdateIntegrationWithContext(ctx, input) + _, err = conn.UpdateIntegration(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Integration: %s", err) @@ -341,16 +342,16 @@ func resourceMethodUpdate(ctx context.Context, d *schema.ResourceData, meta inte func resourceMethodDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Method: %s", d.Id()) - _, err := conn.DeleteMethodWithContext(ctx, &apigateway.DeleteMethodInput{ + _, err := conn.DeleteMethod(ctx, &apigateway.DeleteMethodInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -361,16 +362,16 @@ func resourceMethodDelete(ctx context.Context, d *schema.ResourceData, meta inte return diags } -func FindMethodByThreePartKey(ctx context.Context, conn *apigateway.APIGateway, httpMethod, resourceID, apiID string) (*apigateway.Method, error) { +func FindMethodByThreePartKey(ctx context.Context, conn *apigateway.Client, httpMethod, resourceID, apiID string) (*apigateway.GetMethodOutput, error) { input := &apigateway.GetMethodInput{ HttpMethod: aws.String(httpMethod), ResourceId: aws.String(resourceID), RestApiId: aws.String(apiID), } - output, err := conn.GetMethodWithContext(ctx, input) + output, err := conn.GetMethod(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/method_response.go b/internal/service/apigateway/method_response.go index 1b0668d474d..82d2a1f6d2d 100644 --- a/internal/service/apigateway/method_response.go +++ b/internal/service/apigateway/method_response.go @@ -11,13 +11,14 @@ import ( "sync" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/flex" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" @@ -88,8 +89,9 @@ func ResourceMethodResponse() *schema.Resource { } func resourceMethodResponseCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { + const conflictRetryPeriod = 2 * time.Minute var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.PutMethodResponseInput{ HttpMethod: aws.String(d.Get("http_method").(string)), @@ -99,19 +101,19 @@ func resourceMethodResponseCreate(ctx context.Context, d *schema.ResourceData, m } if v, ok := d.GetOk("response_models"); ok && len(v.(map[string]interface{})) > 0 { - input.ResponseModels = flex.ExpandStringMap(v.(map[string]interface{})) + input.ResponseModels = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("response_parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.ResponseParameters = flex.ExpandBoolMap(v.(map[string]interface{})) + input.ResponseParameters = expandBoolValueMap(v.(map[string]interface{})) } resourceMethodResponseMutex.Lock() defer resourceMethodResponseMutex.Unlock() - _, err := tfresource.RetryWhenAWSErrCodeEquals(ctx, 2*time.Minute, func() (interface{}, error) { - return conn.PutMethodResponseWithContext(ctx, input) - }, apigateway.ErrCodeConflictException) + _, err := tfresource.RetryWhenIsA[*awstypes.ConflictException](ctx, conflictRetryPeriod, func() (interface{}, error) { + return conn.PutMethodResponse(ctx, input) + }) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Method Response: %s", err) @@ -124,7 +126,7 @@ func resourceMethodResponseCreate(ctx context.Context, d *schema.ResourceData, m func resourceMethodResponseRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) methodResponse, err := FindMethodResponseByFourPartKey(ctx, conn, d.Get("http_method").(string), d.Get("resource_id").(string), d.Get("rest_api_id").(string), d.Get("status_code").(string)) @@ -138,13 +140,13 @@ func resourceMethodResponseRead(ctx context.Context, d *schema.ResourceData, met return sdkdiag.AppendErrorf(diags, "reading API Gateway Method Response (%s): %s", d.Id(), err) } - log.Printf("[DEBUG] Received API Gateway Method Response: %s", methodResponse) + log.Printf("[DEBUG] Received API Gateway Method Response: %+v", methodResponse) - if err := d.Set("response_models", aws.StringValueMap(methodResponse.ResponseModels)); err != nil { + if err := d.Set("response_models", methodResponse.ResponseModels); err != nil { return sdkdiag.AppendErrorf(diags, "setting response_models: %s", err) } - if err := d.Set("response_parameters", aws.BoolValueMap(methodResponse.ResponseParameters)); err != nil { + if err := d.Set("response_parameters", methodResponse.ResponseParameters); err != nil { return sdkdiag.AppendErrorf(diags, "setting response_parameters: %s", err) } @@ -153,9 +155,9 @@ func resourceMethodResponseRead(ctx context.Context, d *schema.ResourceData, met func resourceMethodResponseUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("response_models") { operations = append(operations, expandRequestResponseModelOperations(d, "response_models", "responseModels")...) @@ -173,7 +175,7 @@ func resourceMethodResponseUpdate(ctx context.Context, d *schema.ResourceData, m StatusCode: aws.String(d.Get("status_code").(string)), } - _, err := conn.UpdateMethodResponseWithContext(ctx, input) + _, err := conn.UpdateMethodResponse(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Method Response (%s): %s", d.Id(), err) @@ -184,17 +186,17 @@ func resourceMethodResponseUpdate(ctx context.Context, d *schema.ResourceData, m func resourceMethodResponseDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Method Response: %s", d.Id()) - _, err := conn.DeleteMethodResponseWithContext(ctx, &apigateway.DeleteMethodResponseInput{ + _, err := conn.DeleteMethodResponse(ctx, &apigateway.DeleteMethodResponseInput{ HttpMethod: aws.String(d.Get("http_method").(string)), ResourceId: aws.String(d.Get("resource_id").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), StatusCode: aws.String(d.Get("status_code").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -205,7 +207,7 @@ func resourceMethodResponseDelete(ctx context.Context, d *schema.ResourceData, m return diags } -func FindMethodResponseByFourPartKey(ctx context.Context, conn *apigateway.APIGateway, httpMethod, resourceID, apiID, statusCode string) (*apigateway.MethodResponse, error) { +func FindMethodResponseByFourPartKey(ctx context.Context, conn *apigateway.Client, httpMethod, resourceID, apiID, statusCode string) (*apigateway.GetMethodResponseOutput, error) { input := &apigateway.GetMethodResponseInput{ HttpMethod: aws.String(httpMethod), ResourceId: aws.String(resourceID), @@ -213,9 +215,9 @@ func FindMethodResponseByFourPartKey(ctx context.Context, conn *apigateway.APIGa StatusCode: aws.String(statusCode), } - output, err := conn.GetMethodResponseWithContext(ctx, input) + output, err := conn.GetMethodResponse(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/method_response_test.go b/internal/service/apigateway/method_response_test.go index 7461c521cd1..e86b23a9c01 100644 --- a/internal/service/apigateway/method_response_test.go +++ b/internal/service/apigateway/method_response_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayMethodResponse_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.MethodResponse + var conf apigateway.GetMethodResponseOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_response.test" @@ -67,7 +67,7 @@ func TestAccAPIGatewayMethodResponse_basic(t *testing.T) { func TestAccAPIGatewayMethodResponse_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.MethodResponse + var conf apigateway.GetMethodResponseOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_response.test" @@ -89,7 +89,7 @@ func TestAccAPIGatewayMethodResponse_disappears(t *testing.T) { }) } -func testAccCheckMethodResponseExists(ctx context.Context, n string, v *apigateway.MethodResponse) resource.TestCheckFunc { +func testAccCheckMethodResponseExists(ctx context.Context, n string, v *apigateway.GetMethodResponseOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -100,7 +100,7 @@ func testAccCheckMethodResponseExists(ctx context.Context, n string, v *apigatew return fmt.Errorf("No API Gateway Method Response ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindMethodResponseByFourPartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes["resource_id"], rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes["status_code"]) @@ -116,7 +116,7 @@ func testAccCheckMethodResponseExists(ctx context.Context, n string, v *apigatew func testAccCheckMethodResponseDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_method_response" { diff --git a/internal/service/apigateway/method_settings.go b/internal/service/apigateway/method_settings.go index 311e39d9a64..407446c5adb 100644 --- a/internal/service/apigateway/method_settings.go +++ b/internal/service/apigateway/method_settings.go @@ -9,13 +9,15 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "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" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "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" ) @@ -105,10 +107,10 @@ func ResourceMethodSettings() *schema.Resource { Computed: true, }, "unauthorized_cache_control_header_strategy": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(apigateway.UnauthorizedCacheControlHeaderStrategy_Values(), false), - Computed: true, + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[awstypes.UnauthorizedCacheControlHeaderStrategy](), + Computed: true, }, }, }, @@ -117,11 +119,7 @@ func ResourceMethodSettings() *schema.Resource { } } -func flattenMethodSettings(settings *apigateway.MethodSetting) []interface{} { - if settings == nil { - return nil - } - +func flattenMethodSettings(settings awstypes.MethodSetting) []interface{} { return []interface{}{ map[string]interface{}{ "metrics_enabled": settings.MetricsEnabled, @@ -140,7 +138,7 @@ func flattenMethodSettings(settings *apigateway.MethodSetting) []interface{} { func resourceMethodSettingsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) stage, err := FindStageByTwoPartKey(ctx, conn, d.Get("rest_api_id").(string), d.Get("stage_name").(string)) @@ -172,81 +170,81 @@ func resourceMethodSettingsRead(ctx context.Context, d *schema.ResourceData, met func resourceMethodSettingsUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) methodPath := d.Get("method_path").(string) prefix := fmt.Sprintf("/%s/", methodPath) - ops := make([]*apigateway.PatchOperation, 0) + ops := make([]awstypes.PatchOperation, 0) if d.HasChange("settings.0.metrics_enabled") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "metrics/enabled"), Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.metrics_enabled").(bool))), }) } if d.HasChange("settings.0.logging_level") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "logging/loglevel"), Value: aws.String(d.Get("settings.0.logging_level").(string)), }) } if d.HasChange("settings.0.data_trace_enabled") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "logging/dataTrace"), Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.data_trace_enabled").(bool))), }) } if d.HasChange("settings.0.throttling_burst_limit") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "throttling/burstLimit"), Value: aws.String(fmt.Sprintf("%d", d.Get("settings.0.throttling_burst_limit").(int))), }) } if d.HasChange("settings.0.throttling_rate_limit") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "throttling/rateLimit"), Value: aws.String(fmt.Sprintf("%f", d.Get("settings.0.throttling_rate_limit").(float64))), }) } if d.HasChange("settings.0.caching_enabled") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "caching/enabled"), Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.caching_enabled").(bool))), }) } if v, ok := d.GetOkExists("settings.0.cache_ttl_in_seconds"); ok { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "caching/ttlInSeconds"), Value: aws.String(fmt.Sprintf("%d", v.(int))), }) } if d.HasChange("settings.0.cache_data_encrypted") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "caching/dataEncrypted"), Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.cache_data_encrypted").(bool))), }) } if d.HasChange("settings.0.require_authorization_for_cache_control") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "caching/requireAuthorizationForCacheControl"), Value: aws.String(fmt.Sprintf("%t", d.Get("settings.0.require_authorization_for_cache_control").(bool))), }) } if d.HasChange("settings.0.unauthorized_cache_control_header_strategy") { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + "caching/unauthorizedCacheControlHeaderStrategy"), Value: aws.String(d.Get("settings.0.unauthorized_cache_control_header_strategy").(string)), }) @@ -259,9 +257,9 @@ func resourceMethodSettingsUpdate(ctx context.Context, d *schema.ResourceData, m StageName: aws.String(stageName), PatchOperations: ops, } - log.Printf("[DEBUG] Updating API Gateway Stage: %s", input) + log.Printf("[DEBUG] Updating API Gateway Stage: %+v", input) - _, err := conn.UpdateStageWithContext(ctx, &input) + _, err := conn.UpdateStage(ctx, &input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Stage failed: %s", err) @@ -274,27 +272,27 @@ func resourceMethodSettingsUpdate(ctx context.Context, d *schema.ResourceData, m func resourceMethodSettingsDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.UpdateStageInput{ RestApiId: aws.String(d.Get("rest_api_id").(string)), StageName: aws.String(d.Get("stage_name").(string)), - PatchOperations: []*apigateway.PatchOperation{ + PatchOperations: []awstypes.PatchOperation{ { - Op: aws.String(apigateway.OpRemove), + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/%s", d.Get("method_path").(string))), }, }, } - _, err := conn.UpdateStageWithContext(ctx, input) + _, err := conn.UpdateStage(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } // BadRequestException: Cannot remove method setting */* because there is no method setting for this method - if tfawserr.ErrMessageContains(err, apigateway.ErrCodeBadRequestException, "no method setting for this method") { + if errs.IsAErrorMessageContains[*awstypes.BadRequestException](err, "no method setting for this method") { return diags } diff --git a/internal/service/apigateway/method_settings_test.go b/internal/service/apigateway/method_settings_test.go index e7cb1b6bcd5..fef55a0139d 100644 --- a/internal/service/apigateway/method_settings_test.go +++ b/internal/service/apigateway/method_settings_test.go @@ -8,8 +8,8 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccAPIGatewayMethodSettings_basic(t *testing.T) { ctx := acctest.Context(t) - var stage apigateway.Stage + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -52,7 +52,7 @@ func TestAccAPIGatewayMethodSettings_basic(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_cacheDataEncrypted(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -90,7 +90,7 @@ func TestAccAPIGatewayMethodSettings_Settings_cacheDataEncrypted(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_cacheTTLInSeconds(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -136,7 +136,7 @@ func TestAccAPIGatewayMethodSettings_Settings_cacheTTLInSeconds(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_cachingEnabled(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -174,7 +174,7 @@ func TestAccAPIGatewayMethodSettings_Settings_cachingEnabled(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_dataTraceEnabled(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -212,7 +212,7 @@ func TestAccAPIGatewayMethodSettings_Settings_dataTraceEnabled(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_loggingLevel(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -252,7 +252,7 @@ func TestAccAPIGatewayMethodSettings_Settings_loggingLevel(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_metricsEnabled(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -292,7 +292,7 @@ func TestAccAPIGatewayMethodSettings_Settings_metricsEnabled(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_multiple(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -336,7 +336,7 @@ func TestAccAPIGatewayMethodSettings_Settings_multiple(t *testing.T) { func TestAccAPIGatewayMethodSettings_Settings_requireAuthorizationForCacheControl(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -374,7 +374,7 @@ func TestAccAPIGatewayMethodSettings_Settings_requireAuthorizationForCacheContro func TestAccAPIGatewayMethodSettings_Settings_throttlingBurstLimit(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -413,7 +413,7 @@ func TestAccAPIGatewayMethodSettings_Settings_throttlingBurstLimit(t *testing.T) // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/5690 func TestAccAPIGatewayMethodSettings_Settings_throttlingBurstLimitDisabledByDefault(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -451,7 +451,7 @@ func TestAccAPIGatewayMethodSettings_Settings_throttlingBurstLimitDisabledByDefa func TestAccAPIGatewayMethodSettings_Settings_throttlingRateLimit(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -490,7 +490,7 @@ func TestAccAPIGatewayMethodSettings_Settings_throttlingRateLimit(t *testing.T) // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/5690 func TestAccAPIGatewayMethodSettings_Settings_throttlingRateLimitDisabledByDefault(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -528,7 +528,7 @@ func TestAccAPIGatewayMethodSettings_Settings_throttlingRateLimitDisabledByDefau func TestAccAPIGatewayMethodSettings_Settings_unauthorizedCacheControlHeaderStrategy(t *testing.T) { ctx := acctest.Context(t) - var stage1, stage2 apigateway.Stage + var stage1, stage2 apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -564,33 +564,33 @@ func TestAccAPIGatewayMethodSettings_Settings_unauthorizedCacheControlHeaderStra }) } -func testAccCheckMethodSettings_metricsEnabled(conf *apigateway.Stage, path string, expected bool) resource.TestCheckFunc { +func testAccCheckMethodSettings_metricsEnabled(conf *apigateway.GetStageOutput, path string, expected bool) resource.TestCheckFunc { return func(s *terraform.State) error { settings, ok := conf.MethodSettings[path] if !ok { return fmt.Errorf("Expected to find method settings for %q", path) } - if expected && aws.BoolValue(settings.MetricsEnabled) != expected { - return fmt.Errorf("Expected metrics to be enabled, got %t", aws.BoolValue(settings.MetricsEnabled)) + if expected && settings.MetricsEnabled != expected { + return fmt.Errorf("Expected metrics to be enabled, got %t", settings.MetricsEnabled) } - if !expected && aws.BoolValue(settings.MetricsEnabled) != expected { - return fmt.Errorf("Expected metrics to be disabled, got %t", aws.BoolValue(settings.MetricsEnabled)) + if !expected && settings.MetricsEnabled != expected { + return fmt.Errorf("Expected metrics to be disabled, got %t", settings.MetricsEnabled) } return nil } } -func testAccCheckMethodSettings_loggingLevel(conf *apigateway.Stage, path string, expectedLevel string) resource.TestCheckFunc { +func testAccCheckMethodSettings_loggingLevel(conf *apigateway.GetStageOutput, path string, expectedLevel string) resource.TestCheckFunc { return func(s *terraform.State) error { settings, ok := conf.MethodSettings[path] if !ok { return fmt.Errorf("Expected to find method settings for %q", path) } - if aws.StringValue(settings.LoggingLevel) != expectedLevel { - return fmt.Errorf("Expected logging level to match %q, got %q", expectedLevel, aws.StringValue(settings.LoggingLevel)) + if aws.ToString(settings.LoggingLevel) != expectedLevel { + return fmt.Errorf("Expected logging level to match %q, got %q", expectedLevel, aws.ToString(settings.LoggingLevel)) } return nil @@ -599,7 +599,7 @@ func testAccCheckMethodSettings_loggingLevel(conf *apigateway.Stage, path string func TestAccAPIGatewayMethodSettings_disappears(t *testing.T) { ctx := acctest.Context(t) - var stage apigateway.Stage + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method_settings.test" @@ -623,7 +623,7 @@ func TestAccAPIGatewayMethodSettings_disappears(t *testing.T) { func testAccCheckMethodSettingsDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_method_settings" { diff --git a/internal/service/apigateway/method_test.go b/internal/service/apigateway/method_test.go index 0daa36152d8..be7ac100c7f 100644 --- a/internal/service/apigateway/method_test.go +++ b/internal/service/apigateway/method_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayMethod_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Method + var conf apigateway.GetMethodOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method.test" @@ -68,7 +68,7 @@ func TestAccAPIGatewayMethod_basic(t *testing.T) { func TestAccAPIGatewayMethod_customAuthorizer(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Method + var conf apigateway.GetMethodOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method.test" @@ -107,7 +107,7 @@ func TestAccAPIGatewayMethod_customAuthorizer(t *testing.T) { func TestAccAPIGatewayMethod_cognitoAuthorizer(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Method + var conf apigateway.GetMethodOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method.test" @@ -148,7 +148,7 @@ func TestAccAPIGatewayMethod_cognitoAuthorizer(t *testing.T) { func TestAccAPIGatewayMethod_customRequestValidator(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Method + var conf apigateway.GetMethodOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method.test" @@ -185,7 +185,7 @@ func TestAccAPIGatewayMethod_customRequestValidator(t *testing.T) { func TestAccAPIGatewayMethod_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Method + var conf apigateway.GetMethodOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method.test" @@ -209,7 +209,7 @@ func TestAccAPIGatewayMethod_disappears(t *testing.T) { func TestAccAPIGatewayMethod_operationName(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Method + var conf apigateway.GetMethodOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_method.test" @@ -243,7 +243,7 @@ func TestAccAPIGatewayMethod_operationName(t *testing.T) { }) } -func testAccCheckMethodExists(ctx context.Context, n string, v *apigateway.Method) resource.TestCheckFunc { +func testAccCheckMethodExists(ctx context.Context, n string, v *apigateway.GetMethodOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -254,7 +254,7 @@ func testAccCheckMethodExists(ctx context.Context, n string, v *apigateway.Metho return fmt.Errorf("No API Gateway Method ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindMethodByThreePartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes["resource_id"], rs.Primary.Attributes["rest_api_id"]) @@ -270,7 +270,7 @@ func testAccCheckMethodExists(ctx context.Context, n string, v *apigateway.Metho func testAccCheckMethodDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_method" { diff --git a/internal/service/apigateway/model.go b/internal/service/apigateway/model.go index fb1979578b6..32a1563258c 100644 --- a/internal/service/apigateway/model.go +++ b/internal/service/apigateway/model.go @@ -9,15 +9,16 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/structure" "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" @@ -42,9 +43,9 @@ func ResourceModel() *schema.Resource { d.Set("name", name) d.Set("rest_api_id", restApiID) - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - output, err := conn.GetModelWithContext(ctx, &apigateway.GetModelInput{ + output, err := conn.GetModel(ctx, &apigateway.GetModelInput{ ModelName: aws.String(name), RestApiId: aws.String(restApiID), }) @@ -53,7 +54,7 @@ func ResourceModel() *schema.Resource { return nil, err } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return []*schema.ResourceData{d}, nil }, @@ -95,7 +96,7 @@ func ResourceModel() *schema.Resource { func resourceModelCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) name := d.Get("name").(string) input := &apigateway.CreateModelInput{ @@ -112,20 +113,20 @@ func resourceModelCreate(ctx context.Context, d *schema.ResourceData, meta inter input.Schema = aws.String(v.(string)) } - output, err := conn.CreateModelWithContext(ctx, input) + output, err := conn.CreateModel(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Model (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return diags } func resourceModelRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) model, err := FindModelByTwoPartKey(ctx, conn, d.Get("name").(string), d.Get("rest_api_id").(string)) @@ -148,21 +149,21 @@ func resourceModelRead(ctx context.Context, d *schema.ResourceData, meta interfa func resourceModelUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) } if d.HasChange("schema") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/schema"), Value: aws.String(d.Get("schema").(string)), }) @@ -174,7 +175,7 @@ func resourceModelUpdate(ctx context.Context, d *schema.ResourceData, meta inter RestApiId: aws.String(d.Get("rest_api_id").(string)), } - _, err := conn.UpdateModelWithContext(ctx, input) + _, err := conn.UpdateModel(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Model (%s): %s", d.Id(), err) @@ -185,15 +186,15 @@ func resourceModelUpdate(ctx context.Context, d *schema.ResourceData, meta inter func resourceModelDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Model: %s", d.Id()) - _, err := conn.DeleteModelWithContext(ctx, &apigateway.DeleteModelInput{ + _, err := conn.DeleteModel(ctx, &apigateway.DeleteModelInput{ ModelName: aws.String(d.Get("name").(string)), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -204,15 +205,15 @@ func resourceModelDelete(ctx context.Context, d *schema.ResourceData, meta inter return diags } -func FindModelByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, name, apiID string) (*apigateway.Model, error) { +func FindModelByTwoPartKey(ctx context.Context, conn *apigateway.Client, name, apiID string) (*apigateway.GetModelOutput, error) { input := &apigateway.GetModelInput{ ModelName: aws.String(name), RestApiId: aws.String(apiID), } - output, err := conn.GetModelWithContext(ctx, input) + output, err := conn.GetModel(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/model_test.go b/internal/service/apigateway/model_test.go index 2327982b783..f89e359e279 100644 --- a/internal/service/apigateway/model_test.go +++ b/internal/service/apigateway/model_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayModel_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Model + var conf apigateway.GetModelOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) modelName := sdkacctest.RandString(16) resourceName := "aws_api_gateway_model.test" @@ -53,7 +53,7 @@ func TestAccAPIGatewayModel_basic(t *testing.T) { func TestAccAPIGatewayModel_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Model + var conf apigateway.GetModelOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) modelName := sdkacctest.RandString(16) resourceName := "aws_api_gateway_model.test" @@ -76,7 +76,7 @@ func TestAccAPIGatewayModel_disappears(t *testing.T) { }) } -func testAccCheckModelExists(ctx context.Context, n string, v *apigateway.Model) resource.TestCheckFunc { +func testAccCheckModelExists(ctx context.Context, n string, v *apigateway.GetModelOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -87,7 +87,7 @@ func testAccCheckModelExists(ctx context.Context, n string, v *apigateway.Model) return fmt.Errorf("No API Gateway Model ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindModelByTwoPartKey(ctx, conn, rs.Primary.Attributes["name"], rs.Primary.Attributes["rest_api_id"]) @@ -103,7 +103,7 @@ func testAccCheckModelExists(ctx context.Context, n string, v *apigateway.Model) func testAccCheckModelDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_model" { diff --git a/internal/service/apigateway/request_validator.go b/internal/service/apigateway/request_validator.go index 6d61379d050..e0227d42395 100644 --- a/internal/service/apigateway/request_validator.go +++ b/internal/service/apigateway/request_validator.go @@ -9,13 +9,14 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" ) @@ -68,30 +69,30 @@ func ResourceRequestValidator() *schema.Resource { func resourceRequestValidatorCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) name := d.Get("name").(string) input := &apigateway.CreateRequestValidatorInput{ Name: aws.String(name), RestApiId: aws.String(d.Get("rest_api_id").(string)), - ValidateRequestBody: aws.Bool(d.Get("validate_request_body").(bool)), - ValidateRequestParameters: aws.Bool(d.Get("validate_request_parameters").(bool)), + ValidateRequestBody: d.Get("validate_request_body").(bool), + ValidateRequestParameters: d.Get("validate_request_parameters").(bool), } - output, err := conn.CreateRequestValidatorWithContext(ctx, input) + output, err := conn.CreateRequestValidator(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Request Validator (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return diags } func resourceRequestValidatorRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) output, err := FindRequestValidatorByTwoPartKey(ctx, conn, d.Id(), d.Get("rest_api_id").(string)) @@ -114,29 +115,29 @@ func resourceRequestValidatorRead(ctx context.Context, d *schema.ResourceData, m func resourceRequestValidatorUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/name"), Value: aws.String(d.Get("name").(string)), }) } if d.HasChange("validate_request_body") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/validateRequestBody"), Value: aws.String(fmt.Sprintf("%t", d.Get("validate_request_body").(bool))), }) } if d.HasChange("validate_request_parameters") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/validateRequestParameters"), Value: aws.String(fmt.Sprintf("%t", d.Get("validate_request_parameters").(bool))), }) @@ -148,7 +149,7 @@ func resourceRequestValidatorUpdate(ctx context.Context, d *schema.ResourceData, PatchOperations: operations, } - _, err := conn.UpdateRequestValidatorWithContext(ctx, input) + _, err := conn.UpdateRequestValidator(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Request Validator (%s): %s", d.Id(), err) @@ -159,10 +160,10 @@ func resourceRequestValidatorUpdate(ctx context.Context, d *schema.ResourceData, func resourceRequestValidatorDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Request Validator: %s", d.Id()) - _, err := conn.DeleteRequestValidatorWithContext(ctx, &apigateway.DeleteRequestValidatorInput{ + _, err := conn.DeleteRequestValidator(ctx, &apigateway.DeleteRequestValidatorInput{ RequestValidatorId: aws.String(d.Id()), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) @@ -170,7 +171,7 @@ func resourceRequestValidatorDelete(ctx context.Context, d *schema.ResourceData, if err != nil { // XXX: Figure out a way to delete the method that depends on the request validator first // otherwise the validator will be dangling until the API is deleted - if !strings.Contains(err.Error(), apigateway.ErrCodeConflictException) { + if errs.IsA[*awstypes.ConflictException](err) { return sdkdiag.AppendErrorf(diags, "deleting API Gateway Request Validator (%s): %s", d.Id(), err) } } @@ -178,15 +179,15 @@ func resourceRequestValidatorDelete(ctx context.Context, d *schema.ResourceData, return diags } -func FindRequestValidatorByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, requestValidatorID, apiID string) (*apigateway.UpdateRequestValidatorOutput, error) { +func FindRequestValidatorByTwoPartKey(ctx context.Context, conn *apigateway.Client, requestValidatorID, apiID string) (*apigateway.GetRequestValidatorOutput, error) { input := &apigateway.GetRequestValidatorInput{ RequestValidatorId: aws.String(requestValidatorID), RestApiId: aws.String(apiID), } - output, err := conn.GetRequestValidatorWithContext(ctx, input) + output, err := conn.GetRequestValidator(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/request_validator_test.go b/internal/service/apigateway/request_validator_test.go index 2e13cd1ed91..3645dd8dcfe 100644 --- a/internal/service/apigateway/request_validator_test.go +++ b/internal/service/apigateway/request_validator_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayRequestValidator_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UpdateRequestValidatorOutput + var conf apigateway.GetRequestValidatorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_request_validator.test" @@ -61,7 +61,7 @@ func TestAccAPIGatewayRequestValidator_basic(t *testing.T) { func TestAccAPIGatewayRequestValidator_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UpdateRequestValidatorOutput + var conf apigateway.GetRequestValidatorOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_request_validator.test" @@ -83,7 +83,7 @@ func TestAccAPIGatewayRequestValidator_disappears(t *testing.T) { }) } -func testAccCheckRequestValidatorExists(ctx context.Context, n string, v *apigateway.UpdateRequestValidatorOutput) resource.TestCheckFunc { +func testAccCheckRequestValidatorExists(ctx context.Context, n string, v *apigateway.GetRequestValidatorOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -94,7 +94,7 @@ func testAccCheckRequestValidatorExists(ctx context.Context, n string, v *apigat return fmt.Errorf("No API Gateway Request Validator ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindRequestValidatorByTwoPartKey(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["rest_api_id"]) @@ -110,7 +110,7 @@ func testAccCheckRequestValidatorExists(ctx context.Context, n string, v *apigat func testAccCheckRequestValidatorDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_request_validator" { diff --git a/internal/service/apigateway/resource.go b/internal/service/apigateway/resource.go index a7b07582a5c..ba1cad7e67a 100644 --- a/internal/service/apigateway/resource.go +++ b/internal/service/apigateway/resource.go @@ -9,13 +9,14 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" ) @@ -66,7 +67,7 @@ func ResourceResource() *schema.Resource { func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.CreateResourceInput{ ParentId: aws.String(d.Get("parent_id").(string)), @@ -74,20 +75,20 @@ func resourceResourceCreate(ctx context.Context, d *schema.ResourceData, meta in RestApiId: aws.String(d.Get("rest_api_id").(string)), } - output, err := conn.CreateResourceWithContext(ctx, input) + output, err := conn.CreateResource(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Resource: %s", err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return append(diags, resourceResourceRead(ctx, d, meta)...) } func resourceResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) resource, err := FindResourceByTwoPartKey(ctx, conn, d.Id(), d.Get("rest_api_id").(string)) @@ -108,19 +109,19 @@ func resourceResourceRead(ctx context.Context, d *schema.ResourceData, meta inte return diags } -func resourceResourceUpdateOperations(d *schema.ResourceData) []*apigateway.PatchOperation { - operations := make([]*apigateway.PatchOperation, 0) +func resourceResourceUpdateOperations(d *schema.ResourceData) []awstypes.PatchOperation { + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("path_part") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/pathPart"), Value: aws.String(d.Get("path_part").(string)), }) } if d.HasChange("parent_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/parentId"), Value: aws.String(d.Get("parent_id").(string)), }) @@ -130,7 +131,7 @@ func resourceResourceUpdateOperations(d *schema.ResourceData) []*apigateway.Patc func resourceResourceUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.UpdateResourceInput{ ResourceId: aws.String(d.Id()), @@ -138,7 +139,7 @@ func resourceResourceUpdate(ctx context.Context, d *schema.ResourceData, meta in PatchOperations: resourceResourceUpdateOperations(d), } - _, err := conn.UpdateResourceWithContext(ctx, input) + _, err := conn.UpdateResource(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Resource (%s): %s", d.Id(), err) @@ -149,15 +150,15 @@ func resourceResourceUpdate(ctx context.Context, d *schema.ResourceData, meta in func resourceResourceDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Resource: %s", d.Id()) - _, err := conn.DeleteResourceWithContext(ctx, &apigateway.DeleteResourceInput{ + _, err := conn.DeleteResource(ctx, &apigateway.DeleteResourceInput{ ResourceId: aws.String(d.Id()), RestApiId: aws.String(d.Get("rest_api_id").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -168,15 +169,15 @@ func resourceResourceDelete(ctx context.Context, d *schema.ResourceData, meta in return diags } -func FindResourceByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, resourceID, apiID string) (*apigateway.Resource, error) { +func FindResourceByTwoPartKey(ctx context.Context, conn *apigateway.Client, resourceID, apiID string) (*apigateway.GetResourceOutput, error) { input := &apigateway.GetResourceInput{ ResourceId: aws.String(resourceID), RestApiId: aws.String(apiID), } - output, err := conn.GetResourceWithContext(ctx, input) + output, err := conn.GetResource(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/resource_data_source.go b/internal/service/apigateway/resource_data_source.go index bf36dc30605..e04751f4d23 100644 --- a/internal/service/apigateway/resource_data_source.go +++ b/internal/service/apigateway/resource_data_source.go @@ -7,12 +7,14 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/sdkdiag" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // @SDKDataSource("aws_api_gateway_resource") @@ -42,32 +44,36 @@ func DataSourceResource() *schema.Resource { func dataSourceResourceRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restApiId := d.Get("rest_api_id").(string) target := d.Get("path").(string) params := &apigateway.GetResourcesInput{RestApiId: aws.String(restApiId)} - var match *apigateway.Resource - log.Printf("[DEBUG] Reading API Gateway Resources: %s", params) - err := conn.GetResourcesPagesWithContext(ctx, params, func(page *apigateway.GetResourcesOutput, lastPage bool) bool { + var resources []awstypes.Resource + log.Printf("[DEBUG] Reading API Gateway Resources: %+v", params) + + pages := apigateway.NewGetResourcesPaginator(conn, params) + + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + return sdkdiag.AppendErrorf(diags, "describing API Gateway Resources: %s", err) + } + for _, resource := range page.Items { - if aws.StringValue(resource.Path) == target { - match = resource - return false + if aws.ToString(resource.Path) == target { + resources = append(resources, resource) } } - return !lastPage - }) - if err != nil { - return sdkdiag.AppendErrorf(diags, "describing API Gateway Resources: %s", err) } - if match == nil { + match, err := tfresource.AssertSingleValueResult(resources) + if err != nil { return sdkdiag.AppendErrorf(diags, "no Resources with path %q found for rest api %q", target, restApiId) } - d.SetId(aws.StringValue(match.Id)) + d.SetId(aws.ToString(match.Id)) d.Set("path_part", match.PathPart) d.Set("parent_id", match.ParentId) diff --git a/internal/service/apigateway/resource_test.go b/internal/service/apigateway/resource_test.go index 9663a5fdd2d..8cafdb2a635 100644 --- a/internal/service/apigateway/resource_test.go +++ b/internal/service/apigateway/resource_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayResource_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Resource + var conf apigateway.GetResourceOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_resource.test" @@ -51,7 +51,7 @@ func TestAccAPIGatewayResource_basic(t *testing.T) { func TestAccAPIGatewayResource_update(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Resource + var conf apigateway.GetResourceOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_resource.test" @@ -89,7 +89,7 @@ func TestAccAPIGatewayResource_update(t *testing.T) { func TestAccAPIGatewayResource_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Resource + var conf apigateway.GetResourceOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_resource.test" @@ -111,7 +111,7 @@ func TestAccAPIGatewayResource_disappears(t *testing.T) { }) } -func testAccCheckResourceExists(ctx context.Context, n string, v *apigateway.Resource) resource.TestCheckFunc { +func testAccCheckResourceExists(ctx context.Context, n string, v *apigateway.GetResourceOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -122,7 +122,7 @@ func testAccCheckResourceExists(ctx context.Context, n string, v *apigateway.Res return fmt.Errorf("No API Gateway Resource ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindResourceByTwoPartKey(ctx, conn, rs.Primary.ID, rs.Primary.Attributes["rest_api_id"]) @@ -138,7 +138,7 @@ func testAccCheckResourceExists(ctx context.Context, n string, v *apigateway.Res func testAccCheckResourceDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_resource" { diff --git a/internal/service/apigateway/rest_api.go b/internal/service/apigateway/rest_api.go index 9c53b7f3441..e6b336bfeef 100644 --- a/internal/service/apigateway/rest_api.go +++ b/internal/service/apigateway/rest_api.go @@ -10,10 +10,10 @@ import ( "strconv" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" awspolicy "github.com/hashicorp/awspolicyequivalence" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" @@ -21,6 +21,8 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/hashicorp/terraform-provider-aws/internal/conns" + "github.com/hashicorp/terraform-provider-aws/internal/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -41,17 +43,17 @@ func ResourceRestAPI() *schema.Resource { Importer: &schema.ResourceImporter{ StateContext: func(ctx context.Context, d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) { - d.Set("put_rest_api_mode", apigateway.PutModeOverwrite) + d.Set("put_rest_api_mode", awstypes.PutModeOverwrite) return []*schema.ResourceData{d}, nil }, }, Schema: map[string]*schema.Schema{ "api_key_source": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice(apigateway.ApiKeySourceType_Values(), false), + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateDiagFunc: enum.Validate[awstypes.ApiKeySourceType](), }, "arn": { Type: schema.TypeString, @@ -95,8 +97,8 @@ func ResourceRestAPI() *schema.Resource { MinItems: 1, MaxItems: 1, Elem: &schema.Schema{ - Type: schema.TypeString, - ValidateFunc: validation.StringInSlice(apigateway.EndpointType_Values(), false), + Type: schema.TypeString, + ValidateDiagFunc: enum.Validate[awstypes.EndpointType](), }, }, "vpc_endpoint_ids": { @@ -151,12 +153,12 @@ func ResourceRestAPI() *schema.Resource { }, }, "put_rest_api_mode": { - Type: schema.TypeString, - Optional: true, - Default: apigateway.PutModeOverwrite, - ValidateFunc: validation.StringInSlice(apigateway.PutMode_Values(), false), + Type: schema.TypeString, + Optional: true, + Default: awstypes.PutModeOverwrite, + ValidateDiagFunc: enum.Validate[awstypes.PutMode](), DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - if old == "" && new == apigateway.PutModeOverwrite { + if old == "" && new == string(awstypes.PutModeOverwrite) { return true } return false @@ -176,7 +178,7 @@ func ResourceRestAPI() *schema.Resource { func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) name := d.Get("name").(string) input := &apigateway.CreateRestApiInput{ @@ -185,11 +187,11 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("api_key_source"); ok { - input.ApiKeySource = aws.String(v.(string)) + input.ApiKeySource = awstypes.ApiKeySourceType(v.(string)) } if v, ok := d.GetOk("binary_media_types"); ok { - input.BinaryMediaTypes = flex.ExpandStringList(v.([]interface{})) + input.BinaryMediaTypes = flex.ExpandStringValueList(v.([]interface{})) } if v, ok := d.GetOk("description"); ok { @@ -197,7 +199,7 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int } if v, ok := d.GetOk("disable_execute_api_endpoint"); ok { - input.DisableExecuteApiEndpoint = aws.Bool(v.(bool)) + input.DisableExecuteApiEndpoint = v.(bool) } if v, ok := d.GetOk("endpoint_configuration"); ok { @@ -209,7 +211,7 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int if err != nil { return sdkdiag.AppendErrorf(diags, "converting minimum_compression_size (%s): %s", v, err) } - input.MinimumCompressionSize = aws.Int64(int64(mcs)) + input.MinimumCompressionSize = aws.Int32(int32(mcs)) } if v, ok := d.GetOk("policy"); ok { @@ -221,13 +223,13 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int input.Policy = aws.String(policy) } - output, err := conn.CreateRestApiWithContext(ctx, input) + output, err := conn.CreateRestApi(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway REST API (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) if body, ok := d.GetOk("body"); ok { // Terraform implementation uses the `overwrite` mode by default. @@ -237,19 +239,19 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int // The `merge` mode will not delete literal properties of a RestApi if they’re not explicitly set in the OAS definition. input := &apigateway.PutRestApiInput{ Body: []byte(body.(string)), - Mode: aws.String(modeConfigOrDefault(d)), + Mode: awstypes.PutMode(modeConfigOrDefault(d)), RestApiId: aws.String(d.Id()), } if v, ok := d.GetOk("fail_on_warnings"); ok { - input.FailOnWarnings = aws.Bool(v.(bool)) + input.FailOnWarnings = v.(bool) } if v, ok := d.GetOk("parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.Parameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.Parameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } - api, err := conn.PutRestApiWithContext(ctx, input) + api, err := conn.PutRestApi(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway REST API (%s) specification: %s", d.Id(), err) @@ -264,7 +266,7 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int RestApiId: aws.String(d.Id()), } - _, err := conn.UpdateRestApiWithContext(ctx, input) + _, err := conn.UpdateRestApi(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway REST API (%s) after OpenAPI import: %s", d.Id(), err) @@ -277,11 +279,11 @@ func resourceRestAPICreate(ctx context.Context, d *schema.ResourceData, meta int func resourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) api, err := FindRESTAPIByID(ctx, conn, d.Id()) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] API Gateway REST API (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -291,29 +293,7 @@ func resourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta inter return sdkdiag.AppendErrorf(diags, "reading API Gateway REST API (%s): %s", d.Id(), err) } - input := &apigateway.GetResourcesInput{ - RestApiId: aws.String(d.Id()), - } - - err = conn.GetResourcesPagesWithContext(ctx, input, func(page *apigateway.GetResourcesOutput, lastPage bool) bool { - if page == nil { - return !lastPage - } - - for _, v := range page.Items { - if aws.StringValue(v.Path) == "/" { - d.Set("root_resource_id", v.Id) - return false - } - } - - return !lastPage - }) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "reading API Gateway REST API (%s) resources: %s", d.Id(), err) - } - + d.Set("root_resource_id", api.RootResourceId) d.Set("api_key_source", api.ApiKeySource) apiARN := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, @@ -340,7 +320,7 @@ func resourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta inter if api.MinimumCompressionSize == nil { d.Set("minimum_compression_size", nil) } else { - d.Set("minimum_compression_size", strconv.FormatInt(aws.Int64Value(api.MinimumCompressionSize), 10)) + d.Set("minimum_compression_size", strconv.FormatInt(int64(aws.ToInt32(api.MinimumCompressionSize)), 10)) } d.Set("name", api.Name) @@ -350,7 +330,7 @@ func resourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta inter // forward slashes in CIDR blocks, which will break strconv.Unquote // I'm not sure why it needs to be wrapped with double quotes first, but it does - normalized_policy, err := structure.NormalizeJsonString(`"` + aws.StringValue(api.Policy) + `"`) + normalized_policy, err := structure.NormalizeJsonString(`"` + aws.ToString(api.Policy) + `"`) if err != nil { return sdkdiag.AppendErrorf(diags, "normalizing policy JSON: %s", err) } @@ -375,14 +355,14 @@ func resourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) if d.HasChangesExcept("tags", "tags_all") { - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("api_key_source") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/apiKeySource"), Value: aws.String(d.Get("api_key_source").(string)), }) @@ -399,8 +379,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int // since there are no replacings. for _, v := range old { if e, ok := v.(string); ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, escapeJSONPointer(e))), }) } @@ -410,8 +390,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int if len(new) > 0 { for _, v := range new { if e, ok := v.(string); ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(fmt.Sprintf("/%s/%s", prefix, escapeJSONPointer(e))), }) } @@ -420,8 +400,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int } if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) @@ -429,8 +409,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int if d.HasChange("disable_execute_api_endpoint") { value := strconv.FormatBool(d.Get("disable_execute_api_endpoint").(bool)) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/disableExecuteApiEndpoint"), Value: aws.String(value), }) @@ -442,8 +422,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int if v, ok := d.GetOk("endpoint_configuration"); ok && len(v.([]interface{})) > 0 { m := v.([]interface{})[0].(map[string]interface{}) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/endpointConfiguration/types/0"), Value: aws.String(m["types"].([]interface{})[0].(string)), }) @@ -464,8 +444,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int break } } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(prefix), Value: aws.String(v.(string)), }) @@ -477,8 +457,8 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int break } } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(prefix), Value: aws.String(v.(string)), }) @@ -491,16 +471,16 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int if v == "-1" { value = nil } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/minimumCompressionSize"), Value: value, }) } if d.HasChange("name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/name"), Value: aws.String(d.Get("name").(string)), }) @@ -509,15 +489,15 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int if d.HasChange("policy") { policy, _ := structure.NormalizeJsonString(d.Get("policy").(string)) // validation covers error - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/policy"), Value: aws.String(policy), }) } if len(operations) > 0 { - _, err := conn.UpdateRestApiWithContext(ctx, &apigateway.UpdateRestApiInput{ + _, err := conn.UpdateRestApi(ctx, &apigateway.UpdateRestApiInput{ PatchOperations: operations, RestApiId: aws.String(d.Id()), }) @@ -536,19 +516,19 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int // The `merge` mode will not delete literal properties of a RestApi if they’re not explicitly set in the OAS definition. input := &apigateway.PutRestApiInput{ Body: []byte(body.(string)), - Mode: aws.String(modeConfigOrDefault(d)), + Mode: awstypes.PutMode(modeConfigOrDefault(d)), RestApiId: aws.String(d.Id()), } if v, ok := d.GetOk("fail_on_warnings"); ok { - input.FailOnWarnings = aws.Bool(v.(bool)) + input.FailOnWarnings = v.(bool) } if v, ok := d.GetOk("parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.Parameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.Parameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } - output, err := conn.PutRestApiWithContext(ctx, input) + output, err := conn.PutRestApi(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway REST API (%s) specification: %s", d.Id(), err) @@ -563,7 +543,7 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int RestApiId: aws.String(d.Id()), } - _, err := conn.UpdateRestApiWithContext(ctx, input) + _, err := conn.UpdateRestApi(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway REST API (%s) after OpenAPI import: %s", d.Id(), err) @@ -578,14 +558,14 @@ func resourceRestAPIUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceRestAPIDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway REST API: %s", d.Id()) - _, err := conn.DeleteRestApiWithContext(ctx, &apigateway.DeleteRestApiInput{ + _, err := conn.DeleteRestApi(ctx, &apigateway.DeleteRestApiInput{ RestApiId: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -596,14 +576,14 @@ func resourceRestAPIDelete(ctx context.Context, d *schema.ResourceData, meta int return diags } -func FindRESTAPIByID(ctx context.Context, conn *apigateway.APIGateway, id string) (*apigateway.RestApi, error) { +func FindRESTAPIByID(ctx context.Context, conn *apigateway.Client, id string) (*apigateway.GetRestApiOutput, error) { input := &apigateway.GetRestApiInput{ RestApiId: aws.String(id), } - output, err := conn.GetRestApiWithContext(ctx, input) + output, err := conn.GetRestApi(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -621,12 +601,12 @@ func FindRESTAPIByID(ctx context.Context, conn *apigateway.APIGateway, id string return output, nil } -func resourceRestAPIWithBodyUpdateOperations(d *schema.ResourceData, output *apigateway.RestApi) []*apigateway.PatchOperation { - operations := make([]*apigateway.PatchOperation, 0) +func resourceRestAPIWithBodyUpdateOperations(d *schema.ResourceData, output *apigateway.PutRestApiOutput) []awstypes.PatchOperation { + operations := make([]awstypes.PatchOperation, 0) - if v, ok := d.GetOk("api_key_source"); ok && v.(string) != aws.StringValue(output.ApiKeySource) { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + if v, ok := d.GetOk("api_key_source"); ok && v.(string) != string(output.ApiKeySource) { + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/apiKeySource"), Value: aws.String(v.(string)), }) @@ -634,9 +614,9 @@ func resourceRestAPIWithBodyUpdateOperations(d *schema.ResourceData, output *api if v, ok := d.GetOk("binary_media_types"); ok && len(v.([]interface{})) > 0 { if len(output.BinaryMediaTypes) > 0 { - for _, elem := range aws.StringValueSlice(output.BinaryMediaTypes) { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + for _, elem := range output.BinaryMediaTypes { + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/binaryMediaTypes/" + escapeJSONPointer(elem)), }) } @@ -644,25 +624,25 @@ func resourceRestAPIWithBodyUpdateOperations(d *schema.ResourceData, output *api for _, elem := range v.([]interface{}) { if el, ok := elem.(string); ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/binaryMediaTypes/" + escapeJSONPointer(el)), }) } } } - if v, ok := d.GetOk("description"); ok && v.(string) != aws.StringValue(output.Description) { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + if v, ok := d.GetOk("description"); ok && v.(string) != aws.ToString(output.Description) { + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(v.(string)), }) } - if v, ok := d.GetOk("disable_execute_api_endpoint"); ok && v.(bool) != aws.BoolValue(output.DisableExecuteApiEndpoint) { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + if v, ok := d.GetOk("disable_execute_api_endpoint"); ok && v.(bool) != output.DisableExecuteApiEndpoint { + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/disableExecuteApiEndpoint"), Value: aws.String(strconv.FormatBool(v.(bool))), }) @@ -676,59 +656,59 @@ func resourceRestAPIWithBodyUpdateOperations(d *schema.ResourceData, output *api if output.EndpointConfiguration != nil { for _, v := range output.EndpointConfiguration.VpcEndpointIds { for _, x := range endpointConfiguration.VpcEndpointIds { - if aws.StringValue(v) == aws.StringValue(x) { + if v == x { break } } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(prefix), - Value: v, + Value: aws.String(v), }) } } for _, v := range endpointConfiguration.VpcEndpointIds { for _, x := range output.EndpointConfiguration.VpcEndpointIds { - if aws.StringValue(v) == aws.StringValue(x) { + if v == x { break } } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String(prefix), - Value: v, + Value: aws.String(v), }) } } } - if v, ok := d.GetOk("minimum_compression_size"); ok && v.(string) != strconv.FormatInt(aws.Int64Value(output.MinimumCompressionSize), 10) { + if v, ok := d.GetOk("minimum_compression_size"); ok && v.(string) != strconv.FormatInt(int64(aws.ToInt32(output.MinimumCompressionSize)), 10) { value := aws.String(v.(string)) if v.(string) == "-1" { value = nil } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/minimumCompressionSize"), Value: value, }) } - if v, ok := d.GetOk("name"); ok && v.(string) != aws.StringValue(output.Name) { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + if v, ok := d.GetOk("name"); ok && v.(string) != aws.ToString(output.Name) { + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/name"), Value: aws.String(v.(string)), }) } if v, ok := d.GetOk("policy"); ok { - if equivalent, err := awspolicy.PoliciesAreEquivalent(v.(string), aws.StringValue(output.Policy)); err != nil || !equivalent { + if equivalent, err := awspolicy.PoliciesAreEquivalent(v.(string), aws.ToString(output.Policy)); err != nil || !equivalent { policy, _ := structure.NormalizeJsonString(v.(string)) // validation covers error - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/policy"), Value: aws.String(policy), }) @@ -742,39 +722,39 @@ func modeConfigOrDefault(d *schema.ResourceData) string { if v, ok := d.GetOk("put_rest_api_mode"); ok { return v.(string) } else { - return apigateway.PutModeOverwrite + return string(awstypes.PutModeOverwrite) } } -func expandEndpointConfiguration(l []interface{}) *apigateway.EndpointConfiguration { +func expandEndpointConfiguration(l []interface{}) *awstypes.EndpointConfiguration { if len(l) == 0 { return nil } m := l[0].(map[string]interface{}) - endpointConfiguration := &apigateway.EndpointConfiguration{ - Types: flex.ExpandStringList(m["types"].([]interface{})), + endpointConfiguration := &awstypes.EndpointConfiguration{ + Types: flex.ExpandStringyValueList[awstypes.EndpointType](m["types"].([]interface{})), } if endpointIds, ok := m["vpc_endpoint_ids"]; ok { - endpointConfiguration.VpcEndpointIds = flex.ExpandStringSet(endpointIds.(*schema.Set)) + endpointConfiguration.VpcEndpointIds = flex.ExpandStringValueSet(endpointIds.(*schema.Set)) } return endpointConfiguration } -func flattenEndpointConfiguration(endpointConfiguration *apigateway.EndpointConfiguration) []interface{} { +func flattenEndpointConfiguration(endpointConfiguration *awstypes.EndpointConfiguration) []interface{} { if endpointConfiguration == nil { return []interface{}{} } m := map[string]interface{}{ - "types": flex.FlattenStringList(endpointConfiguration.Types), + "types": endpointConfiguration.Types, } if len(endpointConfiguration.VpcEndpointIds) > 0 { - m["vpc_endpoint_ids"] = aws.StringValueSlice(endpointConfiguration.VpcEndpointIds) + m["vpc_endpoint_ids"] = endpointConfiguration.VpcEndpointIds } return []interface{}{m} diff --git a/internal/service/apigateway/rest_api_data_source.go b/internal/service/apigateway/rest_api_data_source.go index 37f0a500e20..979ba5cc200 100644 --- a/internal/service/apigateway/rest_api_data_source.go +++ b/internal/service/apigateway/rest_api_data_source.go @@ -9,14 +9,16 @@ import ( "log" "strconv" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/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/types/nullable" ) @@ -87,36 +89,34 @@ func DataSourceRestAPI() *schema.Resource { func dataSourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &apigateway.GetRestApisInput{} target := d.Get("name") - var matchedApis []*apigateway.RestApi - log.Printf("[DEBUG] Reading API Gateway REST APIs: %s", params) - err := conn.GetRestApisPagesWithContext(ctx, params, func(page *apigateway.GetRestApisOutput, lastPage bool) bool { + var matchedApis []awstypes.RestApi + log.Printf("[DEBUG] Reading API Gateway REST APIs: %+v", params) + pages := apigateway.NewGetRestApisPaginator(conn, params) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + return sdkdiag.AppendErrorf(diags, "describing API Gateway REST APIs: %s", err) + } + for _, api := range page.Items { - if aws.StringValue(api.Name) == target { + if aws.ToString(api.Name) == target { matchedApis = append(matchedApis, api) } } - return !lastPage - }) - if err != nil { - return sdkdiag.AppendErrorf(diags, "describing API Gateway REST APIs: %s", err) } - if len(matchedApis) == 0 { - return sdkdiag.AppendErrorf(diags, "no REST APIs with name %q found in this region", target) - } - if len(matchedApis) > 1 { - return sdkdiag.AppendErrorf(diags, "multiple REST APIs with name %q found in this region", target) + match, err := tfresource.AssertSingleValueResult(matchedApis) + if err != nil { + return sdkdiag.AppendErrorf(diags, "Exactly one API Gateway REST API not found with name: %s", target) } - match := matchedApis[0] - - d.SetId(aws.StringValue(match.Id)) + d.SetId(aws.ToString(match.Id)) restApiArn := arn.ARN{ Partition: meta.(*conns.AWSClient).Partition, @@ -133,7 +133,7 @@ func dataSourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta int if match.MinimumCompressionSize == nil { d.Set("minimum_compression_size", nil) } else { - d.Set("minimum_compression_size", strconv.FormatInt(aws.Int64Value(match.MinimumCompressionSize), 10)) + d.Set("minimum_compression_size", strconv.FormatInt(int64(aws.ToInt32(match.MinimumCompressionSize)), 10)) } if err := d.Set("endpoint_configuration", flattenEndpointConfiguration(match.EndpointConfiguration)); err != nil { @@ -152,23 +152,6 @@ func dataSourceRestAPIRead(ctx context.Context, d *schema.ResourceData, meta int Resource: d.Id(), }.String() d.Set("execution_arn", executionArn) - - resourceParams := &apigateway.GetResourcesInput{ - RestApiId: aws.String(d.Id()), - } - - err = conn.GetResourcesPagesWithContext(ctx, resourceParams, func(page *apigateway.GetResourcesOutput, lastPage bool) bool { - for _, item := range page.Items { - if aws.StringValue(item.Path) == "/" { - d.Set("root_resource_id", item.Id) - return false - } - } - return !lastPage - }) - - if err != nil { - return sdkdiag.AppendErrorf(diags, "reading API Gateway REST API (%s): %s", target, err) - } + d.Set("root_resource_id", match.RootResourceId) return diags } diff --git a/internal/service/apigateway/rest_api_policy.go b/internal/service/apigateway/rest_api_policy.go index 756d289157f..20920348374 100644 --- a/internal/service/apigateway/rest_api_policy.go +++ b/internal/service/apigateway/rest_api_policy.go @@ -8,14 +8,15 @@ import ( "log" "strconv" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "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/structure" "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/verify" ) @@ -55,12 +56,12 @@ func ResourceRestAPIPolicy() *schema.Resource { func resourceRestAPIPolicyPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restApiId := d.Get("rest_api_id").(string) log.Printf("[DEBUG] Setting API Gateway REST API Policy: %s", restApiId) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) policy, err := structure.NormalizeJsonString(d.Get("policy").(string)) @@ -68,13 +69,13 @@ func resourceRestAPIPolicyPut(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "policy (%s) is invalid JSON: %s", policy, err) } - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/policy"), Value: aws.String(policy), }) - res, err := conn.UpdateRestApiWithContext(ctx, &apigateway.UpdateRestApiInput{ + res, err := conn.UpdateRestApi(ctx, &apigateway.UpdateRestApiInput{ RestApiId: aws.String(restApiId), PatchOperations: operations, }) @@ -85,21 +86,21 @@ func resourceRestAPIPolicyPut(ctx context.Context, d *schema.ResourceData, meta log.Printf("[DEBUG] API Gateway REST API Policy Set: %s", restApiId) - d.SetId(aws.StringValue(res.Id)) + d.SetId(aws.ToString(res.Id)) return append(diags, resourceRestAPIPolicyRead(ctx, d, meta)...) } func resourceRestAPIPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Reading API Gateway REST API Policy %s", d.Id()) - api, err := conn.GetRestApiWithContext(ctx, &apigateway.GetRestApiInput{ + api, err := conn.GetRestApi(ctx, &apigateway.GetRestApiInput{ RestApiId: aws.String(d.Id()), }) - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] API Gateway REST API Policy (%s) not found, removing from state", d.Id()) d.SetId("") return diags @@ -108,7 +109,7 @@ func resourceRestAPIPolicyRead(ctx context.Context, d *schema.ResourceData, meta return sdkdiag.AppendErrorf(diags, "reading API Gateway REST API Policy (%s): %s", d.Id(), err) } - normalizedPolicy, err := structure.NormalizeJsonString(`"` + aws.StringValue(api.Policy) + `"`) + normalizedPolicy, err := structure.NormalizeJsonString(`"` + aws.ToString(api.Policy) + `"`) if err != nil { return sdkdiag.AppendErrorf(diags, "normalizing API Gateway REST API policy JSON: %s", err) } @@ -133,20 +134,20 @@ func resourceRestAPIPolicyRead(ctx context.Context, d *schema.ResourceData, meta func resourceRestAPIPolicyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restApiId := d.Get("rest_api_id").(string) log.Printf("[DEBUG] Deleting API Gateway REST API Policy: %s", restApiId) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/policy"), Value: aws.String(""), }) - _, err := conn.UpdateRestApiWithContext(ctx, &apigateway.UpdateRestApiInput{ + _, err := conn.UpdateRestApi(ctx, &apigateway.UpdateRestApiInput{ RestApiId: aws.String(restApiId), PatchOperations: operations, }) diff --git a/internal/service/apigateway/rest_api_policy_test.go b/internal/service/apigateway/rest_api_policy_test.go index 84380cf2fe8..e135fa86b31 100644 --- a/internal/service/apigateway/rest_api_policy_test.go +++ b/internal/service/apigateway/rest_api_policy_test.go @@ -10,8 +10,8 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" @@ -24,7 +24,7 @@ import ( func TestAccAPIGatewayRestAPIPolicy_basic(t *testing.T) { ctx := acctest.Context(t) - var v apigateway.RestApi + var v apigateway.GetRestApiOutput resourceName := "aws_api_gateway_rest_api_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -59,7 +59,7 @@ func TestAccAPIGatewayRestAPIPolicy_basic(t *testing.T) { func TestAccAPIGatewayRestAPIPolicy_disappears(t *testing.T) { ctx := acctest.Context(t) - var v apigateway.RestApi + var v apigateway.GetRestApiOutput resourceName := "aws_api_gateway_rest_api_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -83,7 +83,7 @@ func TestAccAPIGatewayRestAPIPolicy_disappears(t *testing.T) { func TestAccAPIGatewayRestAPIPolicy_Disappears_restAPI(t *testing.T) { ctx := acctest.Context(t) - var v apigateway.RestApi + var v apigateway.GetRestApiOutput resourceName := "aws_api_gateway_rest_api_policy.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -105,7 +105,7 @@ func TestAccAPIGatewayRestAPIPolicy_Disappears_restAPI(t *testing.T) { }) } -func testAccCheckRestAPIPolicyExists(ctx context.Context, n string, res *apigateway.RestApi) resource.TestCheckFunc { +func testAccCheckRestAPIPolicyExists(ctx context.Context, n string, res *apigateway.GetRestApiOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -116,17 +116,17 @@ func testAccCheckRestAPIPolicyExists(ctx context.Context, n string, res *apigate return fmt.Errorf("No API Gateway ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) req := &apigateway.GetRestApiInput{ RestApiId: aws.String(rs.Primary.ID), } - describe, err := conn.GetRestApiWithContext(ctx, req) + describe, err := conn.GetRestApi(ctx, req) if err != nil { return err } - normalizedPolicy, err := structure.NormalizeJsonString(`"` + aws.StringValue(describe.Policy) + `"`) + normalizedPolicy, err := structure.NormalizeJsonString(`"` + aws.ToString(describe.Policy) + `"`) if err != nil { return fmt.Errorf("error normalizing API Gateway REST API policy JSON: %w", err) } @@ -135,7 +135,7 @@ func testAccCheckRestAPIPolicyExists(ctx context.Context, n string, res *apigate return fmt.Errorf("error unescaping API Gateway REST API policy: %w", err) } - if aws.StringValue(describe.Id) != rs.Primary.ID && + if aws.ToString(describe.Id) != rs.Primary.ID && policy != rs.Primary.Attributes["policy"] { return fmt.Errorf("API Gateway REST API Policy not found") } @@ -148,7 +148,7 @@ func testAccCheckRestAPIPolicyExists(ctx context.Context, n string, res *apigate func testAccCheckRestAPIPolicyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_rest_api_policy" { @@ -156,12 +156,11 @@ func testAccCheckRestAPIPolicyDestroy(ctx context.Context) resource.TestCheckFun } req := &apigateway.GetRestApisInput{} - describe, err := conn.GetRestApisWithContext(ctx, req) - + describe, err := conn.GetRestApis(ctx, req) if err == nil { if len(describe.Items) != 0 && - aws.StringValue(describe.Items[0].Id) == rs.Primary.ID && - aws.StringValue(describe.Items[0].Policy) == "" { + aws.ToString(describe.Items[0].Id) == rs.Primary.ID && + aws.ToString(describe.Items[0].Policy) == "" { return fmt.Errorf("API Gateway REST API Policy still exists") } } diff --git a/internal/service/apigateway/rest_api_test.go b/internal/service/apigateway/rest_api_test.go index dc5dcf8a281..cc761b15664 100644 --- a/internal/service/apigateway/rest_api_test.go +++ b/internal/service/apigateway/rest_api_test.go @@ -9,14 +9,15 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" "github.com/hashicorp/terraform-provider-aws/names" @@ -24,7 +25,7 @@ import ( func TestAccAPIGatewayRestAPI_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -65,7 +66,7 @@ func TestAccAPIGatewayRestAPI_basic(t *testing.T) { func TestAccAPIGatewayRestAPI_tags(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput resourceName := "aws_api_gateway_rest_api.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -117,7 +118,7 @@ func TestAccAPIGatewayRestAPI_tags(t *testing.T) { func TestAccAPIGatewayRestAPI_disappears(t *testing.T) { ctx := acctest.Context(t) - var restApi apigateway.RestApi + var restApi apigateway.GetRestApiOutput resourceName := "aws_api_gateway_rest_api.test" rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) @@ -141,7 +142,7 @@ func TestAccAPIGatewayRestAPI_disappears(t *testing.T) { func TestAccAPIGatewayRestAPI_endpoint(t *testing.T) { ctx := acctest.Context(t) - var restApi apigateway.RestApi + var restApi apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -183,22 +184,22 @@ func TestAccAPIGatewayRestAPI_endpoint(t *testing.T) { // This can eventually be moved to a PreCheck function // If the region does not support EDGE endpoint type, this test will either show // SKIP (if REGIONAL passed) or FAIL (if REGIONAL failed) - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) - output, err := conn.CreateRestApiWithContext(ctx, &apigateway.CreateRestApiInput{ + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) + output, err := conn.CreateRestApi(ctx, &apigateway.CreateRestApiInput{ Name: aws.String(sdkacctest.RandomWithPrefix("tf-acc-test-edge-endpoint-precheck")), - EndpointConfiguration: &apigateway.EndpointConfiguration{ - Types: []*string{aws.String("EDGE")}, + EndpointConfiguration: &awstypes.EndpointConfiguration{ + Types: []awstypes.EndpointType{awstypes.EndpointTypeEdge}, }, }) if err != nil { - if tfawserr.ErrMessageContains(err, apigateway.ErrCodeBadRequestException, "Endpoint Configuration type EDGE is not supported in this region") { + if errs.IsAErrorMessageContains[*awstypes.BadRequestException](err, "Endpoint Configuration type EDGE is not supported in this region") { t.Skip("Region does not support EDGE endpoint type") } t.Fatal(err) } // Be kind and rewind. :) - _, err = conn.DeleteRestApiWithContext(ctx, &apigateway.DeleteRestApiInput{ + _, err = conn.DeleteRestApi(ctx, &apigateway.DeleteRestApiInput{ RestApiId: output.Id, }) if err != nil { @@ -219,7 +220,7 @@ func TestAccAPIGatewayRestAPI_endpoint(t *testing.T) { func TestAccAPIGatewayRestAPI_Endpoint_private(t *testing.T) { ctx := acctest.Context(t) - var restApi apigateway.RestApi + var restApi apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -233,22 +234,22 @@ func TestAccAPIGatewayRestAPI_Endpoint_private(t *testing.T) { PreConfig: func() { // Ensure region supports PRIVATE endpoint // This can eventually be moved to a PreCheck function - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) - output, err := conn.CreateRestApiWithContext(ctx, &apigateway.CreateRestApiInput{ + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) + output, err := conn.CreateRestApi(ctx, &apigateway.CreateRestApiInput{ Name: aws.String(sdkacctest.RandomWithPrefix("tf-acc-test-private-endpoint-precheck")), - EndpointConfiguration: &apigateway.EndpointConfiguration{ - Types: []*string{aws.String("PRIVATE")}, + EndpointConfiguration: &awstypes.EndpointConfiguration{ + Types: []awstypes.EndpointType{awstypes.EndpointTypePrivate}, }, }) if err != nil { - if tfawserr.ErrMessageContains(err, apigateway.ErrCodeBadRequestException, "Endpoint Configuration type PRIVATE is not supported in this region") { + if errs.IsAErrorMessageContains[*awstypes.BadRequestException](err, "Endpoint Configuration type PRIVATE is not supported in this region") { t.Skip("Region does not support PRIVATE endpoint type") } t.Fatal(err) } // Be kind and rewind. :) - _, err = conn.DeleteRestApiWithContext(ctx, &apigateway.DeleteRestApiInput{ + _, err = conn.DeleteRestApi(ctx, &apigateway.DeleteRestApiInput{ RestApiId: output.Id, }) if err != nil { @@ -314,7 +315,7 @@ func TestAccAPIGatewayRestAPI_apiKeySource(t *testing.T) { func TestAccAPIGatewayRestAPI_APIKeySource_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -359,7 +360,7 @@ func TestAccAPIGatewayRestAPI_APIKeySource_overrideBody(t *testing.T) { func TestAccAPIGatewayRestAPI_APIKeySource_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -388,7 +389,7 @@ func TestAccAPIGatewayRestAPI_APIKeySource_setByBody(t *testing.T) { func TestAccAPIGatewayRestAPI_binaryMediaTypes(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -426,7 +427,7 @@ func TestAccAPIGatewayRestAPI_binaryMediaTypes(t *testing.T) { func TestAccAPIGatewayRestAPI_BinaryMediaTypes_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -474,7 +475,7 @@ func TestAccAPIGatewayRestAPI_BinaryMediaTypes_overrideBody(t *testing.T) { func TestAccAPIGatewayRestAPI_BinaryMediaTypes_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -504,7 +505,7 @@ func TestAccAPIGatewayRestAPI_BinaryMediaTypes_setByBody(t *testing.T) { func TestAccAPIGatewayRestAPI_body(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -548,7 +549,7 @@ func TestAccAPIGatewayRestAPI_body(t *testing.T) { func TestAccAPIGatewayRestAPI_description(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -584,7 +585,7 @@ func TestAccAPIGatewayRestAPI_description(t *testing.T) { func TestAccAPIGatewayRestAPI_Description_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -629,7 +630,7 @@ func TestAccAPIGatewayRestAPI_Description_overrideBody(t *testing.T) { func TestAccAPIGatewayRestAPI_Description_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -697,7 +698,7 @@ func TestAccAPIGatewayRestAPI_disableExecuteAPIEndpoint(t *testing.T) { func TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -742,7 +743,7 @@ func TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_overrideBody(t *testing. func TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -771,7 +772,7 @@ func TestAccAPIGatewayRestAPI_DisableExecuteAPIEndpoint_setByBody(t *testing.T) func TestAccAPIGatewayRestAPI_Endpoint_vpcEndpointIDs(t *testing.T) { ctx := acctest.Context(t) - var restApi apigateway.RestApi + var restApi apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" vpcEndpointResourceName1 := "aws_vpc_endpoint.test" @@ -829,7 +830,7 @@ func TestAccAPIGatewayRestAPI_Endpoint_vpcEndpointIDs(t *testing.T) { func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" vpcEndpointResourceName1 := "aws_vpc_endpoint.test.0" @@ -886,7 +887,7 @@ func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideBody(t *testing.T) func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_mergeBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" vpcEndpointResourceName1 := "aws_vpc_endpoint.test.0" @@ -944,7 +945,7 @@ func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_mergeBody(t *testing.T) { func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideToMergeBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" vpcEndpointResourceName1 := "aws_vpc_endpoint.test.0" @@ -996,7 +997,7 @@ func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_overrideToMergeBody(t *test func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" vpcEndpointResourceName := "aws_vpc_endpoint.test" @@ -1028,7 +1029,7 @@ func TestAccAPIGatewayRestAPI_EndpointVPCEndpointIDs_setByBody(t *testing.T) { func TestAccAPIGatewayRestAPI_minimumCompressionSize(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1071,7 +1072,7 @@ func TestAccAPIGatewayRestAPI_minimumCompressionSize(t *testing.T) { func TestAccAPIGatewayRestAPI_MinimumCompressionSize_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1116,7 +1117,7 @@ func TestAccAPIGatewayRestAPI_MinimumCompressionSize_overrideBody(t *testing.T) func TestAccAPIGatewayRestAPI_MinimumCompressionSize_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1145,7 +1146,7 @@ func TestAccAPIGatewayRestAPI_MinimumCompressionSize_setByBody(t *testing.T) { func TestAccAPIGatewayRestAPI_Name_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) rName2 := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1191,7 +1192,7 @@ func TestAccAPIGatewayRestAPI_Name_overrideBody(t *testing.T) { func TestAccAPIGatewayRestAPI_FailOnWarnings(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1237,7 +1238,7 @@ func TestAccAPIGatewayRestAPI_FailOnWarnings(t *testing.T) { func TestAccAPIGatewayRestAPI_parameters(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1334,7 +1335,7 @@ func TestAccAPIGatewayRestAPI_Policy_order(t *testing.T) { func TestAccAPIGatewayRestAPI_Policy_overrideBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1382,7 +1383,7 @@ func TestAccAPIGatewayRestAPI_Policy_overrideBody(t *testing.T) { func TestAccAPIGatewayRestAPI_Policy_setByBody(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.RestApi + var conf apigateway.GetRestApiOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_rest_api.test" @@ -1409,11 +1410,11 @@ func TestAccAPIGatewayRestAPI_Policy_setByBody(t *testing.T) { }) } -func testAccCheckRestAPIRoutes(ctx context.Context, conf *apigateway.RestApi, routes []string) resource.TestCheckFunc { +func testAccCheckRestAPIRoutes(ctx context.Context, conf *apigateway.GetRestApiOutput, routes []string) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) - resp, err := conn.GetResourcesWithContext(ctx, &apigateway.GetResourcesInput{ + resp, err := conn.GetResources(ctx, &apigateway.GetResourcesInput{ RestApiId: conf.Id, }) if err != nil { @@ -1440,11 +1441,11 @@ func testAccCheckRestAPIRoutes(ctx context.Context, conf *apigateway.RestApi, ro } } -func testAccCheckRestAPIEndpointsCount(ctx context.Context, conf *apigateway.RestApi, count int) resource.TestCheckFunc { +func testAccCheckRestAPIEndpointsCount(ctx context.Context, conf *apigateway.GetRestApiOutput, count int) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) - resp, err := conn.GetRestApiWithContext(ctx, &apigateway.GetRestApiInput{ + resp, err := conn.GetRestApi(ctx, &apigateway.GetRestApiInput{ RestApiId: conf.Id, }) if err != nil { @@ -1453,7 +1454,7 @@ func testAccCheckRestAPIEndpointsCount(ctx context.Context, conf *apigateway.Res actualEndpoints := map[string]bool{} for _, endpoint := range resp.EndpointConfiguration.VpcEndpointIds { - actualEndpoints[*endpoint] = true + actualEndpoints[endpoint] = true } if len(resp.EndpointConfiguration.VpcEndpointIds) != count { @@ -1464,7 +1465,7 @@ func testAccCheckRestAPIEndpointsCount(ctx context.Context, conf *apigateway.Res } } -func testAccCheckRestAPIExists(ctx context.Context, n string, v *apigateway.RestApi) resource.TestCheckFunc { +func testAccCheckRestAPIExists(ctx context.Context, n string, v *apigateway.GetRestApiOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -1475,7 +1476,7 @@ func testAccCheckRestAPIExists(ctx context.Context, n string, v *apigateway.Rest return fmt.Errorf("No API Gateway ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindRESTAPIByID(ctx, conn, rs.Primary.ID) @@ -1491,7 +1492,7 @@ func testAccCheckRestAPIExists(ctx context.Context, n string, v *apigateway.Rest func testAccCheckRestAPIDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_rest_api" { diff --git a/internal/service/apigateway/sdk_data_source.go b/internal/service/apigateway/sdk_data_source.go index d36b88635de..8a48e99fe5c 100644 --- a/internal/service/apigateway/sdk_data_source.go +++ b/internal/service/apigateway/sdk_data_source.go @@ -7,8 +7,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "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" @@ -58,7 +58,7 @@ func DataSourceSdk() *schema.Resource { func dataSourceSdkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restApiId := d.Get("rest_api_id").(string) stageName := d.Get("stage_name").(string) @@ -71,12 +71,12 @@ func dataSourceSdkRead(ctx context.Context, d *schema.ResourceData, meta interfa } if v, ok := d.GetOk("parameters"); ok && len(v.(map[string]interface{})) > 0 { - input.Parameters = flex.ExpandStringMap(v.(map[string]interface{})) + input.Parameters = flex.ExpandStringValueMap(v.(map[string]interface{})) } id := fmt.Sprintf("%s:%s:%s", restApiId, stageName, sdkType) - export, err := conn.GetSdkWithContext(ctx, input) + export, err := conn.GetSdk(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "reading API Gateway SDK (%s): %s", id, err) } diff --git a/internal/service/apigateway/service_endpoints_gen_test.go b/internal/service/apigateway/service_endpoints_gen_test.go index 3ad34b2d875..91c50a698e9 100644 --- a/internal/service/apigateway/service_endpoints_gen_test.go +++ b/internal/service/apigateway/service_endpoints_gen_test.go @@ -4,17 +4,17 @@ package apigateway_test import ( "context" + "errors" "fmt" "maps" - "net/url" "os" "path/filepath" "reflect" "strings" "testing" - "github.com/aws/aws-sdk-go/aws/endpoints" - apigateway_sdkv1 "github.com/aws/aws-sdk-go/service/apigateway" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + apigateway_sdkv2 "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/aws/smithy-go/middleware" smithyhttp "github.com/aws/smithy-go/transport/http" "github.com/google/go-cmp/cmp" @@ -212,32 +212,42 @@ func TestEndpointConfiguration(t *testing.T) { //nolint:paralleltest // uses t.S } func defaultEndpoint(region string) string { - r := endpoints.DefaultResolver() + r := apigateway_sdkv2.NewDefaultEndpointResolverV2() - ep, err := r.EndpointFor(apigateway_sdkv1.EndpointsID, region) + ep, err := r.ResolveEndpoint(context.Background(), apigateway_sdkv2.EndpointParameters{ + Region: aws_sdkv2.String(region), + }) if err != nil { return err.Error() } - url, _ := url.Parse(ep.URL) - - if url.Path == "" { - url.Path = "/" + if ep.URI.Path == "" { + ep.URI.Path = "/" } - return url.String() + return ep.URI.String() } func callService(ctx context.Context, t *testing.T, meta *conns.AWSClient) string { t.Helper() - client := meta.APIGatewayConn(ctx) - - req, _ := client.GetAccountRequest(&apigateway_sdkv1.GetAccountInput{}) + var endpoint string - req.HTTPRequest.URL.Path = "/" + client := meta.APIGatewayClient(ctx) - endpoint := req.HTTPRequest.URL.String() + _, err := client.GetAccount(ctx, &apigateway_sdkv2.GetAccountInput{}, + func(opts *apigateway_sdkv2.Options) { + opts.APIOptions = append(opts.APIOptions, + addRetrieveEndpointURLMiddleware(t, &endpoint), + addCancelRequestMiddleware(), + ) + }, + ) + if err == nil { + t.Fatal("Expected an error, got none") + } else if !errors.Is(err, errCancelOperation) { + t.Fatalf("Unexpected error: %s", err) + } return endpoint } diff --git a/internal/service/apigateway/service_package_gen.go b/internal/service/apigateway/service_package_gen.go index d72af166fc4..7276ab6c67e 100644 --- a/internal/service/apigateway/service_package_gen.go +++ b/internal/service/apigateway/service_package_gen.go @@ -5,9 +5,8 @@ package apigateway import ( "context" - aws_sdkv1 "github.com/aws/aws-sdk-go/aws" - session_sdkv1 "github.com/aws/aws-sdk-go/aws/session" - apigateway_sdkv1 "github.com/aws/aws-sdk-go/service/apigateway" + aws_sdkv2 "github.com/aws/aws-sdk-go-v2/aws" + apigateway_sdkv2 "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/types" "github.com/hashicorp/terraform-provider-aws/names" @@ -197,11 +196,15 @@ func (p *servicePackage) ServicePackageName() string { return names.APIGateway } -// NewConn returns a new AWS SDK for Go v1 client for this service package's AWS API. -func (p *servicePackage) NewConn(ctx context.Context, config map[string]any) (*apigateway_sdkv1.APIGateway, error) { - sess := config["session"].(*session_sdkv1.Session) +// NewClient returns a new AWS SDK for Go v2 client for this service package's AWS API. +func (p *servicePackage) NewClient(ctx context.Context, config map[string]any) (*apigateway_sdkv2.Client, error) { + cfg := *(config["aws_sdkv2_config"].(*aws_sdkv2.Config)) - return apigateway_sdkv1.New(sess.Copy(&aws_sdkv1.Config{Endpoint: aws_sdkv1.String(config["endpoint"].(string))})), nil + return apigateway_sdkv2.NewFromConfig(cfg, func(o *apigateway_sdkv2.Options) { + if endpoint := config["endpoint"].(string); endpoint != "" { + o.BaseEndpoint = aws_sdkv2.String(endpoint) + } + }), nil } func ServicePackage(ctx context.Context) conns.ServicePackage { diff --git a/internal/service/apigateway/stage.go b/internal/service/apigateway/stage.go index 822b7c00d1d..4f472b203f7 100644 --- a/internal/service/apigateway/stage.go +++ b/internal/service/apigateway/stage.go @@ -9,15 +9,16 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/enum" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -78,9 +79,9 @@ func ResourceStage() *schema.Resource { Optional: true, }, "cache_cluster_size": { - Type: schema.TypeString, - Optional: true, - ValidateFunc: validation.StringInSlice(apigateway.CacheClusterSize_Values(), true), + Type: schema.TypeString, + Optional: true, + ValidateDiagFunc: enum.Validate[awstypes.CacheClusterSize](), }, "canary_settings": { Type: schema.TypeList, @@ -162,7 +163,7 @@ func ResourceStage() *schema.Resource { func resourceStageCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restAPIID := d.Get("rest_api_id").(string) stageName := d.Get("stage_name").(string) @@ -176,12 +177,12 @@ func resourceStageCreate(ctx context.Context, d *schema.ResourceData, meta inter waitForCache := false if v, ok := d.GetOk("cache_cluster_enabled"); ok { - input.CacheClusterEnabled = aws.Bool(v.(bool)) + input.CacheClusterEnabled = v.(bool) waitForCache = true } if v, ok := d.GetOk("cache_cluster_size"); ok { - input.CacheClusterSize = aws.String(v.(string)) + input.CacheClusterSize = awstypes.CacheClusterSize(v.(string)) waitForCache = true } @@ -198,14 +199,14 @@ func resourceStageCreate(ctx context.Context, d *schema.ResourceData, meta inter } if v, ok := d.GetOk("variables"); ok && len(v.(map[string]interface{})) > 0 { - input.Variables = flex.ExpandStringMap(v.(map[string]interface{})) + input.Variables = flex.ExpandStringValueMap(v.(map[string]interface{})) } if v, ok := d.GetOk("xray_tracing_enabled"); ok { - input.TracingEnabled = aws.Bool(v.(bool)) + input.TracingEnabled = v.(bool) } - output, err := conn.CreateStageWithContext(ctx, input) + output, err := conn.CreateStage(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Stage (%s): %s", stageName, err) @@ -213,7 +214,7 @@ func resourceStageCreate(ctx context.Context, d *schema.ResourceData, meta inter d.SetId(fmt.Sprintf("ags-%s-%s", restAPIID, stageName)) - if waitForCache && aws.StringValue(output.CacheClusterStatus) != apigateway.CacheClusterStatusNotAvailable { + if waitForCache && output.CacheClusterStatus != awstypes.CacheClusterStatusNotAvailable { if _, err := waitStageCacheAvailable(ctx, conn, restAPIID, stageName); err != nil { return sdkdiag.AppendErrorf(diags, "waiting for API Gateway Stage (%s) cache create: %s", d.Id(), err) } @@ -231,7 +232,7 @@ func resourceStageCreate(ctx context.Context, d *schema.ResourceData, meta inter func resourceStageRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restAPIID := d.Get("rest_api_id").(string) stageName := d.Get("stage_name").(string) @@ -257,11 +258,11 @@ func resourceStageRead(ctx context.Context, d *schema.ResourceData, meta interfa Resource: fmt.Sprintf("/restapis/%s/stages/%s", restAPIID, stageName), }.String() d.Set("arn", stageARN) - if aws.StringValue(stage.CacheClusterStatus) == apigateway.CacheClusterStatusDeleteInProgress { + if stage.CacheClusterStatus == awstypes.CacheClusterStatusDeleteInProgress { d.Set("cache_cluster_enabled", false) d.Set("cache_cluster_size", d.Get("cache_cluster_size")) } else { - enabled := aws.BoolValue(stage.CacheClusterEnabled) + enabled := stage.CacheClusterEnabled d.Set("cache_cluster_enabled", enabled) if enabled { d.Set("cache_cluster_size", stage.CacheClusterSize) @@ -285,7 +286,7 @@ func resourceStageRead(ctx context.Context, d *schema.ResourceData, meta interfa }.String() d.Set("execution_arn", executionARN) d.Set("invoke_url", meta.(*conns.AWSClient).APIGatewayInvokeURL(ctx, restAPIID, stageName)) - if err := d.Set("variables", aws.StringValueMap(stage.Variables)); err != nil { + if err := d.Set("variables", stage.Variables); err != nil { return sdkdiag.AppendErrorf(diags, "setting variables: %s", err) } d.Set("web_acl_arn", stage.WebAclArn) @@ -298,33 +299,33 @@ func resourceStageRead(ctx context.Context, d *schema.ResourceData, meta interfa func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) restAPIID := d.Get("rest_api_id").(string) stageName := d.Get("stage_name").(string) if d.HasChangesExcept("tags", "tags_all") { - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) waitForCache := false if d.HasChange("cache_cluster_enabled") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/cacheClusterEnabled"), Value: aws.String(fmt.Sprintf("%t", d.Get("cache_cluster_enabled").(bool))), }) waitForCache = true } if d.HasChange("cache_cluster_size") && d.Get("cache_cluster_enabled").(bool) { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/cacheClusterSize"), Value: aws.String(d.Get("cache_cluster_size").(string)), }) waitForCache = true } if d.HasChange("client_certificate_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/clientCertificateId"), Value: aws.String(d.Get("client_certificate_id").(string)), }) @@ -337,37 +338,37 @@ func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta inter ) } if d.HasChange("deployment_id") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/deploymentId"), Value: aws.String(d.Get("deployment_id").(string)), }) if _, ok := d.GetOk("canary_settings"); ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/canarySettings/deploymentId"), Value: aws.String(d.Get("deployment_id").(string)), }) } } if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) } if d.HasChange("xray_tracing_enabled") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/tracingEnabled"), Value: aws.String(fmt.Sprintf("%t", d.Get("xray_tracing_enabled").(bool))), }) } if d.HasChange("documentation_version") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/documentationVersion"), Value: aws.String(d.Get("documentation_version").(string)), }) @@ -382,18 +383,18 @@ func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta inter accessLogSettings := d.Get("access_log_settings").([]interface{}) if len(accessLogSettings) == 1 { operations = append(operations, - &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/accessLogSettings/destinationArn"), Value: aws.String(d.Get("access_log_settings.0.destination_arn").(string)), - }, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + }, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/accessLogSettings/format"), Value: aws.String(d.Get("access_log_settings.0.format").(string)), }) } else if len(accessLogSettings) == 0 { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/accessLogSettings"), }) } @@ -405,13 +406,13 @@ func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta inter PatchOperations: operations, } - output, err := conn.UpdateStageWithContext(ctx, input) + output, err := conn.UpdateStage(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Stage (%s): %s", d.Id(), err) } - if waitForCache && aws.StringValue(output.CacheClusterStatus) != apigateway.CacheClusterStatusNotAvailable { + if waitForCache && output.CacheClusterStatus != awstypes.CacheClusterStatusNotAvailable { _, err := waitStageCacheUpdated(ctx, conn, restAPIID, stageName) if err != nil { return sdkdiag.AppendErrorf(diags, "waiting for API Gateway Stage (%s) to be updated: %s", d.Id(), err) @@ -424,15 +425,15 @@ func resourceStageUpdate(ctx context.Context, d *schema.ResourceData, meta inter func resourceStageDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Stage: %s", d.Id()) - _, err := conn.DeleteStageWithContext(ctx, &apigateway.DeleteStageInput{ + _, err := conn.DeleteStage(ctx, &apigateway.DeleteStageInput{ RestApiId: aws.String(d.Get("rest_api_id").(string)), StageName: aws.String(d.Get("stage_name").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -443,15 +444,15 @@ func resourceStageDelete(ctx context.Context, d *schema.ResourceData, meta inter return diags } -func FindStageByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, restAPIID, stageName string) (*apigateway.Stage, error) { +func FindStageByTwoPartKey(ctx context.Context, conn *apigateway.Client, restAPIID, stageName string) (*apigateway.GetStageOutput, error) { input := &apigateway.GetStageInput{ RestApiId: aws.String(restAPIID), StageName: aws.String(stageName), } - output, err := conn.GetStageWithContext(ctx, input) + output, err := conn.GetStage(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -469,13 +470,13 @@ func FindStageByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, res return output, nil } -func diffVariablesOps(oldVars, newVars map[string]interface{}, prefix string) []*apigateway.PatchOperation { - ops := make([]*apigateway.PatchOperation, 0) +func diffVariablesOps(oldVars, newVars map[string]interface{}, prefix string) []awstypes.PatchOperation { + ops := make([]awstypes.PatchOperation, 0) for k := range oldVars { if _, ok := newVars[k]; !ok { - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String(prefix + k), }) } @@ -490,8 +491,8 @@ func diffVariablesOps(oldVars, newVars map[string]interface{}, prefix string) [] continue } } - ops = append(ops, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + ops = append(ops, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(prefix + k), Value: aws.String(newValue), }) @@ -500,49 +501,49 @@ func diffVariablesOps(oldVars, newVars map[string]interface{}, prefix string) [] return ops } -func flattenAccessLogSettings(accessLogSettings *apigateway.AccessLogSettings) []map[string]interface{} { +func flattenAccessLogSettings(accessLogSettings *awstypes.AccessLogSettings) []map[string]interface{} { result := make([]map[string]interface{}, 0, 1) if accessLogSettings != nil { result = append(result, map[string]interface{}{ - "destination_arn": aws.StringValue(accessLogSettings.DestinationArn), - "format": aws.StringValue(accessLogSettings.Format), + "destination_arn": aws.ToString(accessLogSettings.DestinationArn), + "format": aws.ToString(accessLogSettings.Format), }) } return result } -func expandCanarySettings(tfMap map[string]interface{}, deploymentId string) *apigateway.CanarySettings { +func expandCanarySettings(tfMap map[string]interface{}, deploymentId string) *awstypes.CanarySettings { if tfMap == nil { return nil } - apiObject := &apigateway.CanarySettings{ + apiObject := &awstypes.CanarySettings{ DeploymentId: aws.String(deploymentId), } if v, ok := tfMap["percent_traffic"].(float64); ok { - apiObject.PercentTraffic = aws.Float64(v) + apiObject.PercentTraffic = v } if v, ok := tfMap["stage_variable_overrides"].(map[string]interface{}); ok && len(v) > 0 { - apiObject.StageVariableOverrides = flex.ExpandStringMap(v) + apiObject.StageVariableOverrides = flex.ExpandStringValueMap(v) } if v, ok := tfMap["use_stage_cache"].(bool); ok { - apiObject.UseStageCache = aws.Bool(v) + apiObject.UseStageCache = v } return apiObject } -func flattenCanarySettings(canarySettings *apigateway.CanarySettings) []interface{} { +func flattenCanarySettings(canarySettings *awstypes.CanarySettings) []interface{} { settings := make(map[string]interface{}) if canarySettings == nil { return nil } - overrides := aws.StringValueMap(canarySettings.StageVariableOverrides) + overrides := canarySettings.StageVariableOverrides if len(overrides) > 0 { settings["stage_variable_overrides"] = overrides @@ -554,10 +555,10 @@ func flattenCanarySettings(canarySettings *apigateway.CanarySettings) []interfac return []interface{}{settings} } -func appendCanarySettingsPatchOperations(operations []*apigateway.PatchOperation, oldCanarySettingsRaw, newCanarySettingsRaw []interface{}) []*apigateway.PatchOperation { +func appendCanarySettingsPatchOperations(operations []awstypes.PatchOperation, oldCanarySettingsRaw, newCanarySettingsRaw []interface{}) []awstypes.PatchOperation { if len(newCanarySettingsRaw) == 0 { // Schema guarantees either 0 or 1 - return append(operations, &apigateway.PatchOperation{ - Op: aws.String("remove"), + return append(operations, awstypes.PatchOperation{ + Op: awstypes.Op("remove"), Path: aws.String("/canarySettings"), }) } @@ -581,8 +582,8 @@ func appendCanarySettingsPatchOperations(operations []*apigateway.PatchOperation oldPercentTraffic := oldSettings["percent_traffic"].(float64) newPercentTraffic := newSettings["percent_traffic"].(float64) if oldPercentTraffic != newPercentTraffic { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/canarySettings/percentTraffic"), Value: aws.String(fmt.Sprintf("%f", newPercentTraffic)), }) @@ -591,8 +592,8 @@ func appendCanarySettingsPatchOperations(operations []*apigateway.PatchOperation oldUseStageCache := oldSettings["use_stage_cache"].(bool) newUseStageCache := newSettings["use_stage_cache"].(bool) if oldUseStageCache != newUseStageCache { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/canarySettings/useStageCache"), Value: aws.String(fmt.Sprintf("%t", newUseStageCache)), }) diff --git a/internal/service/apigateway/stage_test.go b/internal/service/apigateway/stage_test.go index 014f8b780c1..4fbc7b416b6 100644 --- a/internal/service/apigateway/stage_test.go +++ b/internal/service/apigateway/stage_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccAPIGatewayStage_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -89,7 +89,7 @@ func TestAccAPIGatewayStage_basic(t *testing.T) { func TestAccAPIGatewayStage_cache(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -143,7 +143,7 @@ func TestAccAPIGatewayStage_cache(t *testing.T) { // Reference: https://github.com/hashicorp/terraform-provider-aws/issues/22866 func TestAccAPIGatewayStage_cacheSizeCacheDisabled(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -197,7 +197,7 @@ func TestAccAPIGatewayStage_cacheSizeCacheDisabled(t *testing.T) { func TestAccAPIGatewayStage_tags(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -244,7 +244,7 @@ func TestAccAPIGatewayStage_tags(t *testing.T) { func TestAccAPIGatewayStage_disappears(t *testing.T) { ctx := acctest.Context(t) - var stage apigateway.Stage + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -269,7 +269,7 @@ func TestAccAPIGatewayStage_disappears(t *testing.T) { func TestAccAPIGatewayStage_Disappears_restAPI(t *testing.T) { ctx := acctest.Context(t) - var stage apigateway.Stage + var stage apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -294,7 +294,7 @@ func TestAccAPIGatewayStage_Disappears_restAPI(t *testing.T) { func TestAccAPIGatewayStage_accessLogSettings(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) cloudwatchLogGroupResourceName := "aws_cloudwatch_log_group.test" resourceName := "aws_api_gateway_stage.test" @@ -364,7 +364,7 @@ func TestAccAPIGatewayStage_accessLogSettings(t *testing.T) { func TestAccAPIGatewayStage_AccessLogSettings_kinesis(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" kinesesResourceName := "aws_kinesis_firehose_delivery_stream.test" @@ -433,7 +433,7 @@ func TestAccAPIGatewayStage_AccessLogSettings_kinesis(t *testing.T) { func TestAccAPIGatewayStage_waf(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -468,7 +468,7 @@ func TestAccAPIGatewayStage_waf(t *testing.T) { func TestAccAPIGatewayStage_canarySettings(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.Stage + var conf apigateway.GetStageOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_stage.test" @@ -515,7 +515,7 @@ func TestAccAPIGatewayStage_canarySettings(t *testing.T) { }) } -func testAccCheckStageExists(ctx context.Context, n string, v *apigateway.Stage) resource.TestCheckFunc { +func testAccCheckStageExists(ctx context.Context, n string, v *apigateway.GetStageOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -526,7 +526,7 @@ func testAccCheckStageExists(ctx context.Context, n string, v *apigateway.Stage) return fmt.Errorf("No API Gateway Stage ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindStageByTwoPartKey(ctx, conn, rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes["stage_name"]) @@ -542,7 +542,7 @@ func testAccCheckStageExists(ctx context.Context, n string, v *apigateway.Stage) func testAccCheckStageDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_stage" { diff --git a/internal/service/apigateway/status.go b/internal/service/apigateway/status.go index 878c36d0163..2a7bb0832cb 100644 --- a/internal/service/apigateway/status.go +++ b/internal/service/apigateway/status.go @@ -7,19 +7,20 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) -func vpcLinkStatus(ctx context.Context, conn *apigateway.APIGateway, vpcLinkId string) retry.StateRefreshFunc { +func vpcLinkStatus(ctx context.Context, conn *apigateway.Client, vpcLinkId string) retry.StateRefreshFunc { return func() (interface{}, string, error) { - output, err := conn.GetVpcLinkWithContext(ctx, &apigateway.GetVpcLinkInput{ + output, err := conn.GetVpcLink(ctx, &apigateway.GetVpcLinkInput{ VpcLinkId: aws.String(vpcLinkId), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, "", nil } if err != nil { @@ -27,15 +28,15 @@ func vpcLinkStatus(ctx context.Context, conn *apigateway.APIGateway, vpcLinkId s } // Error messages can also be contained in the response with FAILED status - if aws.StringValue(output.Status) == apigateway.VpcLinkStatusFailed { - return output, apigateway.VpcLinkStatusFailed, fmt.Errorf("%s: %s", apigateway.VpcLinkStatusFailed, aws.StringValue(output.StatusMessage)) + if output.Status == awstypes.VpcLinkStatusFailed { + return output, string(awstypes.VpcLinkStatusFailed), fmt.Errorf("%s: %s", string(awstypes.VpcLinkStatusFailed), aws.ToString(output.StatusMessage)) } - return output, aws.StringValue(output.Status), nil + return output, string(output.Status), nil } } -func stageCacheStatus(ctx context.Context, conn *apigateway.APIGateway, restApiId, name string) retry.StateRefreshFunc { +func stageCacheStatus(ctx context.Context, conn *apigateway.Client, restApiId, name string) retry.StateRefreshFunc { return func() (interface{}, string, error) { output, err := FindStageByTwoPartKey(ctx, conn, restApiId, name) @@ -46,6 +47,6 @@ func stageCacheStatus(ctx context.Context, conn *apigateway.APIGateway, restApiI return nil, "", err } - return output, aws.StringValue(output.CacheClusterStatus), nil + return output, string(output.CacheClusterStatus), nil } } diff --git a/internal/service/apigateway/sweep.go b/internal/service/apigateway/sweep.go index 343a1dec9ab..e7abfbd32a4 100644 --- a/internal/service/apigateway/sweep.go +++ b/internal/service/apigateway/sweep.go @@ -8,12 +8,13 @@ import ( "log" "time" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/go-multierror" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-provider-aws/internal/errs" "github.com/hashicorp/terraform-provider-aws/internal/sweep" "github.com/hashicorp/terraform-provider-aws/internal/sweep/awsv1" ) @@ -59,19 +60,29 @@ func sweepRestAPIs(region string) error { if err != nil { return fmt.Errorf("getting client: %s", err) } - conn := client.APIGatewayConn(ctx) + conn := client.APIGatewayClient(ctx) + + pages := apigateway.NewGetRestApisPaginator(conn, &apigateway.GetRestApisInput{}) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + if awsv1.SkipSweepError(err) { + log.Printf("[WARN] Skipping API Gateway REST API sweep for %s: %s", region, err) + return nil + } + return fmt.Errorf("retrieving API Gateway REST APIs: %s", err) + } - err = conn.GetRestApisPagesWithContext(ctx, &apigateway.GetRestApisInput{}, func(page *apigateway.GetRestApisOutput, lastPage bool) bool { for _, item := range page.Items { input := &apigateway.DeleteRestApiInput{ RestApiId: item.Id, } - log.Printf("[INFO] Deleting API Gateway REST API: %s", input) + log.Printf("[INFO] Deleting API Gateway REST API: %+v", input) // TooManyRequestsException: Too Many Requests can take over a minute to resolve itself err := retry.RetryContext(ctx, 2*time.Minute, func() *retry.RetryError { - _, err := conn.DeleteRestApiWithContext(ctx, input) + _, err := conn.DeleteRestApi(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeTooManyRequestsException) { + if errs.IsA[*awstypes.TooManyRequestsException](err) { return retry.RetryableError(err) } return retry.NonRetryableError(err) @@ -83,14 +94,6 @@ func sweepRestAPIs(region string) error { continue } } - return !lastPage - }) - if err != nil { - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping API Gateway REST API sweep for %s: %s", region, err) - return nil - } - return fmt.Errorf("retrieving API Gateway REST APIs: %s", err) } return nil @@ -102,20 +105,26 @@ func sweepVPCLinks(region string) error { if err != nil { return fmt.Errorf("getting client: %w", err) } - conn := client.APIGatewayConn(ctx) + conn := client.APIGatewayClient(ctx) input := &apigateway.GetVpcLinksInput{} sweepResources := make([]sweep.Sweepable, 0) - err = conn.GetVpcLinksPagesWithContext(ctx, input, func(page *apigateway.GetVpcLinksOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := apigateway.NewGetVpcLinksPaginator(conn, input) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + if awsv1.SkipSweepError(err) { + log.Printf("[WARN] Skipping API Gateway VPC Link sweep for %s: %s", region, err) + return nil + } + return fmt.Errorf("error listing API Gateway VPC Links (%s): %w", region, err) } for _, v := range page.Items { - id := aws.StringValue(v.Id) + id := aws.ToString(v.Id) - if status := aws.StringValue(v.Status); status == apigateway.VpcLinkStatusFailed { - log.Printf("[INFO] Skipping API Gateway VPC Link %s: Status=%s", id, status) + if v.Status == awstypes.VpcLinkStatusFailed { + log.Printf("[INFO] Skipping API Gateway VPC Link %s: Status=%s", id, string(v.Status)) continue } @@ -125,17 +134,6 @@ func sweepVPCLinks(region string) error { sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if awsv1.SkipSweepError(err) { - log.Printf("[WARN] Skipping API Gateway VPC Link sweep for %s: %s", region, err) - return nil - } - - if err != nil { - return fmt.Errorf("error listing API Gateway VPC Links (%s): %w", region, err) } err = sweep.SweepOrchestrator(ctx, sweepResources) @@ -154,28 +152,24 @@ func sweepClientCertificates(region string) error { return fmt.Errorf("getting client: %s", err) } - conn := client.APIGatewayConn(ctx) + conn := client.APIGatewayClient(ctx) sweepResources := make([]sweep.Sweepable, 0) var errs *multierror.Error - err = conn.GetClientCertificatesPagesWithContext(ctx, &apigateway.GetClientCertificatesInput{}, func(page *apigateway.GetClientCertificatesOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := apigateway.NewGetClientCertificatesPaginator(conn, &apigateway.GetClientCertificatesInput{}) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("describing API Gateway Client Certificates for %s: %w", region, err)) } for _, clientCertificate := range page.Items { r := ResourceClientCertificate() d := r.Data(nil) - d.SetId(aws.StringValue(clientCertificate.ClientCertificateId)) + d.SetId(aws.ToString(clientCertificate.ClientCertificateId)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if err != nil { - errs = multierror.Append(errs, fmt.Errorf("describing API Gateway Client Certificates for %s: %w", region, err)) } if err = sweep.SweepOrchestrator(ctx, sweepResources); err != nil { @@ -199,13 +193,15 @@ func sweepUsagePlans(region string) error { log.Printf("[INFO] Sweeping API Gateway Usage Plans for %s", region) - conn := client.APIGatewayConn(ctx) + conn := client.APIGatewayClient(ctx) sweepResources := make([]sweep.Sweepable, 0) var errs *multierror.Error - err = conn.GetUsagePlansPagesWithContext(ctx, &apigateway.GetUsagePlansInput{}, func(page *apigateway.GetUsagePlansOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := apigateway.NewGetUsagePlansPaginator(conn, &apigateway.GetUsagePlansInput{}) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("describing API Gateway Usage Plans for %s: %w", region, err)) } log.Printf("[INFO] API Gateway Usage Plans: %d", len(page.Items)) @@ -213,17 +209,11 @@ func sweepUsagePlans(region string) error { for _, up := range page.Items { r := ResourceUsagePlan() d := r.Data(nil) - d.SetId(aws.StringValue(up.Id)) + d.SetId(aws.ToString(up.Id)) d.Set("api_stages", flattenAPIStages(up.ApiStages)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if err != nil { - errs = multierror.Append(errs, fmt.Errorf("describing API Gateway Usage Plans for %s: %w", region, err)) } if err = sweep.SweepOrchestrator(ctx, sweepResources); err != nil { @@ -247,13 +237,15 @@ func sweepAPIKeys(region string) error { log.Printf("[INFO] Sweeping API Gateway API Keys for %s", region) - conn := client.APIGatewayConn(ctx) + conn := client.APIGatewayClient(ctx) sweepResources := make([]sweep.Sweepable, 0) var errs *multierror.Error - err = conn.GetApiKeysPagesWithContext(ctx, &apigateway.GetApiKeysInput{}, func(page *apigateway.GetApiKeysOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := apigateway.NewGetApiKeysPaginator(conn, &apigateway.GetApiKeysInput{}) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("describing API Gateway API Keys for %s: %w", region, err)) } log.Printf("[INFO] API Gateway API Keys: %d", len(page.Items)) @@ -261,16 +253,10 @@ func sweepAPIKeys(region string) error { for _, ak := range page.Items { r := ResourceAPIKey() d := r.Data(nil) - d.SetId(aws.StringValue(ak.Id)) + d.SetId(aws.ToString(ak.Id)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if err != nil { - errs = multierror.Append(errs, fmt.Errorf("describing API Gateway API Keys for %s: %w", region, err)) } if err = sweep.SweepOrchestrator(ctx, sweepResources); err != nil { @@ -294,13 +280,15 @@ func sweepDomainNames(region string) error { log.Printf("[INFO] Sweeping API Gateway Domain Names for %s", region) - conn := client.APIGatewayConn(ctx) + conn := client.APIGatewayClient(ctx) sweepResources := make([]sweep.Sweepable, 0) var errs *multierror.Error - err = conn.GetDomainNamesPagesWithContext(ctx, &apigateway.GetDomainNamesInput{}, func(page *apigateway.GetDomainNamesOutput, lastPage bool) bool { - if page == nil { - return !lastPage + pages := apigateway.NewGetDomainNamesPaginator(conn, &apigateway.GetDomainNamesInput{}) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + errs = multierror.Append(errs, fmt.Errorf("describing API Gateway Domain Names for %s: %w", region, err)) } log.Printf("[INFO] API Gateway Domain Names: %d", len(page.Items)) @@ -308,16 +296,10 @@ func sweepDomainNames(region string) error { for _, dn := range page.Items { r := ResourceDomainName() d := r.Data(nil) - d.SetId(aws.StringValue(dn.DomainName)) + d.SetId(aws.ToString(dn.DomainName)) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } - - return !lastPage - }) - - if err != nil { - errs = multierror.Append(errs, fmt.Errorf("describing API Gateway Domain Names for %s: %w", region, err)) } if err = sweep.SweepOrchestrator(ctx, sweepResources); err != nil { diff --git a/internal/service/apigateway/tags_gen.go b/internal/service/apigateway/tags_gen.go index 43069e08601..b5826661ee8 100644 --- a/internal/service/apigateway/tags_gen.go +++ b/internal/service/apigateway/tags_gen.go @@ -5,9 +5,8 @@ import ( "context" "fmt" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "github.com/aws/aws-sdk-go/service/apigateway/apigatewayiface" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/hashicorp/terraform-plugin-log/tflog" "github.com/hashicorp/terraform-provider-aws/internal/conns" "github.com/hashicorp/terraform-provider-aws/internal/logging" @@ -16,21 +15,21 @@ import ( "github.com/hashicorp/terraform-provider-aws/names" ) -// map[string]*string handling +// map[string]string handling // Tags returns apigateway service tags. -func Tags(tags tftags.KeyValueTags) map[string]*string { - return aws.StringMap(tags.Map()) +func Tags(tags tftags.KeyValueTags) map[string]string { + return tags.Map() } // KeyValueTags creates tftags.KeyValueTags from apigateway service tags. -func KeyValueTags(ctx context.Context, tags map[string]*string) tftags.KeyValueTags { +func KeyValueTags(ctx context.Context, tags map[string]string) tftags.KeyValueTags { return tftags.New(ctx, tags) } // getTagsIn returns apigateway service tags from Context. // nil is returned if there are no input tags. -func getTagsIn(ctx context.Context) map[string]*string { +func getTagsIn(ctx context.Context) map[string]string { if inContext, ok := tftags.FromContext(ctx); ok { if tags := Tags(inContext.TagsIn.UnwrapOrDefault()); len(tags) > 0 { return tags @@ -41,7 +40,7 @@ func getTagsIn(ctx context.Context) map[string]*string { } // setTagsOut sets apigateway service tags in Context. -func setTagsOut(ctx context.Context, tags map[string]*string) { +func setTagsOut(ctx context.Context, tags map[string]string) { if inContext, ok := tftags.FromContext(ctx); ok { inContext.TagsOut = option.Some(KeyValueTags(ctx, tags)) } @@ -50,7 +49,7 @@ func setTagsOut(ctx context.Context, tags map[string]*string) { // updateTags updates apigateway service tags. // The identifier is typically the Amazon Resource Name (ARN), although // it may also be a different identifier depending on the service. -func updateTags(ctx context.Context, conn apigatewayiface.APIGatewayAPI, identifier string, oldTagsMap, newTagsMap any) error { +func updateTags(ctx context.Context, conn *apigateway.Client, identifier string, oldTagsMap, newTagsMap any, optFns ...func(*apigateway.Options)) error { oldTags := tftags.New(ctx, oldTagsMap) newTags := tftags.New(ctx, newTagsMap) @@ -61,10 +60,10 @@ func updateTags(ctx context.Context, conn apigatewayiface.APIGatewayAPI, identif if len(removedTags) > 0 { input := &apigateway.UntagResourceInput{ ResourceArn: aws.String(identifier), - TagKeys: aws.StringSlice(removedTags.Keys()), + TagKeys: removedTags.Keys(), } - _, err := conn.UntagResourceWithContext(ctx, input) + _, err := conn.UntagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("untagging resource (%s): %w", identifier, err) @@ -79,7 +78,7 @@ func updateTags(ctx context.Context, conn apigatewayiface.APIGatewayAPI, identif Tags: Tags(updatedTags), } - _, err := conn.TagResourceWithContext(ctx, input) + _, err := conn.TagResource(ctx, input, optFns...) if err != nil { return fmt.Errorf("tagging resource (%s): %w", identifier, err) @@ -92,5 +91,5 @@ func updateTags(ctx context.Context, conn apigatewayiface.APIGatewayAPI, identif // UpdateTags updates apigateway service tags. // It is called from outside this package. func (p *servicePackage) UpdateTags(ctx context.Context, meta any, identifier string, oldTags, newTags any) error { - return updateTags(ctx, meta.(*conns.AWSClient).APIGatewayConn(ctx), identifier, oldTags, newTags) + return updateTags(ctx, meta.(*conns.AWSClient).APIGatewayClient(ctx), identifier, oldTags, newTags) } diff --git a/internal/service/apigateway/usage_plan.go b/internal/service/apigateway/usage_plan.go index fb0c7ee0583..4aefb925423 100644 --- a/internal/service/apigateway/usage_plan.go +++ b/internal/service/apigateway/usage_plan.go @@ -9,15 +9,16 @@ import ( "log" "strconv" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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/enum" + "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" @@ -109,9 +110,9 @@ func ResourceUsagePlan() *schema.Resource { Optional: true, }, "period": { - Type: schema.TypeString, - Required: true, // Required as not removable - ValidateFunc: validation.StringInSlice(apigateway.QuotaPeriodType_Values(), false), + Type: schema.TypeString, + Required: true, // Required as not removable + ValidateDiagFunc: enum.Validate[awstypes.QuotaPeriodType](), }, }, }, @@ -147,7 +148,7 @@ func ResourceUsagePlan() *schema.Resource { func resourceUsagePlanCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) name := d.Get("name").(string) input := &apigateway.CreateUsagePlanInput{ @@ -182,21 +183,21 @@ func resourceUsagePlanCreate(ctx context.Context, d *schema.ResourceData, meta i input.Throttle = expandThrottleSettings(v.([]interface{})) } - output, err := conn.CreateUsagePlanWithContext(ctx, input) + output, err := conn.CreateUsagePlan(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Usage Plan (%s): %s", name, err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) // Handle case of adding the product code since not addable when // creating the Usage Plan initially. if v, ok := d.GetOk("product_code"); ok { input := &apigateway.UpdateUsagePlanInput{ - PatchOperations: []*apigateway.PatchOperation{ + PatchOperations: []awstypes.PatchOperation{ { - Op: aws.String(apigateway.OpAdd), + Op: awstypes.OpAdd, Path: aws.String("/productCode"), Value: aws.String(v.(string)), }, @@ -204,7 +205,7 @@ func resourceUsagePlanCreate(ctx context.Context, d *schema.ResourceData, meta i UsagePlanId: aws.String(d.Id()), } - _, err = conn.UpdateUsagePlanWithContext(ctx, input) + _, err = conn.UpdateUsagePlan(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "adding API Gateway Usage Plan (%s) product code: %s", d.Id(), err) @@ -216,7 +217,7 @@ func resourceUsagePlanCreate(ctx context.Context, d *schema.ResourceData, meta i func resourceUsagePlanRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) up, err := FindUsagePlanByID(ctx, conn, d.Id()) @@ -263,22 +264,22 @@ func resourceUsagePlanRead(ctx context.Context, d *schema.ResourceData, meta int func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) if d.HasChangesExcept("tags", "tags_all") { - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/name"), Value: aws.String(d.Get("name").(string)), }) } if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) @@ -286,14 +287,14 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i if d.HasChange("product_code") { if v, ok := d.GetOk("product_code"); ok { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/productCode"), Value: aws.String(v.(string)), }) } else { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/productCode"), }) } @@ -308,8 +309,8 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // since there are no replacings. for _, v := range os { m := v.(map[string]interface{}) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/apiStages"), Value: aws.String(fmt.Sprintf("%s:%s", m["api_id"].(string), m["stage"].(string))), }) @@ -320,21 +321,21 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i for _, v := range ns { m := v.(map[string]interface{}) id := fmt.Sprintf("%s:%s", m["api_id"].(string), m["stage"].(string)) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/apiStages"), Value: aws.String(id), }) if t, ok := m["throttle"].(*schema.Set); ok && t.Len() > 0 { for _, throttle := range t.List() { th := throttle.(map[string]interface{}) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(fmt.Sprintf("/apiStages/%s/throttle/%s/rateLimit", id, th["path"].(string))), Value: aws.String(strconv.FormatFloat(th["rate_limit"].(float64), 'f', -1, 64)), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String(fmt.Sprintf("/apiStages/%s/throttle/%s/burstLimit", id, th["path"].(string))), Value: aws.String(strconv.Itoa(th["burst_limit"].(int))), }) @@ -350,8 +351,8 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // Handle Removal if len(diff) == 0 { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/throttle"), }) } @@ -361,13 +362,13 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // Handle Replaces if o != nil && n != nil { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/throttle/rateLimit"), Value: aws.String(strconv.FormatFloat(d["rate_limit"].(float64), 'f', -1, 64)), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/throttle/burstLimit"), Value: aws.String(strconv.Itoa(d["burst_limit"].(int))), }) @@ -375,13 +376,13 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // Handle Additions if o == nil && n != nil { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/throttle/rateLimit"), Value: aws.String(strconv.FormatFloat(d["rate_limit"].(float64), 'f', -1, 64)), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/throttle/burstLimit"), Value: aws.String(strconv.Itoa(d["burst_limit"].(int))), }) @@ -395,8 +396,8 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // Handle Removal if len(diff) == 0 { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/quota"), }) } @@ -410,18 +411,18 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // Handle Replaces if o != nil && n != nil { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/quota/limit"), Value: aws.String(strconv.Itoa(d["limit"].(int))), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/quota/offset"), Value: aws.String(strconv.Itoa(d["offset"].(int))), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpReplace), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpReplace, Path: aws.String("/quota/period"), Value: aws.String(d["period"].(string)), }) @@ -429,18 +430,18 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i // Handle Additions if o == nil && n != nil { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/quota/limit"), Value: aws.String(strconv.Itoa(d["limit"].(int))), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/quota/offset"), Value: aws.String(strconv.Itoa(d["offset"].(int))), }) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpAdd), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpAdd, Path: aws.String("/quota/period"), Value: aws.String(d["period"].(string)), }) @@ -453,7 +454,7 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i UsagePlanId: aws.String(d.Id()), } - _, err := conn.UpdateUsagePlanWithContext(ctx, input) + _, err := conn.UpdateUsagePlan(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway Usage Plan (%s): %s", d.Id(), err) @@ -465,24 +466,24 @@ func resourceUsagePlanUpdate(ctx context.Context, d *schema.ResourceData, meta i func resourceUsagePlanDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) // Removing existing api stages associated if apistages, ok := d.GetOk("api_stages"); ok { stages := apistages.(*schema.Set) - operations := []*apigateway.PatchOperation{} + operations := []awstypes.PatchOperation{} for _, v := range stages.List() { sv := v.(map[string]interface{}) - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String(apigateway.OpRemove), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.OpRemove, Path: aws.String("/apiStages"), Value: aws.String(fmt.Sprintf("%s:%s", sv["api_id"].(string), sv["stage"].(string))), }) } - _, err := conn.UpdateUsagePlanWithContext(ctx, &apigateway.UpdateUsagePlanInput{ + _, err := conn.UpdateUsagePlan(ctx, &apigateway.UpdateUsagePlanInput{ PatchOperations: operations, UsagePlanId: aws.String(d.Id()), }) @@ -493,11 +494,11 @@ func resourceUsagePlanDelete(ctx context.Context, d *schema.ResourceData, meta i } log.Printf("[DEBUG] Deleting API Gateway Usage Plan: %s", d.Id()) - _, err := conn.DeleteUsagePlanWithContext(ctx, &apigateway.DeleteUsagePlanInput{ + _, err := conn.DeleteUsagePlan(ctx, &apigateway.DeleteUsagePlanInput{ UsagePlanId: aws.String(d.Id()), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -508,14 +509,14 @@ func resourceUsagePlanDelete(ctx context.Context, d *schema.ResourceData, meta i return diags } -func FindUsagePlanByID(ctx context.Context, conn *apigateway.APIGateway, id string) (*apigateway.UsagePlan, error) { +func FindUsagePlanByID(ctx context.Context, conn *apigateway.Client, id string) (*apigateway.GetUsagePlanOutput, error) { input := &apigateway.GetUsagePlanInput{ UsagePlanId: aws.String(id), } - output, err := conn.GetUsagePlanWithContext(ctx, input) + output, err := conn.GetUsagePlan(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, @@ -533,11 +534,11 @@ func FindUsagePlanByID(ctx context.Context, conn *apigateway.APIGateway, id stri return output, nil } -func expandAPIStages(s *schema.Set) []*apigateway.ApiStage { - stages := []*apigateway.ApiStage{} +func expandAPIStages(s *schema.Set) []awstypes.ApiStage { + stages := []awstypes.ApiStage{} for _, stageRaw := range s.List() { - stage := &apigateway.ApiStage{} + stage := awstypes.ApiStage{} mStage := stageRaw.(map[string]interface{}) if v, ok := mStage["api_id"].(string); ok && v != "" { @@ -558,58 +559,58 @@ func expandAPIStages(s *schema.Set) []*apigateway.ApiStage { return stages } -func expandQuotaSettings(l []interface{}) *apigateway.QuotaSettings { +func expandQuotaSettings(l []interface{}) *awstypes.QuotaSettings { if len(l) == 0 { return nil } m := l[0].(map[string]interface{}) - qs := &apigateway.QuotaSettings{} + qs := &awstypes.QuotaSettings{} if v, ok := m["limit"].(int); ok { - qs.Limit = aws.Int64(int64(v)) + qs.Limit = int32(v) } if v, ok := m["offset"].(int); ok { - qs.Offset = aws.Int64(int64(v)) + qs.Offset = int32(v) } if v, ok := m["period"].(string); ok && v != "" { - qs.Period = aws.String(v) + qs.Period = awstypes.QuotaPeriodType(v) } return qs } -func expandThrottleSettings(l []interface{}) *apigateway.ThrottleSettings { +func expandThrottleSettings(l []interface{}) *awstypes.ThrottleSettings { if len(l) == 0 { return nil } m := l[0].(map[string]interface{}) - ts := &apigateway.ThrottleSettings{} + ts := &awstypes.ThrottleSettings{} if sv, ok := m["burst_limit"].(int); ok { - ts.BurstLimit = aws.Int64(int64(sv)) + ts.BurstLimit = int32(sv) } if sv, ok := m["rate_limit"].(float64); ok { - ts.RateLimit = aws.Float64(sv) + ts.RateLimit = sv } return ts } -func flattenAPIStages(s []*apigateway.ApiStage) []map[string]interface{} { +func flattenAPIStages(s []awstypes.ApiStage) []map[string]interface{} { stages := make([]map[string]interface{}, 0) for _, bd := range s { if bd.ApiId != nil && bd.Stage != nil { stage := make(map[string]interface{}) - stage["api_id"] = aws.StringValue(bd.ApiId) - stage["stage"] = aws.StringValue(bd.Stage) + stage["api_id"] = aws.ToString(bd.ApiId) + stage["stage"] = aws.ToString(bd.Stage) stage["throttle"] = flattenThrottleSettingsMap(bd.Throttle) stages = append(stages, stage) @@ -623,52 +624,39 @@ func flattenAPIStages(s []*apigateway.ApiStage) []map[string]interface{} { return nil } -func flattenThrottleSettings(s *apigateway.ThrottleSettings) []map[string]interface{} { +func flattenThrottleSettings(s *awstypes.ThrottleSettings) []map[string]interface{} { settings := make(map[string]interface{}) if s == nil { return nil } - if s.BurstLimit != nil { - settings["burst_limit"] = aws.Int64Value(s.BurstLimit) - } - - if s.RateLimit != nil { - settings["rate_limit"] = aws.Float64Value(s.RateLimit) - } + settings["burst_limit"] = s.BurstLimit + settings["rate_limit"] = s.RateLimit return []map[string]interface{}{settings} } -func flattenQuotaSettings(s *apigateway.QuotaSettings) []map[string]interface{} { +func flattenQuotaSettings(s *awstypes.QuotaSettings) []map[string]interface{} { settings := make(map[string]interface{}) if s == nil { return nil } - if s.Limit != nil { - settings["limit"] = aws.Int64Value(s.Limit) - } - - if s.Offset != nil { - settings["offset"] = aws.Int64Value(s.Offset) - } - - if s.Period != nil { - settings["period"] = aws.StringValue(s.Period) - } + settings["limit"] = s.Limit + settings["offset"] = s.Offset + settings["period"] = s.Period return []map[string]interface{}{settings} } -func expandThrottleSettingsList(tfList []interface{}) map[string]*apigateway.ThrottleSettings { +func expandThrottleSettingsList(tfList []interface{}) map[string]awstypes.ThrottleSettings { if len(tfList) == 0 { return nil } - apiObjects := map[string]*apigateway.ThrottleSettings{} + apiObjects := map[string]awstypes.ThrottleSettings{} for _, tfMapRaw := range tfList { tfMap, ok := tfMapRaw.(map[string]interface{}) @@ -677,14 +665,14 @@ func expandThrottleSettingsList(tfList []interface{}) map[string]*apigateway.Thr continue } - apiObject := &apigateway.ThrottleSettings{} + apiObject := awstypes.ThrottleSettings{} - if v, ok := tfMap["burst_limit"].(int); ok { - apiObject.BurstLimit = aws.Int64(int64(v)) + if v, ok := tfMap["burst_limit"].(int32); ok { + apiObject.BurstLimit = v } if v, ok := tfMap["rate_limit"].(float64); ok { - apiObject.RateLimit = aws.Float64(v) + apiObject.RateLimit = v } if v, ok := tfMap["path"].(string); ok && v != "" { @@ -695,7 +683,7 @@ func expandThrottleSettingsList(tfList []interface{}) map[string]*apigateway.Thr return apiObjects } -func flattenThrottleSettingsMap(apiObjects map[string]*apigateway.ThrottleSettings) []interface{} { +func flattenThrottleSettingsMap(apiObjects map[string]awstypes.ThrottleSettings) []interface{} { if len(apiObjects) == 0 { return nil } @@ -703,14 +691,10 @@ func flattenThrottleSettingsMap(apiObjects map[string]*apigateway.ThrottleSettin var tfList []interface{} for k, apiObject := range apiObjects { - if apiObject == nil { - continue - } - tfList = append(tfList, map[string]interface{}{ "path": k, - "rate_limit": aws.Float64Value(apiObject.RateLimit), - "burst_limit": aws.Int64Value(apiObject.BurstLimit), + "rate_limit": apiObject.RateLimit, + "burst_limit": apiObject.BurstLimit, }) } diff --git a/internal/service/apigateway/usage_plan_key.go b/internal/service/apigateway/usage_plan_key.go index 9e543b6e755..100a747eec1 100644 --- a/internal/service/apigateway/usage_plan_key.go +++ b/internal/service/apigateway/usage_plan_key.go @@ -9,13 +9,14 @@ import ( "log" "strings" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" ) @@ -72,7 +73,7 @@ func ResourceUsagePlanKey() *schema.Resource { func resourceUsagePlanKeyCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.CreateUsagePlanKeyInput{ KeyId: aws.String(d.Get("key_id").(string)), @@ -80,20 +81,20 @@ func resourceUsagePlanKeyCreate(ctx context.Context, d *schema.ResourceData, met UsagePlanId: aws.String(d.Get("usage_plan_id").(string)), } - output, err := conn.CreateUsagePlanKeyWithContext(ctx, input) + output, err := conn.CreateUsagePlanKey(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway Usage Plan Key: %s", err) } - d.SetId(aws.StringValue(output.Id)) + d.SetId(aws.ToString(output.Id)) return append(diags, resourceUsagePlanKeyRead(ctx, d, meta)...) } func resourceUsagePlanKeyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) upk, err := FindUsagePlanKeyByTwoPartKey(ctx, conn, d.Get("usage_plan_id").(string), d.Get("key_id").(string)) @@ -116,15 +117,15 @@ func resourceUsagePlanKeyRead(ctx context.Context, d *schema.ResourceData, meta func resourceUsagePlanKeyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) log.Printf("[DEBUG] Deleting API Gateway Usage Plan Key: %s", d.Id()) - _, err := conn.DeleteUsagePlanKeyWithContext(ctx, &apigateway.DeleteUsagePlanKeyInput{ + _, err := conn.DeleteUsagePlanKey(ctx, &apigateway.DeleteUsagePlanKeyInput{ KeyId: aws.String(d.Get("key_id").(string)), UsagePlanId: aws.String(d.Get("usage_plan_id").(string)), }) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } @@ -135,15 +136,15 @@ func resourceUsagePlanKeyDelete(ctx context.Context, d *schema.ResourceData, met return diags } -func FindUsagePlanKeyByTwoPartKey(ctx context.Context, conn *apigateway.APIGateway, usagePlanID, keyID string) (*apigateway.UsagePlanKey, error) { +func FindUsagePlanKeyByTwoPartKey(ctx context.Context, conn *apigateway.Client, usagePlanID, keyID string) (*apigateway.GetUsagePlanKeyOutput, error) { input := &apigateway.GetUsagePlanKeyInput{ KeyId: aws.String(keyID), UsagePlanId: aws.String(usagePlanID), } - output, err := conn.GetUsagePlanKeyWithContext(ctx, input) + output, err := conn.GetUsagePlanKey(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil, &retry.NotFoundError{ LastError: err, LastRequest: input, diff --git a/internal/service/apigateway/usage_plan_key_test.go b/internal/service/apigateway/usage_plan_key_test.go index dff72876351..4a5cb92bf77 100644 --- a/internal/service/apigateway/usage_plan_key_test.go +++ b/internal/service/apigateway/usage_plan_key_test.go @@ -8,7 +8,7 @@ import ( "fmt" "testing" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -21,7 +21,7 @@ import ( func TestAccAPIGatewayUsagePlanKey_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlanKey + var conf apigateway.GetUsagePlanKeyOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) apiGatewayApiKeyResourceName := "aws_api_gateway_api_key.test" apiGatewayUsagePlanResourceName := "aws_api_gateway_usage_plan.test" @@ -56,7 +56,7 @@ func TestAccAPIGatewayUsagePlanKey_basic(t *testing.T) { func TestAccAPIGatewayUsagePlanKey_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlanKey + var conf apigateway.GetUsagePlanKeyOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan_key.test" @@ -80,7 +80,7 @@ func TestAccAPIGatewayUsagePlanKey_disappears(t *testing.T) { func TestAccAPIGatewayUsagePlanKey_KeyID_concurrency(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlanKey + var conf apigateway.GetUsagePlanKeyOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resource.ParallelTest(t, resource.TestCase{ @@ -108,7 +108,7 @@ func TestAccAPIGatewayUsagePlanKey_KeyID_concurrency(t *testing.T) { }) } -func testAccCheckUsagePlanKeyExists(ctx context.Context, n string, v *apigateway.UsagePlanKey) resource.TestCheckFunc { +func testAccCheckUsagePlanKeyExists(ctx context.Context, n string, v *apigateway.GetUsagePlanKeyOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -119,7 +119,7 @@ func testAccCheckUsagePlanKeyExists(ctx context.Context, n string, v *apigateway return fmt.Errorf("No API Gateway Usage Plan Key ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindUsagePlanKeyByTwoPartKey(ctx, conn, rs.Primary.Attributes["usage_plan_id"], rs.Primary.Attributes["key_id"]) @@ -135,7 +135,7 @@ func testAccCheckUsagePlanKeyExists(ctx context.Context, n string, v *apigateway func testAccCheckUsagePlanKeyDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_usage_plan_key" { diff --git a/internal/service/apigateway/usage_plan_test.go b/internal/service/apigateway/usage_plan_test.go index ded28c1faf8..a56e01360a9 100644 --- a/internal/service/apigateway/usage_plan_test.go +++ b/internal/service/apigateway/usage_plan_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" "github.com/hashicorp/terraform-plugin-testing/helper/resource" "github.com/hashicorp/terraform-plugin-testing/terraform" @@ -22,7 +22,7 @@ import ( func TestAccAPIGatewayUsagePlan_basic(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) updatedName := sdkacctest.RandomWithPrefix("tf-acc-test-2") resourceName := "aws_api_gateway_usage_plan.test" @@ -64,7 +64,7 @@ func TestAccAPIGatewayUsagePlan_basic(t *testing.T) { func TestAccAPIGatewayUsagePlan_tags(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -112,7 +112,7 @@ func TestAccAPIGatewayUsagePlan_tags(t *testing.T) { func TestAccAPIGatewayUsagePlan_description(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -167,7 +167,7 @@ func TestAccAPIGatewayUsagePlan_description(t *testing.T) { func TestAccAPIGatewayUsagePlan_productCode(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -216,7 +216,7 @@ func TestAccAPIGatewayUsagePlan_productCode(t *testing.T) { func TestAccAPIGatewayUsagePlan_throttling(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -272,7 +272,7 @@ func TestAccAPIGatewayUsagePlan_throttling(t *testing.T) { // https://github.com/hashicorp/terraform-provider-aws/issues/2057 func TestAccAPIGatewayUsagePlan_throttlingInitialRateLimit(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -300,7 +300,7 @@ func TestAccAPIGatewayUsagePlan_throttlingInitialRateLimit(t *testing.T) { func TestAccAPIGatewayUsagePlan_quota(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -357,7 +357,7 @@ func TestAccAPIGatewayUsagePlan_quota(t *testing.T) { func TestAccAPIGatewayUsagePlan_apiStages(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -442,7 +442,7 @@ func TestAccAPIGatewayUsagePlan_apiStages(t *testing.T) { func TestAccAPIGatewayUsagePlan_APIStages_multiple(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -476,7 +476,7 @@ func TestAccAPIGatewayUsagePlan_APIStages_multiple(t *testing.T) { func TestAccAPIGatewayUsagePlan_APIStages_throttle(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -535,7 +535,7 @@ func TestAccAPIGatewayUsagePlan_APIStages_throttle(t *testing.T) { func TestAccAPIGatewayUsagePlan_disappears(t *testing.T) { ctx := acctest.Context(t) - var conf apigateway.UsagePlan + var conf apigateway.GetUsagePlanOutput rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) resourceName := "aws_api_gateway_usage_plan.test" @@ -558,7 +558,7 @@ func TestAccAPIGatewayUsagePlan_disappears(t *testing.T) { }) } -func testAccCheckUsagePlanExists(ctx context.Context, n string, v *apigateway.UsagePlan) resource.TestCheckFunc { +func testAccCheckUsagePlanExists(ctx context.Context, n string, v *apigateway.GetUsagePlanOutput) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -569,7 +569,7 @@ func testAccCheckUsagePlanExists(ctx context.Context, n string, v *apigateway.Us return fmt.Errorf("No API Gateway Usage Plan ID is set") } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) output, err := tfapigateway.FindUsagePlanByID(ctx, conn, rs.Primary.ID) @@ -585,7 +585,7 @@ func testAccCheckUsagePlanExists(ctx context.Context, n string, v *apigateway.Us func testAccCheckUsagePlanDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_usage_plan" { diff --git a/internal/service/apigateway/validate.go b/internal/service/apigateway/validate.go index aacd02b7ac5..a7c1e14174b 100644 --- a/internal/service/apigateway/validate.go +++ b/internal/service/apigateway/validate.go @@ -6,9 +6,10 @@ package apigateway import ( "fmt" - "github.com/aws/aws-sdk-go/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "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/enum" ) func validHTTPMethod() schema.SchemaValidateFunc { @@ -24,26 +25,23 @@ func validHTTPMethod() schema.SchemaValidateFunc { }, false) } -func validIntegrationContentHandling() schema.SchemaValidateFunc { - return validation.StringInSlice([]string{ - apigateway.ContentHandlingStrategyConvertToBinary, - apigateway.ContentHandlingStrategyConvertToText, - }, false) +func validIntegrationContentHandling() schema.SchemaValidateDiagFunc { + return enum.Validate[awstypes.ContentHandlingStrategy]() } func validUsagePlanQuotaSettings(v map[string]interface{}) (errors []error) { period := v["period"].(string) offset := v["offset"].(int) - if period == apigateway.QuotaPeriodTypeDay && offset != 0 { + if period == string(awstypes.QuotaPeriodTypeDay) && offset != 0 { errors = append(errors, fmt.Errorf("Usage Plan quota offset must be zero in the DAY period")) } - if period == apigateway.QuotaPeriodTypeWeek && (offset < 0 || offset > 6) { + if period == string(awstypes.QuotaPeriodTypeWeek) && (offset < 0 || offset > 6) { errors = append(errors, fmt.Errorf("Usage Plan quota offset must be between 0 and 6 inclusive in the WEEK period")) } - if period == apigateway.QuotaPeriodTypeMonth && (offset < 0 || offset > 27) { + if period == string(awstypes.QuotaPeriodTypeMonth) && (offset < 0 || offset > 27) { errors = append(errors, fmt.Errorf("Usage Plan quota offset must be between 0 and 27 inclusive in the MONTH period")) } diff --git a/internal/service/apigateway/vpc_link.go b/internal/service/apigateway/vpc_link.go index c870a1ed301..da1b6c4bbe3 100644 --- a/internal/service/apigateway/vpc_link.go +++ b/internal/service/apigateway/vpc_link.go @@ -8,13 +8,14 @@ import ( "fmt" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/arn" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/aws/arn" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" @@ -65,23 +66,23 @@ func ResourceVPCLink() *schema.Resource { func resourceVPCLinkCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.CreateVpcLinkInput{ Name: aws.String(d.Get("name").(string)), - TargetArns: flex.ExpandStringList(d.Get("target_arns").([]interface{})), + TargetArns: flex.ExpandStringValueList(d.Get("target_arns").([]interface{})), Tags: getTagsIn(ctx), } if v, ok := d.GetOk("description"); ok { input.Description = aws.String(v.(string)) } - resp, err := conn.CreateVpcLinkWithContext(ctx, input) + resp, err := conn.CreateVpcLink(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway VPC Link (%s): %s", d.Get("name").(string), err) } - d.SetId(aws.StringValue(resp.Id)) + d.SetId(aws.ToString(resp.Id)) if err := waitVPCLinkAvailable(ctx, conn, d.Id()); err != nil { return sdkdiag.AppendErrorf(diags, "creating API Gateway VPC Link (%s): waiting for completion: %s", d.Get("name").(string), err) @@ -92,15 +93,15 @@ func resourceVPCLinkCreate(ctx context.Context, d *schema.ResourceData, meta int func resourceVPCLinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.GetVpcLinkInput{ VpcLinkId: aws.String(d.Id()), } - resp, err := conn.GetVpcLinkWithContext(ctx, input) + resp, err := conn.GetVpcLink(ctx, input) if err != nil { - if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if !d.IsNewResource() && errs.IsA[*awstypes.NotFoundException](err) { log.Printf("[WARN] API Gateway VPC Link %s not found, removing from state", d.Id()) d.SetId("") return diags @@ -120,7 +121,7 @@ func resourceVPCLinkRead(ctx context.Context, d *schema.ResourceData, meta inter d.Set("name", resp.Name) d.Set("description", resp.Description) - if err := d.Set("target_arns", flex.FlattenStringList(resp.TargetArns)); err != nil { + if err := d.Set("target_arns", flex.FlattenStringValueList(resp.TargetArns)); err != nil { return sdkdiag.AppendErrorf(diags, "reading API Gateway VPC Link (%s): %s", d.Id(), err) } @@ -129,21 +130,21 @@ func resourceVPCLinkRead(ctx context.Context, d *schema.ResourceData, meta inter func resourceVPCLinkUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) - operations := make([]*apigateway.PatchOperation, 0) + operations := make([]awstypes.PatchOperation, 0) if d.HasChange("name") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String("replace"), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.Op("replace"), Path: aws.String("/name"), Value: aws.String(d.Get("name").(string)), }) } if d.HasChange("description") { - operations = append(operations, &apigateway.PatchOperation{ - Op: aws.String("replace"), + operations = append(operations, awstypes.PatchOperation{ + Op: awstypes.Op("replace"), Path: aws.String("/description"), Value: aws.String(d.Get("description").(string)), }) @@ -154,7 +155,7 @@ func resourceVPCLinkUpdate(ctx context.Context, d *schema.ResourceData, meta int PatchOperations: operations, } - _, err := conn.UpdateVpcLinkWithContext(ctx, input) + _, err := conn.UpdateVpcLink(ctx, input) if err != nil { return sdkdiag.AppendErrorf(diags, "updating API Gateway VPC Link (%s): %s", d.Id(), err) } @@ -168,15 +169,15 @@ func resourceVPCLinkUpdate(ctx context.Context, d *schema.ResourceData, meta int func resourceVPCLinkDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.DeleteVpcLinkInput{ VpcLinkId: aws.String(d.Id()), } - _, err := conn.DeleteVpcLinkWithContext(ctx, input) + _, err := conn.DeleteVpcLink(ctx, input) - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return diags } diff --git a/internal/service/apigateway/vpc_link_data_source.go b/internal/service/apigateway/vpc_link_data_source.go index 0acf4550251..d4106e4de4b 100644 --- a/internal/service/apigateway/vpc_link_data_source.go +++ b/internal/service/apigateway/vpc_link_data_source.go @@ -7,14 +7,16 @@ import ( "context" "log" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "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/sdkdiag" "github.com/hashicorp/terraform-provider-aws/internal/flex" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" + "github.com/hashicorp/terraform-provider-aws/internal/tfresource" ) // @SDKDataSource("aws_api_gateway_vpc_link") @@ -56,41 +58,40 @@ func DataSourceVPCLink() *schema.Resource { func dataSourceVPCLinkRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { var diags diag.Diagnostics - conn := meta.(*conns.AWSClient).APIGatewayConn(ctx) + conn := meta.(*conns.AWSClient).APIGatewayClient(ctx) ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig params := &apigateway.GetVpcLinksInput{} target := d.Get("name") - var matchedVpcLinks []*apigateway.UpdateVpcLinkOutput - log.Printf("[DEBUG] Reading API Gateway VPC links: %s", params) - err := conn.GetVpcLinksPagesWithContext(ctx, params, func(page *apigateway.GetVpcLinksOutput, lastPage bool) bool { + var matchedVpcLinks []awstypes.VpcLink + log.Printf("[DEBUG] Reading API Gateway VPC links: %+v", params) + + pages := apigateway.NewGetVpcLinksPaginator(conn, params) + for pages.HasMorePages() { + page, err := pages.NextPage(ctx) + if err != nil { + return sdkdiag.AppendErrorf(diags, "describing API Gateway VPC links: %s", err) + } + for _, api := range page.Items { - if aws.StringValue(api.Name) == target { + if aws.ToString(api.Name) == target { matchedVpcLinks = append(matchedVpcLinks, api) } } - return !lastPage - }) - if err != nil { - return sdkdiag.AppendErrorf(diags, "describing API Gateway VPC links: %s", err) } - if len(matchedVpcLinks) == 0 { - return sdkdiag.AppendErrorf(diags, "no API Gateway VPC link with name %q found in this region", target) - } - if len(matchedVpcLinks) > 1 { - return sdkdiag.AppendErrorf(diags, "multiple API Gateway VPC links with name %q found in this region", target) + match, err := tfresource.AssertSingleValueResult(matchedVpcLinks) + if err != nil { + return sdkdiag.AppendErrorf(diags, "Exactly one API Gateway VPC link with name %q not found in this region", target) } - match := matchedVpcLinks[0] - - d.SetId(aws.StringValue(match.Id)) + d.SetId(aws.ToString(match.Id)) d.Set("name", match.Name) d.Set("status", match.Status) d.Set("status_message", match.StatusMessage) d.Set("description", match.Description) - d.Set("target_arns", flex.FlattenStringList(match.TargetArns)) + d.Set("target_arns", flex.FlattenStringValueList(match.TargetArns)) if err := d.Set("tags", KeyValueTags(ctx, match.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { return sdkdiag.AppendErrorf(diags, "setting tags: %s", err) diff --git a/internal/service/apigateway/vpc_link_test.go b/internal/service/apigateway/vpc_link_test.go index 6f7f6d29263..9b405c221e4 100644 --- a/internal/service/apigateway/vpc_link_test.go +++ b/internal/service/apigateway/vpc_link_test.go @@ -9,14 +9,15 @@ import ( "testing" "github.com/YakDriver/regexache" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" - "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/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/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" tfapigateway "github.com/hashicorp/terraform-provider-aws/internal/service/apigateway" "github.com/hashicorp/terraform-provider-aws/names" ) @@ -144,7 +145,7 @@ func TestAccAPIGatewayVPCLink_disappears(t *testing.T) { func testAccCheckVPCLinkDestroy(ctx context.Context) resource.TestCheckFunc { return func(s *terraform.State) error { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) for _, rs := range s.RootModule().Resources { if rs.Type != "aws_api_gateway_vpc_link" { @@ -155,9 +156,9 @@ func testAccCheckVPCLinkDestroy(ctx context.Context) resource.TestCheckFunc { VpcLinkId: aws.String(rs.Primary.ID), } - _, err := conn.GetVpcLinkWithContext(ctx, input) + _, err := conn.GetVpcLink(ctx, input) if err != nil { - if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) { + if errs.IsA[*awstypes.NotFoundException](err) { return nil } return err @@ -177,13 +178,13 @@ func testAccCheckVPCLinkExists(ctx context.Context, name string) resource.TestCh return fmt.Errorf("Not found: %s", name) } - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) input := &apigateway.GetVpcLinkInput{ VpcLinkId: aws.String(rs.Primary.ID), } - _, err := conn.GetVpcLinkWithContext(ctx, input) + _, err := conn.GetVpcLink(ctx, input) return err } } diff --git a/internal/service/apigateway/wait.go b/internal/service/apigateway/wait.go index 01f06c848fa..df54024316b 100644 --- a/internal/service/apigateway/wait.go +++ b/internal/service/apigateway/wait.go @@ -7,8 +7,10 @@ import ( "context" "time" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go-v2/service/apigateway" + awstypes "github.com/aws/aws-sdk-go-v2/service/apigateway/types" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" + "github.com/hashicorp/terraform-provider-aws/internal/enum" ) const ( @@ -25,10 +27,10 @@ const ( stageCacheUpdateTimeout = 30 * time.Minute ) -func waitVPCLinkAvailable(ctx context.Context, conn *apigateway.APIGateway, vpcLinkId string) error { +func waitVPCLinkAvailable(ctx context.Context, conn *apigateway.Client, vpcLinkId string) error { stateConf := &retry.StateChangeConf{ - Pending: []string{apigateway.VpcLinkStatusPending}, - Target: []string{apigateway.VpcLinkStatusAvailable}, + Pending: enum.Slice(awstypes.VpcLinkStatusPending), + Target: enum.Slice(awstypes.VpcLinkStatusAvailable), Refresh: vpcLinkStatus(ctx, conn, vpcLinkId), Timeout: vpcLinkAvailableTimeout, MinTimeout: 3 * time.Second, @@ -39,13 +41,9 @@ func waitVPCLinkAvailable(ctx context.Context, conn *apigateway.APIGateway, vpcL return err } -func waitVPCLinkDeleted(ctx context.Context, conn *apigateway.APIGateway, vpcLinkId string) error { +func waitVPCLinkDeleted(ctx context.Context, conn *apigateway.Client, vpcLinkId string) error { stateConf := retry.StateChangeConf{ - Pending: []string{ - apigateway.VpcLinkStatusPending, - apigateway.VpcLinkStatusAvailable, - apigateway.VpcLinkStatusDeleting, - }, + Pending: enum.Slice(awstypes.VpcLinkStatusPending, awstypes.VpcLinkStatusAvailable, awstypes.VpcLinkStatusDeleting), Target: []string{}, Timeout: vpcLinkDeleteTimeout, MinTimeout: 1 * time.Second, @@ -57,46 +55,38 @@ func waitVPCLinkDeleted(ctx context.Context, conn *apigateway.APIGateway, vpcLin return err } -func waitStageCacheAvailable(ctx context.Context, conn *apigateway.APIGateway, restApiId, name string) (*apigateway.Stage, error) { +func waitStageCacheAvailable(ctx context.Context, conn *apigateway.Client, restApiId, name string) (*awstypes.Stage, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ - apigateway.CacheClusterStatusCreateInProgress, - apigateway.CacheClusterStatusDeleteInProgress, - apigateway.CacheClusterStatusFlushInProgress, - }, - Target: []string{apigateway.CacheClusterStatusAvailable}, + Pending: enum.Slice(awstypes.CacheClusterStatusCreateInProgress, awstypes.CacheClusterStatusDeleteInProgress, awstypes.CacheClusterStatusFlushInProgress), + Target: enum.Slice(awstypes.CacheClusterStatusAvailable), Refresh: stageCacheStatus(ctx, conn, restApiId, name), Timeout: stageCacheAvailableTimeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*apigateway.Stage); ok { + if output, ok := outputRaw.(*awstypes.Stage); ok { return output, err } return nil, err } -func waitStageCacheUpdated(ctx context.Context, conn *apigateway.APIGateway, restApiId, name string) (*apigateway.Stage, error) { +func waitStageCacheUpdated(ctx context.Context, conn *apigateway.Client, restApiId, name string) (*awstypes.Stage, error) { stateConf := &retry.StateChangeConf{ - Pending: []string{ - apigateway.CacheClusterStatusCreateInProgress, - apigateway.CacheClusterStatusFlushInProgress, - }, - Target: []string{ - apigateway.CacheClusterStatusAvailable, + Pending: enum.Slice(awstypes.CacheClusterStatusCreateInProgress, awstypes.CacheClusterStatusFlushInProgress), + Target: enum.Slice(awstypes.CacheClusterStatusAvailable, // There's an AWS API bug (raised & confirmed in Sep 2016 by support) // which causes the stage to remain in deletion state forever - apigateway.CacheClusterStatusDeleteInProgress, - }, + // TODO: Check if this bug still exists in AWS SDK v2 + awstypes.CacheClusterStatusDeleteInProgress), Refresh: stageCacheStatus(ctx, conn, restApiId, name), Timeout: stageCacheUpdateTimeout, } outputRaw, err := stateConf.WaitForStateContext(ctx) - if output, ok := outputRaw.(*apigateway.Stage); ok { + if output, ok := outputRaw.(*awstypes.Stage); ok { return output, err } diff --git a/internal/service/apigatewayv2/stage_test.go b/internal/service/apigatewayv2/stage_test.go index 6aba5d79a6e..58236cefcd3 100644 --- a/internal/service/apigatewayv2/stage_test.go +++ b/internal/service/apigatewayv2/stage_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/YakDriver/regexache" + "github.com/aws/aws-sdk-go-v2/service/apigateway" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" "github.com/aws/aws-sdk-go/service/apigatewayv2" "github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr" sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest" @@ -1541,9 +1541,9 @@ resource "aws_apigatewayv2_stage" "test" { // testAccPreCheckAPIGatewayAccountCloudWatchRoleARN checks whether a CloudWatch role ARN has been configured in the current AWS region. func testAccPreCheckAPIGatewayAccountCloudWatchRoleARN(ctx context.Context, t *testing.T) { - conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayConn(ctx) + conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx) - output, err := conn.GetAccountWithContext(ctx, &apigateway.GetAccountInput{}) + output, err := conn.GetAccount(ctx, &apigateway.GetAccountInput{}) if acctest.PreCheckSkipError(err) { t.Skipf("skipping tests: %s", err) diff --git a/names/data/names_data.csv b/names/data/names_data.csv index 8d40ed8201c..852dbbbbc1c 100644 --- a/names/data/names_data.csv +++ b/names/data/names_data.csv @@ -9,7 +9,7 @@ amplify,amplify,amplify,amplify,,amplify,,,Amplify,Amplify,,1,,,aws_amplify_,,am amplifybackend,amplifybackend,amplifybackend,amplifybackend,,amplifybackend,,,AmplifyBackend,AmplifyBackend,,1,,,aws_amplifybackend_,,amplifybackend_,Amplify Backend,AWS,,x,,,,,AmplifyBackend,,, amplifyuibuilder,amplifyuibuilder,amplifyuibuilder,amplifyuibuilder,,amplifyuibuilder,,,AmplifyUIBuilder,AmplifyUIBuilder,,1,,,aws_amplifyuibuilder_,,amplifyuibuilder_,Amplify UI Builder,AWS,,x,,,,,AmplifyUIBuilder,,, ,,,,,,,,,,,,,,,,,Apache MXNet on AWS,AWS,x,,,,,,,,,Documentation -apigateway,apigateway,apigateway,apigateway,,apigateway,,,APIGateway,APIGateway,,1,,aws_api_gateway_,aws_apigateway_,,api_gateway_,API Gateway,Amazon,,,,,,,API Gateway,GetAccount,, +apigateway,apigateway,apigateway,apigateway,,apigateway,,,APIGateway,APIGateway,,,2,aws_api_gateway_,aws_apigateway_,,api_gateway_,API Gateway,Amazon,,,,,,,API Gateway,GetAccount,, apigatewaymanagementapi,apigatewaymanagementapi,apigatewaymanagementapi,apigatewaymanagementapi,,apigatewaymanagementapi,,,APIGatewayManagementAPI,ApiGatewayManagementApi,,1,,,aws_apigatewaymanagementapi_,,apigatewaymanagementapi_,API Gateway Management API,Amazon,,x,,,,,ApiGatewayManagementApi,,, apigatewayv2,apigatewayv2,apigatewayv2,apigatewayv2,,apigatewayv2,,,APIGatewayV2,ApiGatewayV2,,1,,,aws_apigatewayv2_,,apigatewayv2_,API Gateway V2,Amazon,,,,,,,ApiGatewayV2,GetApis,, appfabric,appfabric,appfabric,appfabric,,appfabric,,,AppFabric,AppFabric,,,2,,aws_appfabric_,,appfabric_,AppFabric,AWS,,,,,,,AppFabric,ListAppBundles,, diff --git a/names/names.go b/names/names.go index 79ff75317cf..143135079fd 100644 --- a/names/names.go +++ b/names/names.go @@ -27,6 +27,7 @@ import ( const ( AccessAnalyzerEndpointID = "access-analyzer" AMPEndpointID = "aps" + APIGatewayID = "apigateway" AthenaEndpointID = "athena" AuditManagerEndpointID = "auditmanager" BatchEndpointID = "batch"