Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

apigateway: Migrate to AWS SDK v2 #36445

Merged
merged 93 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
b9dfeaf
apigateway: Migrate to AWS SDK v2
mattburgess Mar 18, 2024
7c63059
Merge branch 'main' into HEAD
ewbankkit Apr 1, 2024
61c6dbe
r/aws_api_gateway_account: Reduce visibility.
ewbankkit Apr 1, 2024
6cc840b
r/aws_api_gateway_account: Serialize acceptance tests.
ewbankkit Apr 1, 2024
94a3b43
r/aws_api_gateway_api_key: Reduce visibility.
ewbankkit Apr 1, 2024
343f749
d/aws_api_gateway_api_key: Reduce visibility.
ewbankkit Apr 1, 2024
d760095
r/aws_api_gateway_authorizer: Reduce visibility.
ewbankkit Apr 2, 2024
9db8914
d/aws_api_gateway_authorizer: Reduce visibility.
ewbankkit Apr 2, 2024
583236d
d/aws_api_gateway_authorizers: Reduce visibility.
ewbankkit Apr 2, 2024
5d760e6
r/aws_api_gateway_base_path_mapping: Reduce visibility.
ewbankkit Apr 2, 2024
096ed25
r/aws_api_gateway_client_certificate: Reduce visibility.
ewbankkit Apr 2, 2024
4819247
r/aws_api_gateway_deployment: Reduce visibility.
ewbankkit Apr 2, 2024
c409806
r/aws_api_gateway_documentation_part: Reduce visibility.
ewbankkit Apr 2, 2024
65dc80b
r/aws_api_gateway_documentation_version: Reduce visibility.
ewbankkit Apr 2, 2024
f4dd226
r/aws_api_gateway_domain_name: Reduce visibility.
ewbankkit Apr 2, 2024
a437fcd
d/aws_api_gateway_export: Reduce visibility.
ewbankkit Apr 2, 2024
89ea554
r/aws_cloudwatch_dashboard: Correct sweeper.
ewbankkit Apr 2, 2024
13b9e34
Use 'flex.ExpandBoolValueMap'.
ewbankkit Apr 2, 2024
a1984b2
r/aws_api_gateway_rest_api: Reduce visibility.
ewbankkit Apr 2, 2024
7b9f520
r/aws_api_gateway_gateway_response: Reduce visibility.
ewbankkit Apr 2, 2024
39a8ebe
r/aws_api_gateway_integration_response: Reduce visibility.
ewbankkit Apr 2, 2024
f866f8f
r/aws_api_gateway_integration: Reduce visibility.
ewbankkit Apr 2, 2024
6511a4e
r/aws_api_gateway_method_response: Reduce visibility.
ewbankkit Apr 2, 2024
6da867c
r/aws_api_gateway_method_settings: Reduce visibility.
ewbankkit Apr 2, 2024
ed675a6
r/aws_api_gateway_method: Reduce visibility.
ewbankkit Apr 2, 2024
8437d90
r/aws_api_gateway_model: Reduce visibility.
ewbankkit Apr 2, 2024
8208edb
r/aws_api_gateway_request_validator: Reduce visibility.
ewbankkit Apr 3, 2024
864fd50
r/aws_api_gateway_resource: Reduce visibility.
ewbankkit Apr 3, 2024
72b3362
d/aws_api_gateway_resource: Reduce visibility.
ewbankkit Apr 3, 2024
af777d7
d/aws_api_gateway_rest_api: Reduce visibility.
ewbankkit Apr 3, 2024
841a15c
Add 'domainNameARN'.
ewbankkit Apr 3, 2024
74cac62
r/aws_api_gateway_rest_api_policy: Reduce visibility.
ewbankkit Apr 3, 2024
8667fab
d/aws_api_gateway_sdk: Reduce visibility.
ewbankkit Apr 3, 2024
7bbf9bb
r/aws_api_gateway_vpc_link: Reduce visibility.
ewbankkit Apr 3, 2024
e8cd6c7
d/aws_api_gateway_vpc_link: Reduce visibility.
ewbankkit Apr 3, 2024
8fa5ff1
r/aws_api_gateway_stage: Reduce visibility.
ewbankkit Apr 3, 2024
33eecc5
d/aws_api_gateway_domain_name: 'tags' is Computed-only.
ewbankkit Apr 3, 2024
7214732
Fix acceptance test compilation errors.
ewbankkit Apr 3, 2024
bc0d057
r/aws_api_gateway_usage_plan_key: Reduce visibility.
ewbankkit Apr 3, 2024
f622c51
r/aws_api_gateway_usage_plan: Reduce visibility.
ewbankkit Apr 3, 2024
d4287d4
'DefaultAuthorizerTTL' -> 'defaultAuthorizerTTL'.
ewbankkit Apr 3, 2024
940797d
apigateway: Tidy up sweepers.
ewbankkit Apr 3, 2024
618c578
r/aws_api_gateway_vpc_link: Tidy up acceptance tests.
ewbankkit Apr 3, 2024
d3f8f3a
d/aws_api_gateway_vpc_link: Tidy up acceptance tests.
ewbankkit Apr 3, 2024
65edb99
Acceptance test output:
ewbankkit Apr 3, 2024
d987c73
r/aws_api_gateway_authorizer: Tweak CustomizeDiff.
ewbankkit Apr 4, 2024
b0ed9bd
Handle 'NotFoundException' on resource Delete.
ewbankkit Apr 4, 2024
1261762
Use 'acctest.ConfigCompose'.
ewbankkit Apr 4, 2024
1b8ecb6
Add 'TestAccAPIGateway_serial'.
ewbankkit Apr 4, 2024
ddc048d
r/aws_api_gateway_method_settings: Serialize acceptance tests.
ewbankkit Apr 4, 2024
d632f6e
r/aws_api_gateway_method_settings: Setup account-level CloudWatch Log…
ewbankkit Apr 4, 2024
65d8138
Fix golangci-lint 'gomnd'.
ewbankkit Apr 4, 2024
de1112f
Fix golangci-lint 'unparam'.
ewbankkit Apr 4, 2024
90839b9
r/aws_api_gateway_integration: Correctly set 'connection_type'.
ewbankkit Apr 4, 2024
9bd45bc
r/aws_api_gateway_usage_plan: Fix 'burst_limit' diff.
ewbankkit Apr 4, 2024
9ca32f3
r/aws_api_gateway_rest_api_policy: Handle 'NotFoundException' on reso…
ewbankkit Apr 4, 2024
f352fe5
r/aws_api_gateway_authorizer: Retry deletion on 'ConflictException'.
ewbankkit Apr 4, 2024
73cc4f0
Add 'ImportStateVerifyIgnore' to fix acceptance tests.
ewbankkit Apr 4, 2024
70dcc49
r/aws_api_gateway_authorizer: Handle 'ConflictException' on resource …
ewbankkit Apr 4, 2024
6d3815d
r/aws_api_gateway_documentation_part: Add 'documentation_part_id' att…
ewbankkit Apr 4, 2024
e2f0a15
apigateway: Handle certain 'ConflictException's centrally.
ewbankkit Apr 4, 2024
dcd2b1b
r/aws_wafregional_byte_match_set: Reduce visibility.
ewbankkit Apr 5, 2024
1a2bff5
r/aws_wafregional_geo_match_set: Reduce visibility.
ewbankkit Apr 5, 2024
8b660a2
r/aws_wafregional_ipset: Reduce visibility.
ewbankkit Apr 5, 2024
01bcb84
d/aws_wafregional_ipset: Reduce visibility.
ewbankkit Apr 5, 2024
57e8153
r/aws_wafregional_rate_based_rule: Reduce visibility.
ewbankkit Apr 5, 2024
97c2bd3
d/aws_wafregional_rate_based_rule: Reduce visibility.
ewbankkit Apr 5, 2024
da23c70
r/aws_wafregional_regex_match_set: Reduce visibility.
ewbankkit Apr 5, 2024
8967973
r/aws_wafregional_regex_pattern_set: Reduce visibility.
ewbankkit Apr 5, 2024
a281e97
d/aws_wafregional_rule: Reduce visibility.
ewbankkit Apr 5, 2024
54032c6
r/aws_wafregional_rule_group: Reduce visibility.
ewbankkit Apr 5, 2024
069df59
r/aws_wafregional_rule: Reduce visibility.
ewbankkit Apr 5, 2024
2f4ee40
r/aws_wafregional_size_constraint_set: Reduce visibility.
ewbankkit Apr 5, 2024
eca49b7
r/aws_wafregional_sql_injection_match_set: Reduce visibility.
ewbankkit Apr 5, 2024
40f1956
d/aws_wafregional_subscribed_rule_group: Reduce visibility.
ewbankkit Apr 5, 2024
5c94345
r/aws_wafregional_web_acl_association: Reduce visibility.
ewbankkit Apr 5, 2024
6aacdae
r/aws_wafregional_web_acl: Reduce visibility.
ewbankkit Apr 5, 2024
bc0cf88
d/aws_wafregional_web_acl: Reduce visibility.
ewbankkit Apr 5, 2024
389d8f1
r/aws_wafregional_xss_match_set: Reduce visibility.
ewbankkit Apr 5, 2024
6edb76a
Make 'aws_wafregional_web_acl_association' more like 'aws_wafv2_web_a…
ewbankkit Apr 5, 2024
b3dea15
r/aws_wafregional_web_acl_association: Add configurable timeouts.
ewbankkit Apr 5, 2024
e8a6b2f
wafregional: Handle 'WAFNonexistentContainerException' and 'WAFNonexi…
ewbankkit Apr 5, 2024
3b07656
Acceptance test output:
ewbankkit Apr 5, 2024
4ad8b9b
r/aws_wafregional_regex_pattern_set: Add sweeper.
ewbankkit Apr 5, 2024
6d46b6d
r/aws_wafregional_regex_match_set: Tidy up sweeper.
ewbankkit Apr 5, 2024
551060f
wafregional: Handle 'WAFNonexistentContainerException' and 'WAFNonexi…
ewbankkit Apr 5, 2024
389c32f
Acceptance test output:
ewbankkit Apr 5, 2024
14b88aa
Fix 'TestAccAPIGatewayAPIKey_value'.
ewbankkit Apr 5, 2024
f47d4cb
r/aws_api_gateway_base_path_mapping: Fix acceptance testAccCheckBaseP…
ewbankkit Apr 5, 2024
dff07be
r/aws_api_gateway_stage: Serialize acceptance tests to fix 'BadReques…
ewbankkit Apr 5, 2024
dd74aba
Acceptance test output:
ewbankkit Apr 5, 2024
3e84bb0
Fix semgrep 'dgryski.semgrep-go.oddifsequence.odd-sequence-ifs'.
ewbankkit Apr 5, 2024
0af4208
Fix golangci-lint 'unparam'.
ewbankkit Apr 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changelog/36445.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/aws_api_gateway_documentation_part: Add `documentation_part_id` attribute
```

```release-note:enhancement
resource/aws_wafregional_web_acl_association: Add plan-time validation of `resource_arn`
```

```release-note:enhancement
resource/aws_wafregional_web_acl_association: Add configurable timeouts
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/acmpca v1.29.4
github.com/aws/aws-sdk-go-v2/service/amp v1.25.4
github.com/aws/aws-sdk-go-v2/service/amplify v1.21.5
github.com/aws/aws-sdk-go-v2/service/apigateway v1.23.6
github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.2
github.com/aws/aws-sdk-go-v2/service/appfabric v1.7.4
github.com/aws/aws-sdk-go-v2/service/appflow v1.41.4
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/aws/aws-sdk-go-v2/service/amp v1.25.4 h1:TgkApdPnCVX7RtHMcsswmUYsDnnj
github.com/aws/aws-sdk-go-v2/service/amp v1.25.4/go.mod h1:i5BA2ACkXa8Pzqinz/xEukdVJnMdfQLRcx7ftb5g0pk=
github.com/aws/aws-sdk-go-v2/service/amplify v1.21.5 h1:2r72Kx6V0U6js4KZryjZO+tzxri7dQ5nT0BHPXoWxwg=
github.com/aws/aws-sdk-go-v2/service/amplify v1.21.5/go.mod h1:DBFsAufxSC9f12Z3JCcqlErAAE6KHDGrHBe+KgNV1ZA=
github.com/aws/aws-sdk-go-v2/service/apigateway v1.23.6 h1:YZ4tYuH59Xd5q3bYmDqKXt8fQVJ19WPoq4lKzW1iLMg=
github.com/aws/aws-sdk-go-v2/service/apigateway v1.23.6/go.mod h1:3h9BDpayKgNNrpHZBvL7gCIeikqiE7oBxGGcrzmtLAM=
github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.2 h1:Nm1Pqug23c/Ib+/FgwYpFZiLJyuohWxy0bdCj28SFNE=
github.com/aws/aws-sdk-go-v2/service/appconfig v1.29.2/go.mod h1:Z4uxjsQCQYIZQYOf5js8AN9B5ZCFfwRkEHuiihgjHWs=
github.com/aws/aws-sdk-go-v2/service/appfabric v1.7.4 h1:xQyow1kdXLj4kcU9ja1MyZSFSlb1Ab4ZDYeTO/mSkRE=
Expand Down
6 changes: 3 additions & 3 deletions internal/conns/awsclient_gen.go

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

57 changes: 40 additions & 17 deletions internal/service/apigateway/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ package apigateway

import (
"context"
"log"

"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"
"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"
)

// @SDKResource("aws_api_gateway_account")
func ResourceAccount() *schema.Resource {
// @SDKResource("aws_api_gateway_account", name="Account")
func resourceAccount() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAccountUpdate,
ReadWithoutTimeout: resourceAccountRead,
Expand Down Expand Up @@ -67,34 +68,34 @@ 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 = []types.PatchOperation{{
Op: types.OpReplace,
Path: aws.String("/cloudwatchRoleArn"),
Value: aws.String(v.(string)),
}}
} else {
input.PatchOperations = []*apigateway.PatchOperation{{
Op: aws.String(apigateway.OpReplace),
input.PatchOperations = []types.PatchOperation{{
Op: types.OpReplace,
Path: aws.String("/cloudwatchRoleArn"),
Value: aws.String(""),
}}
}

_, 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[*types.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[*types.BadRequestException](err, "API Gateway could not successfully write to CloudWatch Logs using the ARN specified") {
return true, err
}

Expand All @@ -115,20 +116,42 @@ 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 := findAccount(ctx, conn)

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] API Gateway Account (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading API Gateway Account: %s", err)
}

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)
}

return diags
}

func findAccount(ctx context.Context, conn *apigateway.Client) (*apigateway.GetAccountOutput, error) {
input := &apigateway.GetAccountInput{}

output, err := conn.GetAccount(ctx, input)

if err != nil {
return nil, err
}

if output == nil {
return nil, tfresource.NewEmptyResultError(input)
}

return output, nil
}
4 changes: 2 additions & 2 deletions internal/service/apigateway/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"github.com/hashicorp/terraform-provider-aws/names"
)

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

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, names.APIGatewayServiceID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
Expand Down
60 changes: 31 additions & 29 deletions internal/service/apigateway/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"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"
Expand All @@ -27,12 +28,13 @@ import (

// @SDKResource("aws_api_gateway_api_key", name="API Key")
// @Tags(identifierAttribute="arn")
func ResourceAPIKey() *schema.Resource {
func resourceAPIKey() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceAPIKeyCreate,
ReadWithoutTimeout: resourceAPIKeyRead,
UpdateWithoutTimeout: resourceAPIKeyUpdate,
DeleteWithoutTimeout: resourceAPIKeyDelete,

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Expand Down Expand Up @@ -86,12 +88,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)),
Expand All @@ -101,22 +103,22 @@ 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())
apiKey, err := findAPIKeyByID(ctx, conn, d.Id())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] API Gateway API Key (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -148,40 +150,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) []types.PatchOperation {
operations := make([]types.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, types.PatchOperation{
Op: types.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, types.PatchOperation{
Op: types.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, types.PatchOperation{
Op: types.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, types.PatchOperation{
Op: types.OpReplace,
Path: aws.String("/customerId"),
Value: aws.String(d.Get("customer_id").(string)),
})
Expand All @@ -192,10 +194,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),
})
Expand All @@ -210,14 +212,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[*types.NotFoundException](err) {
return diags
}

Expand All @@ -228,15 +230,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[*types.NotFoundException](err) {
return nil, &retry.NotFoundError{
LastError: err,
LastRequest: input,
Expand Down
Loading
Loading