Skip to content

Commit

Permalink
Merge pull request #14 from clouddrove/fix/locals
Browse files Browse the repository at this point in the history
Fix: 🐛 Updated local condition to prevent error if enabled is false.
  • Loading branch information
Om Sharma authored Oct 2, 2023
2 parents 7195861 + 5ecfc7f commit 7e89e9b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion _example/public-hostedzone/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module "route53" {
type = "A"
alias = {
name = "d130easdflja734js.cloudfront.net" # name/DNS of attached cloudfront.
zone_id = "Z2XXXXHXTXXXX4" # A valid zone ID of cloudfront you are trying to create alias of.
zone_id = "Z2XXXXHXTXXXX4" # A valid zone ID of cloudfront you are trying to create alias of.
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions _example/vpc-association/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module "route53" {
environment = "test"
label_order = ["environment", "name"]
private_enabled = true
record_enabled = false
record_enabled = false

domain_name = "clouddrove.com"
vpc_id = "vpc-xxxxxxxxxxxxxx"

secondary_vpc_id = "vpc-xxxxxxxxxxxxxx"
secondary_vpc_id = "vpc-xxxxxxxxxxxxxx"
}
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ locals {
## Convert `records` from list to map with unique keys
##-----------------------------------------------------------------------------
recordsets = { for rs in local.records : try(rs.key, join(" ", compact(["${rs.name} ${rs.type}", try(rs.set_identifier, "")]))) => rs }
zone_id = var.zone_id != "" ? var.zone_id : (var.private_enabled ? aws_route53_zone.private.*.zone_id[0] : aws_route53_zone.public.*.zone_id[0])
zone_id = var.enabled ? (var.zone_id != "" ? var.zone_id : (var.private_enabled ? aws_route53_zone.private.*.zone_id[0] : aws_route53_zone.public.*.zone_id[0])) : ""
}

##-----------------------------------------------------------------------------
Expand Down Expand Up @@ -63,7 +63,7 @@ resource "aws_route53_zone" "public" {
## Terraform module to create Route53 record sets resource on AWS.
##-----------------------------------------------------------------------------
resource "aws_route53_record" "this" {
for_each = { for k, v in local.recordsets : k => v if var.enabled && var.record_enabled && ( var.zone_id != null || var.public_enabled != null || var.private_enabled != null || var.domain_name != null) }
for_each = { for k, v in local.recordsets : k => v if var.enabled && var.record_enabled && (var.zone_id != null || var.public_enabled != null || var.private_enabled != null || var.domain_name != null) }

zone_id = local.zone_id

Expand Down Expand Up @@ -119,8 +119,8 @@ resource "aws_route53_record" "this" {
subdivision = lookup(each.value.geolocation_routing_policy, "subdivision", null)
}
}
depends_on = [
aws_route53_zone.public,
depends_on = [
aws_route53_zone.public,
aws_route53_zone.private
]
}
Expand Down

0 comments on commit 7e89e9b

Please sign in to comment.