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
151 stars 203 forks source link

Call to function "coalesce" failed #125

Open dang-ng opened 3 weeks ago

dang-ng commented 3 weeks ago

Description

i got error when trying creating a simple api_gateway below:

Reproduction Code [Required]

module "api_gateway" {
  source        = "terraform-aws-modules/apigateway-v2/aws"
  name          = "UserAPI"
  protocol_type = "HTTP"
  routes = {
    "GET /" = {
      integration = {
        uri = "my lambda arn"
      }
    }
  }
}

Steps to reproduce the behavior:

put the code in main.tf, simply run:

terraform init terraform plan

Expected behavior

There shouldn't any error

Actual behavior

Below error shown in terminal:

│ Error: Error in function call
│ 
│   on .terraform/modules/api_gateway/main.tf line 137, in data "aws_route53_zone" "this":
│  137:   name = coalesce(var.hosted_zone_name, local.stripped_domain_name)
│     ├────────────────
│     │ while calling coalesce(vals...)
│     │ local.stripped_domain_name is ""
│     │ var.hosted_zone_name is null
│ 
│ Call to function "coalesce" failed: no non-null, non-empty-string arguments.

Terminal Output Screenshot(s)

image

Additional context

I think it relates to this issue here: https://github.com/terraform-aws-modules/terraform-aws-apigateway-v2/pull/119

codinronan commented 3 weeks ago

This is a strange error. I encountered this as well.

The module requires the addition of a domain name? What if I don't want to use one?

codinronan commented 3 weeks ago

I see. If you don't want that, you need to add this to the config:

  create_domain_name    = false
  create_domain_records = false

This skips the relevant config and avoids the error.

Personally I feel those should default to false (or flip if domain is set) but, this is straightforward enough.

dang-ng commented 2 weeks ago

yeah, these should default to false since these fields are optional as stated in the README file. Thanks anyway @codinronan