Skip to content

feat: Allow skipping data source lookup #120

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

Conversation

mike-carey
Copy link

Description

Adds a skip_zone_lookup variable to bypass looking up the aws_route53_zone data source.

Motivation and Context

We would like to create DNS zones and records within the same state file. Even when using terragrunt with two units/state files, we need the hosted zone (or at least one that we can use as a mock output) to exist or we get the following error when attempting a run-all:

  ╷
  │ Error: no matching Route 53 Hosted Zone found
  │
  │   with data.aws_route53_zone.this[0],
  │   on main.tf line 10, in data "aws_route53_zone" "this":
  │   10: data "aws_route53_zone" "this" {
  │
  ╵

  exit status 1

Breaking Changes

There are none.

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

I have used this module within our environment to create a DNS zone and records with the same plan and apply.

module "zone" {
  source = "terraform-aws-modules/route53/aws//modules/zones"
  version = "~> 5.0"

  zones = {
    "sandbox.example.com" = {
      comment = "Sandbox domain"
      vpc     = [{ vpc_id = var.vpc_id }]
    }
  }
}

module "records" {
  source = "git@github.com:mike-carey/terraform-aws-route53//modules/records?ref=feat/skip-zone-lookup"

  skip_zone_lookup = true
  zone_id   = module.zone.route53_zone_zone_id["sandbox.example.com"]
  zone_name = module.zone.route53_zone_name["sandbox.example.com"]

  records = [
    # ... records here
  ]  
}

Please feel free to make any edits, change the variable name, remove or reword any comments, etc. The ternary operators look strange, but the only way we can "short circuit" in terraform is via lazy evaluation.

Copy link

This PR has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this PR will be closed in 10 days

@github-actions github-actions bot added the stale label May 30, 2025
@mike-carey
Copy link
Author

Any chance I can get some 👀 on this? Even if it is to reject it so I can replace in my internal module with the resources themselves.

@github-actions github-actions bot removed the stale label Jun 3, 2025
@bryantbiggs
Copy link
Member

I don't follow the logic nor issue so going to close this one out

Lets start with an issue and a reproduction to understand what you are trying to do and work from there

@bryantbiggs bryantbiggs closed this Jun 4, 2025
@squ1d123
Copy link

squ1d123 commented Jun 5, 2025

This is actually what I have been looking for, but for a different use case.

I get rate limited from the amount of calls I make to route53, (only 5 API operations per sec). And I have many zones.

With the current behavior of the module, it will do a zone lookup on each invocation of the module.

With this change, it allows me to look up the zones data once, and then pass that info down into the module for it to use, no longer requiring it to always lookup the zone id.

This helps me with my rate limiting issues, and results in much faster plans/deployments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants