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

5.0 Update fails to find nested subdomain route53 zones #105

Closed plukevdh closed 3 months ago

plukevdh commented 3 months ago

Description

When attempting to update from < 5.0 to 5.0, I get new errors relating to route53 hosted zone discovery that did not exist prior to the update. It appears that the code to lookup the hosted zone for the gateway has changed when using the domain_name parameter when using single subdomained domains, i.e.,

Zone domain: my.domain.here.io Subdomain/domain of the api gateway: testing.my.domain.here.io

Versions

provider registry.terraform.io/hashicorp/aws v5.52.0

Reproduction Code [Required]

provider "aws" {
  region = "us-east-1"
}

data "aws_region" "current" {}

data "aws_route53_zone" "verify" {
  name = "my.domain.here.io"
}

module "gateway" {
  source  = "terraform-aws-modules/apigateway-v2/aws"
  version = "5.0.0"

  name          = "test-endpoint"
  protocol_type = "HTTP"

  # Custom domain
  domain_name = "testing.my.domain.here.io"

  # Routes and integrations
  routes = {
    "GET /" = {
      integration = {
        uri                    = "arn:aws:lambda:us-east-1:${data.aws_region.current.name}:function:my-function"
        payload_format_version = "2.0"
      }
    }
  }
}

Expected behavior

I should get a successful terraform plan back from this specifying a new API gateway creation

Actual behavior

β”‚ Error: no matching Route 53 Hosted Zone found
β”‚
β”‚   with module.gateway.data.aws_route53_zone.this[0],
β”‚   on .terraform/modules/gateway/main.tf line 134, in data "aws_route53_zone" "this":
β”‚  134: data "aws_route53_zone" "this" {

Terminal Output Screenshot(s)

CleanShot 2024-06-04 at 18 24 18@2x

Additional context

If one comments out the module, clears the .terraform directories and re-inits/plans, the aws_route53_zone data module finds the zone just fine. My assumption is that the use of the domain_name var has changed without clear guidance on how to replicate previous behavior. Apologies if this is in the new documentation or migration guide, I couldn't find it.

bryantbiggs commented 3 months ago

I think you would have:

  ...
  domain_name = "my.domain.here.io"
  subdomains  = ["testing"]
  ...

If you plan to route multiple sub-domains to this in the future, you can use:

  ...
  domain_name = "*.my.domain.here.io"
  subdomains  = ["testing"]
  ...

Ref https://github.com/terraform-aws-modules/terraform-aws-apigateway-v2?tab=readme-ov-file#multiple-subdomains

plukevdh commented 3 months ago

That does appear to at least clear the errors in the sample code. Is that something that can be added to the migration document? It seems a change from previous behavior that may not be clear to others referencing that document rather than the primary readme (like myself).

I also need to verify that this change does not cause any additional changes to the existing AWS resources. Once verified, I'll either follow up or close this ticket. Thanks for the quick response @bryantbiggs

plukevdh commented 3 months ago

Looks like this does resolve my errors, so I'll close. It does appear the final output differs pretty significantly due to the resource reorganization under the hood, which I suppose is expected for a major version number change. Appreciate the quick feedback!

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.