Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Issues when fetching route53 zone #120

Closed

Conversation

atorrescogollo
Copy link

Description

Records registration seems to be partially broken

Motivation and Context

Given this code:

module "api_gateway" {
  source = "../.."

  name          = "demo"
  description   = "API Gateway"
  protocol_type = "HTTP"

  # Custom domain
  domain_name = "demo.example.com" # route53 zone "example.com" already exists

  routes = {
    "POST /" = {
      integration = {
        uri                    = "arn:aws:lambda:eu-west-1:012345678901:function:my-function"
        payload_format_version = "2.0"
        timeout_milliseconds   = 12000
      }
    }
  }
}

It fails to get the zone_id since it tries demo.example.com instead of just example.com.

This PR was made to fix that. Also, it includes a way to avoid doing that data lookup and using a variable instead.

Now there are three ways to register the domain records:

  1. Fetch the zone_id and register demo.example.com records
  domain_name = "demo.example.com"
  1. Fetch the zone_id and register demo1.example.com and demo2.example.com records
  domain_name = "*.example.com"
  subdomains  = ["demo1", "demo2"]
  1. Register demo.example.com records in the given zone id
  domain_name    = "demo.example.com"
  domain_zone_id = "Z1234567890"

Breaking Changes

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@tonnenpinguin
Copy link
Contributor

FYI: I implemented a fix for the same issue here: #119
🙂

@atorrescogollo
Copy link
Author

Hey @tonnenpinguin sorry , my fault, I was debugging the issue at first and I didn't realize your PR (I thought it was for just allowing var.hosted_zone_name).

However, your PR doesn't fix the issue I described here. It only allows you to set the var.hosted_zone_name ad-hoc. I can't successfully run a plan against this:

module "api_gateway" {
  source = "[email protected]:tonnenpinguin/terraform-aws-apigateway-v2.git?ref=fix/hosted_zone_name"

  name          = "demo"
  description   = "API Gateway"
  protocol_type = "HTTP"

  # Custom domain
  domain_name = "demo.example.com" # Having an example.com zone already created
}
│ Error: no matching Route 53 Hosted Zone found
│ 
│   with module.api_gateway.data.aws_route53_zone.this[0],
│   on .terraform/modules/api_gateway/main.tf line 134, in data "aws_route53_zone" "this":
│  134: data "aws_route53_zone" "this" {
│ 

I have to explicitly say this to make it work (which should behave in the same way AFAIK):

module "api_gateway" {
  ...

  hosted_zone_name = "example.com"
}

If you implement that fix, tell me and I'll close this one. Since you had reviews already, I think it makes more sense to keep yours instead.

@atorrescogollo
Copy link
Author

atorrescogollo commented Aug 21, 2024

On the other hand, I would prefer to forward the zone_id instead of the zone_name.

I have a personal reference about trying to send IDs and ARNs when possible and against doing data lookups inside modules. The plan is usually faster at scale, and you might see more "known after apply" references when using data lookups.

In my change, I was suggesting forwarding the zone_id so that you don't have to do the data lookup since you don't need it. But it's just an opinion.

@antonbabenko
Copy link
Member

This issue has been resolved in version 5.2.0 🎉

Copy link

I'm going to lock this pull request 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 related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants