Skip to content

Commit

Permalink
feat[lb-domain]: add possibility to create dns record for "custom dom…
Browse files Browse the repository at this point in the history
…ains" feature (#11)
  • Loading branch information
hardillb authored Aug 29, 2024
2 parents 199e05d + d2af033 commit 9e18fb5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
40 changes: 34 additions & 6 deletions lb-domain/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ data "aws_lb" "ingress" {
}
}

module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "~> 2.11"

zone_name = var.route53_zone_name
data "aws_lb" "custom_domains_ingress" {
count = var.create_custom_domain_record ? 1 : 0
tags = {
Namespace = var.namespace
Stage = var.stage
custom_domains= "true"
}
}

records = [
locals {
main_dns_records = [
{
name = "*"
type = "CNAME"
Expand All @@ -21,4 +25,28 @@ module "records" {
]
}
]

custom_domain_dns_record = var.create_custom_domain_record ? {
name = var.custom_domain_record_value
type = "CNAME"
ttl = 300
records = [
data.aws_lb.custom_domains_ingress.0.dns_name
]
} : null

dns_records = concat(
local.main_dns_records,
var.create_custom_domain_record ? [ local.custom_domain_dns_record ] : []
)
}


module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "~> 2.11"

zone_name = var.route53_zone_name

records = local.dns_records
}
12 changes: 12 additions & 0 deletions lb-domain/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ variable "route53_zone_name" {
description = "The name of the Route53 zone"
}

variable "create_custom_domain_record" {
type = bool
description = "Define if a custom domain record should be created"
default = false
}

variable "custom_domain_record_value" {
type = string
description = "The value of the custom domain record"
default = "custom-loadbalancer"
}

variable "tags" {
type = map(string)
description = "A map of tags to add to all resources"
Expand Down

0 comments on commit 9e18fb5

Please sign in to comment.