Skip to content

use the cname module #4

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ Change logs are auto-generated with commitizen.

## Modules

No modules.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_cname_cluster_domain"></a> [cname\_cluster\_domain](#module\_cname\_cluster\_domain) | git@github.e.it.census.gov:terraform-modules/aws-dns//cname | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_route53_record.entry](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_record.entry_heritage](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
| [aws_route53_vpc_association_authorization.self_zone_east](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_vpc_association_authorization) | resource |
| [aws_route53_vpc_association_authorization.self_zone_west](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_vpc_association_authorization) | resource |
| [aws_route53_zone.cluster_domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_zone) | resource |
Expand Down
46 changes: 6 additions & 40 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,9 @@
#-------------------------------------------------

locals {
defaults = {
enable_ptr = {
cname = false
a = false
aaaa = false
txt = false
host = true
ptr = true
}
heritage_label = "terraform"
heritage_prefix = {
cname = "_txt"
a = ""
aaaa = ""
txt = "_txt"
host = ""
ptr = ""
}
}
base_heritage_tags = [
format("heritage=%v", local.defaults.heritage_label),
format("%v/account_id=%v", local.defaults.heritage_label, data.aws_caller_identity.current.account_id),
format("%v/region=%v", local.defaults.heritage_label, local.region),
format("%v/create_time=%d", local.defaults.heritage_label, time_static.timestamp.unix)
]
cluster_domain_description = format("%v EKS Cluster DNS Zone", var.cluster_name)
cluster_domain_name = format("%v.%v", var.cluster_name, local.vpc_domain_name)
default_heritage_prefix = lookup(local.defaults.heritage_prefix, local.record_type, "") != "" ? format("%v.", local.defaults.heritage_prefix[local.record_type]) : ""
is_shared_vpc = data.aws_vpc.eks_vpc.owner_id != data.aws_caller_identity.current.account_id
record_type = "cname"
region = var.region
vpc_domain_name = var.vpc_domain_name
}
Expand Down Expand Up @@ -122,18 +95,11 @@ resource "aws_route53_zone_association" "self_zone_west" {
# Cluster DNS CNAME MAPPED TO INGRESS NLB
###################################################################

resource "aws_route53_record" "entry" {
name = "*.${local.cluster_domain_name}"
records = [data.aws_lb.lb.dns_name]
ttl = 900
type = "CNAME"
zone_id = aws_route53_zone.cluster_domain.zone_id
}
module "cname_cluster_domain" {
# tflint-ignore: terraform_module_pinned_source
source = "git@github.e.it.census.gov:terraform-modules/aws-dns//cname"

resource "aws_route53_record" "entry_heritage" {
name = format("%v%v", local.default_heritage_prefix, "*.${local.cluster_domain_name}")
records = [join(",", local.base_heritage_tags)]
ttl = 900
type = "TXT"
zone_id = aws_route53_zone.cluster_domain.zone_id
name = format("%v.%v", "*", local.cluster_domain_name)
values = data.aws_lb.lb.dns_name
zone = aws_route53_zone.cluster_domain.zone_id
}