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

r/aws_apigatewayv2_authorizer: Skip ttl when there are no identity sources #32629

Merged
merged 2 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/32629.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_apigatewayv2_authorizer: Skip setting authorizer TTL when there are no identity sources
```
3 changes: 2 additions & 1 deletion internal/service/apigatewayv2/authorizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@ func resourceAuthorizerCreate(ctx context.Context, d *schema.ResourceData, meta
}
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 {
} else if protocolType == apigatewayv2.ProtocolTypeHttp && authorizerType == apigatewayv2.AuthorizerTypeRequest && len(req.IdentitySource) > 0 {
// Default in the AWS Console is 300 seconds.
// Explicitly set on creation so that we can correctly detect changes to the 0 value.
// This value should only be set when IdentitySources have been defined
req.AuthorizerResultTtlInSeconds = aws.Int64(300)
}
if v, ok := d.GetOk("authorizer_uri"); ok {
Expand Down
26 changes: 26 additions & 0 deletions internal/service/apigatewayv2/authorizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ func TestAccAPIGatewayV2Authorizer_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "name", rName),
),
},
{
Config: testAccAuthorizerConfig_httpNoAuthenticationSources(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckAuthorizerExists(ctx, resourceName, &apiId, &v),
resource.TestCheckResourceAttr(resourceName, "authorizer_type", "REQUEST"),
resource.TestCheckResourceAttr(resourceName, "identity_sources.#", "0"),
resource.TestCheckResourceAttr(resourceName, "authorizer_result_ttl_in_seconds", "0"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
),
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccAuthorizerImportStateIdFunc(resourceName),
Expand Down Expand Up @@ -573,6 +583,22 @@ resource "aws_apigatewayv2_authorizer" "test" {
`, rName))
}

func testAccAuthorizerConfig_httpNoAuthenticationSources(rName string) string {
return acctest.ConfigCompose(
testAccAuthorizerConfig_apiHTTP(rName),
testAccAuthorizerConfig_baseLambda(rName),
fmt.Sprintf(`
resource "aws_apigatewayv2_authorizer" "test" {
api_id = aws_apigatewayv2_api.test.id
authorizer_payload_format_version = "2.0"
authorizer_type = "REQUEST"
authorizer_uri = aws_lambda_function.test.invoke_arn
enable_simple_responses = true
name = %[1]q
}
`, rName))
}

func testAccAuthorizerConfig_httpAPILambdaRequestUpdated(rName string, authorizerResultTtl int) string {
return acctest.ConfigCompose(
testAccAuthorizerConfig_apiHTTP(rName),
Expand Down