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

Adds Semgrep rules for casting of awserr #27991

Merged
merged 72 commits into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
493059c
Adds semgrep rule
gdavison Nov 23, 2022
14df84e
Update existing rule to expand conditional cases
gdavison Nov 23, 2022
52fc004
Adds another rule
gdavison Nov 23, 2022
c5625e6
Updates another existing rule
gdavison Nov 24, 2022
62914ab
Cleans up error handling
gdavison Nov 24, 2022
9f91d6c
Merge branch 'main' into td-awserr-casts
ewbankkit Jan 19, 2023
24ddeaa
Redshift: Fix semgrep 'aws-go-sdk-error-code-helper'.
ewbankkit Jan 19, 2023
0bb8654
r/aws_rds_cluster_parameter_group: Modernize.
ewbankkit Jan 19, 2023
feb76ea
r/aws_redshift_parameter_group: Modernize.
ewbankkit Jan 19, 2023
199471f
r/aws_opsworks_permission: Modernize.
ewbankkit Jan 19, 2023
334a14d
r/aws_opsworks_user_profile: Modernize.
ewbankkit Jan 19, 2023
353df87
r/aws_elasticache_security_group: Use 'tfawserr.ErrCodeEquals'.
ewbankkit Jan 19, 2023
97d08ab
r/aws_elasticache_subnet_group: Remove explicit cast to 'awserr.Error'.
ewbankkit Jan 20, 2023
02044f1
r/aws_ses_receipt_rule: Modernize.
ewbankkit Jan 20, 2023
99b8b71
r/aws_emr_fleet: Modernize.
ewbankkit Jan 20, 2023
74092f5
Remove 'testAccCheckInstanceGroupDestroy'.
ewbankkit Jan 20, 2023
9722d21
r/aws_iam_server_certificate: Modernize.
ewbankkit Jan 20, 2023
12957da
Simplify 'aws-go-sdk-error-code-helper'.
ewbankkit Jan 20, 2023
43ff85e
Merge branch 'main' into td-awserr-casts
ewbankkit Jan 20, 2023
b1aff11
r/aws_ses_receipt_rule: Add 'context.Context'.
ewbankkit Jan 20, 2023
c7e9eaa
r/aws_opsworks_user_profile: Add 'context.Context'.
ewbankkit Jan 20, 2023
d4c7c02
r/aws_opsworks_permission: Add 'context.Context'.
ewbankkit Jan 20, 2023
f16cf2e
r/aws_emr_instance_fleet: Add 'context.Context'.
ewbankkit Jan 20, 2023
e699ef1
Merge branch 'main' into td-awserr-casts
ewbankkit Feb 3, 2023
f8d852c
Various Context-related enhancements.
ewbankkit Feb 3, 2023
798bca7
Simplify 'aws-go-sdk-error-code-helper' semgrep rule.
ewbankkit Feb 3, 2023
d29e670
r/aws_api_gateway_api_key: Add 'FindAPIKeyByID'.
ewbankkit Feb 3, 2023
1d25b77
d/aws_api_gateway_api_key: Use 'FindAPIKeyByID'.
ewbankkit Feb 3, 2023
e09cd1a
d/aws_api_gateway_api_key: Tidy up acceptance test configuration.
ewbankkit Feb 4, 2023
f10dc66
r/aws_api_gateway_authorizer: Add 'FindAuthorizerByTwoPartKey'.
ewbankkit Feb 4, 2023
b55bf04
r/aws_api_gateway_client_certificate: Add 'FindClientCertificateByID'.
ewbankkit Feb 4, 2023
cd0c218
r/aws_api_gateway_gateway_response: Add 'FindGatewayResponseByTwoPart…
ewbankkit Feb 4, 2023
643d680
r/aws_api_gateway_integration_response: Add 'FindIntegrationResponseB…
ewbankkit Feb 4, 2023
ce80f53
r/aws_api_gateway_integration: Add 'FindIntegrationByThreePartKey'.
ewbankkit Feb 4, 2023
1e314c8
r/aws_api_gateway_method_response: Add 'FindMethodResponseByFourPartK…
ewbankkit Feb 4, 2023
fca7bfd
Move 'aws-go-sdk-error-code-helper' semgrep rule to its own file.
ewbankkit Feb 4, 2023
61c8526
r/aws_api_gateway_method: Add 'FindMethodByThreePartKey'.
ewbankkit Feb 4, 2023
b11dd74
r/aws_api_gateway_model: Add 'FindModelByTwoPartKey'.
ewbankkit Feb 4, 2023
1074f98
r/aws_api_gateway_request_validator: Add 'FindRequestValidatorByTwoPa…
ewbankkit Feb 5, 2023
df9618c
r/aws_api_gateway_usage_plan_key: Add 'FindUsagePlanKeyByTwoPartKey'.
ewbankkit Feb 5, 2023
6833f65
r/aws_api_gateway_resource: Add 'FindResourceByTwoPartKey'.
ewbankkit Feb 5, 2023
88e0193
r/aws_cognito_user: Add 'FindUserByTwoPartKey'.
ewbankkit Feb 5, 2023
142529a
r/aws_efs_mount_target: Add 'FindMountTargetByID'.
ewbankkit Feb 5, 2023
af9e4bb
r/aws_elasticache_security_group: Use 'tfawserr.ErrCodeEquals'.
ewbankkit Feb 5, 2023
dbf64f6
testAccCheckApplicationVersionDestroy: Use 'tfawserr.ErrCodeEquals'.
ewbankkit Feb 5, 2023
b9ae1da
elasticsearch/testAccCheckELBDestroy: Remove.
ewbankkit Feb 5, 2023
37fa012
r/aws_elastic_beanstalk_configuration_template: Add 'FindConfiguratio…
ewbankkit Feb 5, 2023
8b84c8d
IoT: Use 'tfawserr.ErrCodeEquals'.
ewbankkit Feb 5, 2023
ea2cbc0
opensearch/testAccCheckELBDestroy: Remove.
ewbankkit Feb 5, 2023
166507f
r/aws_redshift_security_group: Use 'tfawserr.ErrCodeEquals'.
ewbankkit Feb 5, 2023
f3b34b4
r/aws_sagemaker_model: Use 'tfawserr.ErrCodeEquals'.
ewbankkit Feb 5, 2023
b251a7d
r/aws_servicecatalog_portfolio: Add 'FindPortfolioByID'.
ewbankkit Feb 5, 2023
eeabf8f
Delete 'testAccCheckInstanceGroupDestroy'.
ewbankkit Feb 6, 2023
debe1f6
r/aws_neptune_subnet_group: Add 'FindSubnetGroupByName'.
ewbankkit Feb 6, 2023
e9ed553
r/aws_db_parameter_group: Add 'FindDBParameterGroupByName'.
ewbankkit Feb 6, 2023
b3b10c9
r/aws_waf_size_constraint_set: Add 'FindSizeConstraintSetByID'.
ewbankkit Feb 6, 2023
fc0de5e
r/aws_waf_rate_based_rule: Add 'FindRateBasedRuleByID'.
ewbankkit Feb 6, 2023
f1c97dd
r/aws_iam_account_password_policy: Add 'FindAccountPasswordPolicy'.
ewbankkit Feb 7, 2023
c60bd3a
r/aws_iam_group: Add 'FindGroupByName'.
ewbankkit Feb 8, 2023
488e7a3
r/aws_iam_user_ssh_key: Add 'FindSSHPublicKeyByThreePartKey'.
ewbankkit Feb 8, 2023
f14dab2
r/aws_app_cookie_stickiness_policy: Add 'FindLoadBalancerPolicyByTwoP…
ewbankkit Feb 8, 2023
73ca3c0
Add 'acctest.TLSPEMRemovePublicKeyEncapsulationBoundaries'.
ewbankkit Feb 8, 2023
43d66ae
Add 'acctest.TLSPEMRemoveNewlines'.
ewbankkit Feb 8, 2023
7c0bcf0
r/aws_load_balancer_backend_server_policy: Add 'FindLoadBalancerBacke…
ewbankkit Feb 8, 2023
3bbd12c
r/aws_lb_cookie_stickiness_policy: Use 'FindLoadBalancerListenerPolic…
ewbankkit Feb 8, 2023
a901ed0
r/aws_lb_ssl_negotiation_policy: Use 'FindLoadBalancerListenerPolicyB…
ewbankkit Feb 8, 2023
4716b4e
r/aws_load_balancer_listener_policy: Add 'FindLoadBalancerListenerPol…
ewbankkit Feb 8, 2023
04f28ab
r/aws_load_balancer_policy: Use 'FindLoadBalancerPolicyByTwoPartKey'.
ewbankkit Feb 9, 2023
ccd77c5
r/aws_elb: Use 'FindLoadBalancerByName'.
ewbankkit Feb 9, 2023
54a2bf7
d/aws_elb: Use 'FindLoadBalancerByName'.
ewbankkit Feb 9, 2023
4da4cb9
Merge branch 'main' into td-awserr-casts
ewbankkit Feb 9, 2023
aa9c28a
r/aws_elb: Fix sweeper.
ewbankkit Feb 9, 2023
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
7 changes: 7 additions & 0 deletions .changelog/27991.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_opsworks_permission: `stack_id` and `user_arn` are both Required and ForceNew
```

```release-note:enhancement
resource/aws_efs_mount_target: Add configurable timeouts for Create and Delete
```
15 changes: 0 additions & 15 deletions .ci/.semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -833,21 +833,6 @@ rules:
pattern: int(*$VALUE)
severity: WARNING

- id: aws-go-sdk-error-code-helper
languages: [go]
message: "Use `tfawserr` helpers for checking AWS Go SDK errors (e.g. `tfawserr.ErrMessageContains(err, CODE, MESSAGE)`)"
paths:
include:
- internal/
patterns:
- pattern-either:
- pattern: if $AWSERR, $OK := $ORIGINALERR.(awserr.Error); $OK && $AWSERR.Code() == $CODE { $BODY }
- pattern: |
if $AWSERR, $OK := $ORIGINALERR.(awserr.Error); $OK {
if $AWSERR.Code() == $CODE { $BODY }
}
severity: WARNING

- id: fmt-Errorf-awserr-Error-Code
languages: [go]
message: Prefer `err` with `%w` format verb instead of `err.Code()` or `err.Message()`
Expand Down
9 changes: 9 additions & 0 deletions .ci/semgrep/aws/awserr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rules:
- id: aws-go-sdk-error-code-helper
languages: [go]
message: 'Use `tfawserr` helpers for checking AWS Go SDK v1 errors (e.g. `tfawserr.ErrMessageContains(err, CODE, MESSAGE)`)'
paths:
include:
- internal/
pattern: $AWSERR, $OK := $ORIGINALERR.(awserr.Error)
severity: WARNING
27 changes: 26 additions & 1 deletion internal/acctest/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,28 @@ const (
PEMBlockTypePublicKey = `PUBLIC KEY`
)

var tlsX509CertificateSerialNumberLimit = new(big.Int).Lsh(big.NewInt(1), 128) //nolint:gomnd
var (
tlsX509CertificateSerialNumberLimit = new(big.Int).Lsh(big.NewInt(1), 128) //nolint:gomnd
)

// TLSPEMRemovePublicKeyEncapsulationBoundaries removes public key
// pre and post encapsulation boundaries from a PEM string.
func TLSPEMRemovePublicKeyEncapsulationBoundaries(pem string) string {
return removePEMEncapsulationBoundaries(pem, PEMBlockTypePublicKey)
}

func removePEMEncapsulationBoundaries(pem, label string) string {
return strings.ReplaceAll(strings.ReplaceAll(pem, pemPreEncapsulationBoundary(label), ""), pemPostEncapsulationBoundary(label), "")
}

// See https://www.rfc-editor.org/rfc/rfc7468#section-2.
func pemPreEncapsulationBoundary(label string) string {
return `-----BEGIN ` + label + `-----`
}

func pemPostEncapsulationBoundary(label string) string {
return `-----END ` + label + `-----`
}

// TLSECDSAPublicKeyPEM generates an ECDSA private key PEM string using the specified elliptic curve.
// Wrap with TLSPEMEscapeNewlines() to allow simple fmt.Sprintf()
Expand Down Expand Up @@ -392,6 +413,10 @@ func TLSPEMEscapeNewlines(pem string) string {
return strings.ReplaceAll(pem, "\n", "\\n")
}

func TLSPEMRemoveNewlines(pem string) string {
return strings.ReplaceAll(pem, "\n", "")
}

func ellipticCurveForName(name string) elliptic.Curve {
switch name {
case "P-224":
Expand Down
44 changes: 44 additions & 0 deletions internal/acctest/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,47 @@ func TestTLSECDSAPublicKeyPEM(t *testing.T) {
t.Errorf("key does not contain PUBLIC KEY: %s", publicKey)
}
}

func TestTLSPEMEscapeNewlines(t *testing.T) {
t.Parallel()

input := `
ABCD
12345
`
want := "\\nABCD\\n12345\\n"

if got := acctest.TLSPEMEscapeNewlines(input); got != want {
t.Errorf("got: %s\nwant: %s", got, want)
}
}

func TestTLSPEMRemovePublicKeyEncapsulationBoundaries(t *testing.T) {
t.Parallel()

input := `-----BEGIN PUBLIC KEY-----
ABCD
12345
-----END PUBLIC KEY-----
`
want := "\nABCD\n12345\n\n"

if got := acctest.TLSPEMRemovePublicKeyEncapsulationBoundaries(input); got != want {
t.Errorf("got: %s\nwant: %s", got, want)
}
}

func TestTLSPEMRemoveNewlines(t *testing.T) {
t.Parallel()

input := `
ABCD
12345

`
want := "ABCD12345"

if got := acctest.TLSPEMRemoveNewlines(input); got != want {
t.Errorf("got: %s\nwant: %s", got, want)
}
}
83 changes: 56 additions & 27 deletions internal/service/apigateway/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import (
"github.com/aws/aws-sdk-go/service/apigateway"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"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/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/verify"
)

Expand Down Expand Up @@ -83,17 +85,20 @@ func resourceAPIKeyCreate(ctx context.Context, d *schema.ResourceData, meta inte
conn := meta.(*conns.AWSClient).APIGatewayConn()
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
tags := defaultTagsConfig.MergeTags(tftags.New(d.Get("tags").(map[string]interface{})))
log.Printf("[DEBUG] Creating API Gateway API Key")

apiKey, err := conn.CreateApiKeyWithContext(ctx, &apigateway.CreateApiKeyInput{
Name: aws.String(d.Get("name").(string)),
name := d.Get("name").(string)
input := &apigateway.CreateApiKeyInput{
Description: aws.String(d.Get("description").(string)),
Enabled: aws.Bool(d.Get("enabled").(bool)),
Value: aws.String(d.Get("value").(string)),
Name: aws.String(name),
Tags: Tags(tags.IgnoreAWS()),
})
Value: aws.String(d.Get("value").(string)),
}

apiKey, err := conn.CreateApiKeyWithContext(ctx, input)

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

d.SetId(aws.StringValue(apiKey.Id))
Expand All @@ -107,19 +112,15 @@ func resourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta interf
defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

log.Printf("[DEBUG] Reading API Gateway API Key: %s", d.Id())
apiKey, err := FindAPIKeyByID(ctx, conn, d.Id())

apiKey, err := conn.GetApiKeyWithContext(ctx, &apigateway.GetApiKeyInput{
ApiKey: aws.String(d.Id()),
IncludeValue: aws.Bool(true),
})
if err != nil {
if !d.IsNewResource() && tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) {
log.Printf("[WARN] API Gateway API Key (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
}
if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] API Gateway API Key (%s) not found, removing from state", d.Id())
d.SetId("")
return diags
}

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

Expand Down Expand Up @@ -187,31 +188,33 @@ func resourceAPIKeyUpdate(ctx context.Context, d *schema.ResourceData, meta inte
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).APIGatewayConn()

log.Printf("[DEBUG] Updating API Gateway API Key: %s", d.Id())
if d.HasChangesExcept("tags", "tags_all") {
_, err := conn.UpdateApiKeyWithContext(ctx, &apigateway.UpdateApiKeyInput{
ApiKey: aws.String(d.Id()),
PatchOperations: resourceAPIKeyUpdateOperations(d),
})

if err != nil {
return sdkdiag.AppendErrorf(diags, "updating API Gateway API Key (%s): %s", d.Id(), err)
}
}

if d.HasChange("tags_all") {
o, n := d.GetChange("tags_all")

if err := UpdateTags(ctx, conn, d.Get("arn").(string), o, n); err != nil {
return sdkdiag.AppendErrorf(diags, "updating tags: %s", err)
}
}

_, err := conn.UpdateApiKeyWithContext(ctx, &apigateway.UpdateApiKeyInput{
ApiKey: aws.String(d.Id()),
PatchOperations: resourceAPIKeyUpdateOperations(d),
})
if err != nil {
return sdkdiag.AppendErrorf(diags, "updating API Gateway API Key (%s): %s", d.Id(), err)
}

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

func resourceAPIKeyDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).APIGatewayConn()
log.Printf("[DEBUG] Deleting API Gateway API Key: %s", d.Id())

log.Printf("[DEBUG] Deleting API Gateway API Key: %s", d.Id())
_, err := conn.DeleteApiKeyWithContext(ctx, &apigateway.DeleteApiKeyInput{
ApiKey: aws.String(d.Id()),
})
Expand All @@ -226,3 +229,29 @@ 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) {
input := &apigateway.GetApiKeyInput{
ApiKey: aws.String(id),
IncludeValue: aws.Bool(true),
}

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

if tfawserr.ErrCodeEquals(err, apigateway.ErrCodeNotFoundException) {
return nil, &resource.NotFoundError{
LastError: err,
LastRequest: input,
}
}

if err != nil {
return nil, err
}

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

return output, nil
}
10 changes: 4 additions & 6 deletions internal/service/apigateway/api_key_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/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"
Expand Down Expand Up @@ -56,13 +55,11 @@ func dataSourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta inte
conn := meta.(*conns.AWSClient).APIGatewayConn()
ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig

apiKey, err := conn.GetApiKeyWithContext(ctx, &apigateway.GetApiKeyInput{
ApiKey: aws.String(d.Get("id").(string)),
IncludeValue: aws.Bool(true),
})
id := d.Get("id").(string)
apiKey, err := FindAPIKeyByID(ctx, conn, id)

if err != nil {
return sdkdiag.AppendErrorf(diags, "reading API Gateway API Key (%s): %s", d.Get("id").(string), err)
return sdkdiag.AppendErrorf(diags, "reading API Gateway API Key (%s): %s", id, err)
}

d.SetId(aws.StringValue(apiKey.Id))
Expand All @@ -76,5 +73,6 @@ func dataSourceAPIKeyRead(ctx context.Context, d *schema.ResourceData, meta inte
if err := d.Set("tags", KeyValueTags(apiKey.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return sdkdiag.AppendErrorf(diags, "setting tags: %s", err)
}

return diags
}
30 changes: 15 additions & 15 deletions internal/service/apigateway/api_key_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
)

func TestAccAPIGatewayAPIKeyDataSource_basic(t *testing.T) {
rName := sdkacctest.RandString(8)
resourceName1 := "aws_api_gateway_api_key.example_key"
dataSourceName1 := "data.aws_api_gateway_api_key.test_key"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_api_gateway_api_key.test"
dataSourceName := "data.aws_api_gateway_api_key.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
Expand All @@ -23,14 +23,14 @@ func TestAccAPIGatewayAPIKeyDataSource_basic(t *testing.T) {
{
Config: testAccAPIKeyDataSourceConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair(resourceName1, "id", dataSourceName1, "id"),
resource.TestCheckResourceAttrPair(resourceName1, "name", dataSourceName1, "name"),
resource.TestCheckResourceAttrPair(resourceName1, "value", dataSourceName1, "value"),
resource.TestCheckResourceAttrPair(resourceName1, "enabled", dataSourceName1, "enabled"),
resource.TestCheckResourceAttrPair(resourceName1, "description", dataSourceName1, "description"),
resource.TestCheckResourceAttrSet(dataSourceName1, "last_updated_date"),
resource.TestCheckResourceAttrSet(dataSourceName1, "created_date"),
resource.TestCheckResourceAttr(dataSourceName1, "tags.%", "0"),
resource.TestCheckResourceAttrPair(resourceName, "id", dataSourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "name", dataSourceName, "name"),
resource.TestCheckResourceAttrPair(resourceName, "value", dataSourceName, "value"),
resource.TestCheckResourceAttrPair(resourceName, "enabled", dataSourceName, "enabled"),
resource.TestCheckResourceAttrPair(resourceName, "description", dataSourceName, "description"),
resource.TestCheckResourceAttrSet(dataSourceName, "last_updated_date"),
resource.TestCheckResourceAttrSet(dataSourceName, "created_date"),
resource.TestCheckResourceAttr(dataSourceName, "tags.%", "0"),
),
},
},
Expand All @@ -39,12 +39,12 @@ func TestAccAPIGatewayAPIKeyDataSource_basic(t *testing.T) {

func testAccAPIKeyDataSourceConfig_basic(r string) string {
return fmt.Sprintf(`
resource "aws_api_gateway_api_key" "example_key" {
name = "%s"
resource "aws_api_gateway_api_key" "test" {
name = %[1]q
}

data "aws_api_gateway_api_key" "test_key" {
id = aws_api_gateway_api_key.example_key.id
data "aws_api_gateway_api_key" "test" {
id = aws_api_gateway_api_key.test.id
}
`, r)
}
Loading