terraform-aws-modules / terraform-aws-apigateway-v2

Terraform module to create AWS API Gateway v2 (HTTP/WebSocket) 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/apigateway-v2/aws
Apache License 2.0
144 stars 187 forks source link

Authorization type not included when using "authorizer_key" within an integration #82

Closed eschrock closed 1 year ago

eschrock commented 1 year ago

Description

The authorizer example has the following code:

    "GET /some-route-with-authorizer" = {
      integration_type = "HTTP_PROXY"
      integration_uri  = "some url"
      authorizer_key   = "azure"
    }
  ...
  authorizers = {
    "azure" = {
      authorizer_type  = "JWT"
      identity_sources = "$request.header.Authorization"
      name             = "azure-auth"
      audience         = ["d6a38afd-45d6-4874-d1aa-3c5c558aqcc2"]
      issuer           = "https://sts.windows.net/aaee026e-8f37-410e-8869-72d9154873e4/"
    }
  }

This makes it seem like you can just reference the authorizer key and don't need to specify the authorization type within the integration. However, the module code doesn't reference the authorizer_key.

resource "aws_apigatewayv2_route" "this" {
  for_each = var.create && var.create_routes_and_integrations ? var.integrations : {}

  api_id    = aws_apigatewayv2_api.this[0].id
  route_key = each.key

  api_key_required                    = try(each.value.api_key_required, null)
  authorization_scopes                = try(split(",", each.value.authorization_scopes), null)
  authorization_type                  = try(each.value.authorization_type, "NONE")
...

The result is that if you use the authorizer_key the authorization type is always NONE. Either it should pull the type from key like it does with the ID, or the example should be updated to explicitly set authorization_type in addition to authorizer_key. As a casual user, the first seems more intuitive to me but I don't know if that was an explicit decision or not. The workaround is to always set the authorization_type even when using authorizer_key

Versions

v2.2.0

Terraform v1.2.9

Reproduction Code [Required]

Steps to reproduce the behavior:

Follow the example to create an authorizer and reference it by authorizer_key.

Expected behavior

The authorization type will match that of the declared authorizer (e.g. JWT)

Actual behavior

The authorization type is always set to NONE

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has been open 30 days with no activity. Remove stale label or comment or this issue will be closed in 10 days

github-actions[bot] commented 1 year ago

This issue was automatically closed because of stale in 10 days

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.