Skip to content

Commit f3c1cbd

Browse files
author
rohit-ng
committed
update: replace sub and base domain input with domain
1 parent e6fb1d6 commit f3c1cbd

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

modules/route-53-record/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ No requirements.
66

77
| Name | Version |
88
|------|---------|
9-
| <a name="provider_aws"></a> [aws](#provider\_aws) | n/a |
9+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.60.0 |
1010

1111
## Modules
1212

@@ -17,7 +17,7 @@ No modules.
1717
| Name | Type |
1818
|------|------|
1919
| [aws_route53_record.record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
20-
| [aws_acm_certificate.base_domain_certificate](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/acm_certificate) | data source |
20+
| [aws_acm_certificate.domain](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/acm_certificate) | data source |
2121
| [aws_route53_zone.zone](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
2222

2323
## Inputs
@@ -26,8 +26,7 @@ No modules.
2626
|------|-------------|------|---------|:--------:|
2727
| <a name="input_alb_dns_name"></a> [alb\_dns\_name](#input\_alb\_dns\_name) | ALB DNS name | `string` | n/a | yes |
2828
| <a name="input_alb_zone_id"></a> [alb\_zone\_id](#input\_alb\_zone\_id) | ALB zone ID | `string` | n/a | yes |
29-
| <a name="input_base_domain"></a> [base\_domain](#input\_base\_domain) | The base domain for the Route 53 zone | `string` | n/a | yes |
30-
| <a name="input_endpoints"></a> [endpoints](#input\_endpoints) | A list of endpoints for which to create Route 53 records | `list(string)` | n/a | yes |
29+
| <a name="input_domain"></a> [domain](#input\_domain) | Domain name | `string` | n/a | yes |
3130

3231
## Outputs
3332

modules/route-53-record/data.tf

Lines changed: 0 additions & 9 deletions
This file was deleted.

modules/route-53-record/main.tf

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
locals {
2+
domain_parts = regexall("(.*\\.)?(.*\\..*)", var.domain)
3+
base_domain = length(local.domain_parts) > 0 && length(local.domain_parts[0]) > 1 ? local.domain_parts[0][1] : var.domain
4+
}
5+
6+
data "aws_acm_certificate" "domain" {
7+
domain = local.base_domain
8+
statuses = ["ISSUED"]
9+
most_recent = false
10+
}
11+
12+
data "aws_route53_zone" "zone" {
13+
name = local.base_domain
14+
}
15+
116
resource "aws_route53_record" "record" {
2-
for_each = toset(var.endpoints)
3-
zone_id = data.aws_route53_zone.zone.zone_id
4-
name = each.key
5-
type = "A"
17+
zone_id = data.aws_route53_zone.zone.zone_id
18+
name = var.domain
19+
type = "A"
620

721
alias {
822
name = var.alb_dns_name

modules/route-53-record/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
output "certificate_arn" {
22
description = "ARN of the base domain certificate"
3-
value = data.aws_acm_certificate.base_domain_certificate.arn
3+
value = data.aws_acm_certificate.domain.arn
44
}
55

66
output "zone_id" {

modules/route-53-record/variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
variable "base_domain" {
2-
description = "The base domain for the Route 53 zone"
1+
variable "domain" {
2+
description = "Domain name"
33
type = string
44
}
55

6-
variable "endpoints" {
7-
description = "A list of endpoints for which to create Route 53 records"
8-
type = list(string)
9-
}
10-
116
variable "alb_dns_name" {
127
description = "ALB DNS name"
138
type = string

0 commit comments

Comments
 (0)