Skip to content

Commit

Permalink
r/aws_apigatewayv2_authorizer: Distinguish between missing and zero v…
Browse files Browse the repository at this point in the history
…alues for cache TTL.

Acceptance test output:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSAPIGatewayV2Authorizer_' ACCTEST_PARALLELISM=2
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 2 -run=TestAccAWSAPIGatewayV2Authorizer_ -timeout 120m
=== RUN   TestAccAWSAPIGatewayV2Authorizer_basic
=== PAUSE TestAccAWSAPIGatewayV2Authorizer_basic
=== RUN   TestAccAWSAPIGatewayV2Authorizer_disappears
=== PAUSE TestAccAWSAPIGatewayV2Authorizer_disappears
=== RUN   TestAccAWSAPIGatewayV2Authorizer_Credentials
=== PAUSE TestAccAWSAPIGatewayV2Authorizer_Credentials
=== RUN   TestAccAWSAPIGatewayV2Authorizer_JWT
=== PAUSE TestAccAWSAPIGatewayV2Authorizer_JWT
=== RUN   TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialMissingCacheTTL
=== PAUSE TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialMissingCacheTTL
=== RUN   TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialZeroCacheTTL
=== PAUSE TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialZeroCacheTTL
=== CONT  TestAccAWSAPIGatewayV2Authorizer_basic
=== CONT  TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialMissingCacheTTL
--- PASS: TestAccAWSAPIGatewayV2Authorizer_basic (39.77s)
=== CONT  TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialZeroCacheTTL
--- PASS: TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialMissingCacheTTL (88.17s)
=== CONT  TestAccAWSAPIGatewayV2Authorizer_Credentials
--- PASS: TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialZeroCacheTTL (73.00s)
=== CONT  TestAccAWSAPIGatewayV2Authorizer_JWT
--- PASS: TestAccAWSAPIGatewayV2Authorizer_Credentials (86.61s)
=== CONT  TestAccAWSAPIGatewayV2Authorizer_disappears
--- PASS: TestAccAWSAPIGatewayV2Authorizer_JWT (90.80s)
=== CONT  TestAccAWSAPIGatewayV2Authorizer_disappears
    resource_aws_apigatewayv2_authorizer_test.go:58: [INFO] Got non-empty plan, as expected
--- PASS: TestAccAWSAPIGatewayV2Authorizer_disappears (37.71s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	212.532s
  • Loading branch information
ewbankkit committed Sep 22, 2020
1 parent b066e85 commit fc1bc5b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
2 changes: 1 addition & 1 deletion aws/resource_aws_apigatewayv2_authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func resourceAwsApiGatewayV2AuthorizerCreate(d *schema.ResourceData, meta interf
if v, ok := d.GetOk("authorizer_payload_format_version"); ok {
req.AuthorizerPayloadFormatVersion = aws.String(v.(string))
}
if v, ok := d.GetOk("authorizer_result_ttl_in_seconds"); ok {
if v, ok := d.GetOkExists("authorizer_result_ttl_in_seconds"); ok {
req.AuthorizerResultTtlInSeconds = aws.Int64(int64(v.(int)))
} else if protocolType == apigatewayv2.ProtocolTypeHttp && authorizerType == apigatewayv2.AuthorizerTypeRequest {
// Default in the AWS Console is 300 seconds.
Expand Down
58 changes: 57 additions & 1 deletion aws/resource_aws_apigatewayv2_authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func TestAccAWSAPIGatewayV2Authorizer_JWT(t *testing.T) {
})
}

func TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer(t *testing.T) {
func TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialMissingCacheTTL(t *testing.T) {
var apiId string
var v apigatewayv2.GetAuthorizerOutput
resourceName := "aws_apigatewayv2_authorizer.test"
Expand Down Expand Up @@ -273,6 +273,62 @@ func TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer(t *testing.
})
}

func TestAccAWSAPIGatewayV2Authorizer_HttpApiLambdaRequestAuthorizer_InitialZeroCacheTTL(t *testing.T) {
var apiId string
var v apigatewayv2.GetAuthorizerOutput
resourceName := "aws_apigatewayv2_authorizer.test"
lambdaResourceName := "aws_lambda_function.test"
rName := acctest.RandomWithPrefix("tf-acc-test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSAPIGatewayV2AuthorizerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAWSAPIGatewayV2AuthorizerConfig_httpApiLambdaRequestAuthorizerUpdated(rName, 0),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayV2AuthorizerExists(resourceName, &apiId, &v),
resource.TestCheckResourceAttr(resourceName, "authorizer_credentials_arn", ""),
resource.TestCheckResourceAttr(resourceName, "authorizer_payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "authorizer_type", "REQUEST"),
resource.TestCheckResourceAttrPair(resourceName, "authorizer_uri", lambdaResourceName, "invoke_arn"),
resource.TestCheckResourceAttr(resourceName, "enable_simple_responses", "false"),
resource.TestCheckResourceAttr(resourceName, "identity_sources.#", "2"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "identity_sources.*", "$request.querystring.User"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "identity_sources.*", "$context.routeKey"),
resource.TestCheckResourceAttr(resourceName, "jwt_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
),
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccAWSAPIGatewayV2AuthorizerImportStateIdFunc(resourceName),
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccAWSAPIGatewayV2AuthorizerConfig_httpApiLambdaRequestAuthorizerUpdated(rName, 600),
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSAPIGatewayV2AuthorizerExists(resourceName, &apiId, &v),
resource.TestCheckResourceAttr(resourceName, "authorizer_credentials_arn", ""),
resource.TestCheckResourceAttr(resourceName, "authorizer_payload_format_version", "1.0"),
resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", "600"),
resource.TestCheckResourceAttr(resourceName, "authorizer_type", "REQUEST"),
resource.TestCheckResourceAttrPair(resourceName, "authorizer_uri", lambdaResourceName, "invoke_arn"),
resource.TestCheckResourceAttr(resourceName, "enable_simple_responses", "false"),
resource.TestCheckResourceAttr(resourceName, "identity_sources.#", "2"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "identity_sources.*", "$request.querystring.User"),
tfawsresource.TestCheckTypeSetElemAttr(resourceName, "identity_sources.*", "$context.routeKey"),
resource.TestCheckResourceAttr(resourceName, "jwt_configuration.#", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
),
},
},
})
}

func testAccCheckAWSAPIGatewayV2AuthorizerDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).apigatewayv2conn

Expand Down

0 comments on commit fc1bc5b

Please sign in to comment.