Skip to content

Commit 833a717

Browse files
committed
refactor: route-53-record to read zone_id from variables
Re-use `acm_record_zone_id` for creating route53 record.
1 parent 1c86695 commit 833a717

File tree

4 files changed

+8
-17
lines changed

4 files changed

+8
-17
lines changed

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ module "grafana_backend_rds_security_group" {
377377
module "grafana_dns_record" {
378378
source = "./modules/route-53-record"
379379

380+
zone_id = var.acm_record_zone_id
380381
domain = var.acm_grafana_domain_name
381382
alb_dns_name = module.grafana_ecs_deployment.alb_dns_name
382383
alb_zone_id = module.grafana_ecs_deployment.alb_zone_id

modules/route-53-record/main.tf

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
locals {
2-
domain_parts = regexall("(.*\\.)?(.*\\..*)", var.domain)
3-
base_domain = (
4-
length(local.domain_parts) > 0 && length(local.domain_parts[0]) > 1 ?
5-
local.domain_parts[0][1] : var.domain)
6-
}
7-
81
################################################################################
92
# ACM Certificate
103
################################################################################
114

12-
data "aws_route53_zone" "base_domain" {
13-
name = local.base_domain
14-
}
15-
165
resource "aws_route53_record" "this" {
17-
zone_id = data.aws_route53_zone.base_domain.zone_id
6+
zone_id = var.zone_id
187
name = var.domain
198
type = "A"
209

modules/route-53-record/outputs.tf

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,3 @@ output "id" {
66
description = "Identifier of the Route53 Record"
77
value = aws_route53_record.this.id
88
}
9-
10-
output "zone_id" {
11-
description = "ID of the Route 53 zone"
12-
value = data.aws_route53_zone.base_domain.zone_id
13-
}

modules/route-53-record/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Route53 Record
33
################################################################################
44

5+
variable "zone_id" {
6+
description = "(Required) The ID of the hosted zone to contain this record."
7+
type = string
8+
nullable = false
9+
}
10+
511
variable "domain" {
612
description = "(Required) Domain name for which the certificate should be issued."
713
type = string

0 commit comments

Comments
 (0)