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

Terraform forces map(any) type for integrations to have the exact same structure #100

Closed ferhatys closed 3 months ago

ferhatys commented 3 months ago

Description

We're passing a map(any) of integrations into the module for setting the API GW integrations. However, Terraform is trying to infer the type of the items inside the map and is enforcing the same structure. So we can't have one integration where we pass a lambda_arn and another one where we pass the integration_uri without the lambda_arn for example.

Versions

Reproduction Code [Required]

Steps to reproduce the behavior:

integrations = tomap({
    "POST /xxx" = {
      lambda_arn             = module.lambda[0].lambda_function_arn
      payload_format_version = "2.0"
      timeout_milliseconds   = 12000
      integration_type       = "AWS_PROXY"
    },
    "$default" = {
      connection_type    = "VPC_LINK"
      vpc_link           = "main"
      integration_type   = "HTTP_PROXY"
      integration_method = "ANY"
      authorizer_key     = "xxx"
      authorization_type = "CUSTOM"
      integration_uri = data.aws_lb_listener.backend[0].arn
    }
  })

Expected behavior

terraform plan is executed successfully.

Actual behavior

terraform plan fails with the following message.

β”‚ The given value is not suitable for module.api_gateway.var.integrations
126β”‚ declared at .terraform/modules/api_gateway/variables.tf:197,1-24: attribute
127β”‚ types must all match for conversion to map.
128β•΅
129Error: Terraform exited with code 1.
130Error: Process completed with exit code 1.

Terminal Output Screenshot(s)

Additional context

antonbabenko commented 3 months ago

Just remove tomap(), see code in examples/complete directory.

github-actions[bot] commented 2 months 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.