我有一个 aws http apigatewayv2 模块。
resource "aws_apigatewayv2_route" "this" {
for_each = var.routes_configuration
api_id = aws_apigatewayv2_api.this.id
route_key = "${each.value.http_method} /${each.value.route}"
target = "integrations/${aws_apigatewayv2_integration.this[each.key].id}"
authorization_type = each.value.auth_type
authorizer_id = aws_apigatewayv2_authorizer.this.id
authorization_scopes = each.value.auth_type == "JWT" ? ["${local.api-resource-server}/${each.value.route}"] : null
}
对于某些路由,我需要authorization_type为NONE,以便该路由是公共的。 考虑到我已经使用“JWT”授权类型创建了路线,当我切换到“NONE”授权类型时,一切进展顺利,但是当运行另一个 terraform apply 时,出现以下异常:
updating API Gateway v2 route (*****): BadRequestException: Unable to update route. Authorizer type is invalid or null.
这里的问题是我提供了一个授权类型为“NONE”的
authorizer_id
。
在我的例子中,authorization_type 是“JWT”或“NONE”,因此authorization_type 不是“JWT”,authorizer_id 应该为 null。
来自
authorizer_id = aws_apigatewayv2_authorizer.this.id
到
authorizer_id = each.value.auth_type == "JWT" ? aws_apigatewayv2_authorizer.this.id : null
resource "aws_apigatewayv2_route" "this" {
for_each = var.routes_configuration
api_id = aws_apigatewayv2_api.this.id
route_key = "${each.value.http_method} /${each.value.route}"
target = "integrations/${aws_apigatewayv2_integration.this[each.key].id}"
authorization_type = each.value.auth_type
authorizer_id = each.value.auth_type == "JWT" ? aws_apigatewayv2_authorizer.this.id : null #CHANGED
authorization_scopes = each.value.auth_type == "JWT" ? ["${local.api-resource-server}/${each.value.route}"] : null
}