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

Fix update operation for authorizer id on apigatewayv2 route #35821

Merged
merged 4 commits into from
Feb 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35821.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_apigatewayv2_route: Fix `BadRequestException: Unable to update route. Authorizer type is invalid or null` errors when updating `authorizer_id`
```
1 change: 1 addition & 0 deletions internal/service/apigatewayv2/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ func resourceRouteUpdate(ctx context.Context, d *schema.ResourceData, meta inter
}
if d.HasChange("authorizer_id") {
req.AuthorizerId = aws.String(d.Get("authorizer_id").(string))
req.AuthorizationType = aws.String(d.Get("authorization_type").(string))
}
if d.HasChange("model_selection_expression") {
req.ModelSelectionExpression = aws.String(d.Get("model_selection_expression").(string))
Expand Down
19 changes: 15 additions & 4 deletions internal/service/apigatewayv2/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func TestAccAPIGatewayV2Route_jwtAuthorization(t *testing.T) {
var apiId string
var v apigatewayv2.GetRouteOutput
resourceName := "aws_apigatewayv2_route.test"
authorizerResourceName := "aws_apigatewayv2_authorizer.test"
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -163,7 +162,7 @@ func TestAccAPIGatewayV2Route_jwtAuthorization(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_required", "false"),
resource.TestCheckResourceAttr(resourceName, "authorization_scopes.#", "2"),
resource.TestCheckResourceAttr(resourceName, "authorization_type", apigatewayv2.AuthorizationTypeJwt),
resource.TestCheckResourceAttrPair(resourceName, "authorizer_id", authorizerResourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "authorizer_id", "aws_apigatewayv2_authorizer.test", "id"),
resource.TestCheckResourceAttr(resourceName, "model_selection_expression", ""),
resource.TestCheckResourceAttr(resourceName, "operation_name", ""),
resource.TestCheckResourceAttr(resourceName, "request_models.%", "0"),
Expand All @@ -186,7 +185,7 @@ func TestAccAPIGatewayV2Route_jwtAuthorization(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "api_key_required", "false"),
resource.TestCheckResourceAttr(resourceName, "authorization_scopes.#", "1"),
resource.TestCheckResourceAttr(resourceName, "authorization_type", apigatewayv2.AuthorizationTypeJwt),
resource.TestCheckResourceAttrPair(resourceName, "authorizer_id", authorizerResourceName, "id"),
resource.TestCheckResourceAttrPair(resourceName, "authorizer_id", "aws_apigatewayv2_authorizer.another", "id"),
resource.TestCheckResourceAttr(resourceName, "model_selection_expression", ""),
resource.TestCheckResourceAttr(resourceName, "operation_name", ""),
resource.TestCheckResourceAttr(resourceName, "request_models.%", "0"),
Expand Down Expand Up @@ -646,12 +645,24 @@ func testAccRouteConfig_jwtAuthorizationUpdated(rName string) string {
return acctest.ConfigCompose(
testAccAuthorizerConfig_jwt(rName),
`
resource "aws_apigatewayv2_authorizer" "another" {
api_id = aws_apigatewayv2_api.test.id
authorizer_type = "JWT"
identity_sources = ["$request.header.Authorization"]
name = "another-authorizer"

jwt_configuration {
audience = ["test"]
issuer = "https://${aws_cognito_user_pool.test.endpoint}"
}
}

resource "aws_apigatewayv2_route" "test" {
api_id = aws_apigatewayv2_api.test.id
route_key = "GET /test"

authorization_type = "JWT"
authorizer_id = aws_apigatewayv2_authorizer.test.id
authorizer_id = aws_apigatewayv2_authorizer.another.id

authorization_scopes = ["user.email"]
}
Expand Down
Loading