BadRequestException:无法更新路线。当authorization_type NONE时,授权者类型无效或为空

问题描述 投票:0回答:1

我有一个 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.

terraform aws-api-gateway
1个回答
0
投票

这里的问题是我提供了一个授权类型为“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
}

© www.soinside.com 2019 - 2024. All rights reserved.