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
148 stars 200 forks source link

Integrations: all map elements must have the same type. #89

Closed IbraheemAlSaady closed 1 year ago

IbraheemAlSaady commented 1 year ago

Description

Specifying the value of integrations variable while having different attributes for each integration results in the error The given value is not suitable for module.api_gateway.var.integrations declared at .terraform/modules/api_gateway/variables.tf:197,1-24: all map elements must have the same type.

Versions

Reproduction Code [Required]

Here is what I'm trying to run

module "api_gateway" {
  source = "terraform-aws-modules/apigateway-v2/aws"

  name          = "some-api-name"
  protocol_type = "HTTP"

  # Routes and integrations
  integrations = {
    "GET /test-lambda" = {
      lambda_arn             = "arn:aws:lambda:eu-west-1:052235179155:function:my-function"
      payload_format_version = "2.0"
      timeout_milliseconds   = 12000
      authorization_type     = "CUSTOM"
      authorizer_key         = "some-authorizer"
    }

    "GET /test-http-proxy" = {
      integration_type = "HTTP_PROXY"
      integration_uri  = "some url"
      authorizer_key   = "some-authorizer"

      response_parameters = [{
        status_code = 200
        mappings = {
          ....
        }
      }]
    }
  }

  authorizers = {
    ....
  }
}

What I noticed is adding the response_parameters is what's breaking it

antonbabenko commented 1 year ago

You should wrap value with jsonencode() to make all arguments look like strings. See this example:

https://github.com/terraform-aws-modules/terraform-aws-apigateway-v2/blob/dd6826c62909fe6aaf6761cb755b5124d876e80a/examples/complete-http/main.tf#L123-L137

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.