Skip to content

Commit 6de4621

Browse files
author
Premdeep Saini
committed
feat: add secondary record and failover policy
1 parent ef2d4f3 commit 6de4621

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ module "app_ingress" {
3939
target_group_healthcheck_protocol = "HTTP"
4040
target_group_healthcheck_interval = 30
4141
target_group_healthcheck_timeout = 5
42+
enable_failover_policy = true
43+
primary_record_healthcheck_id = "primary_healthcheck_id"
44+
secondary_record_alias_name = "secondary_alias_name"
45+
secondary_record_zone_id = "secondary_zone_id"
46+
secondary_record_healthcheck_id = "secondary_healthcheck_id"
4247
}
4348
```
4449

@@ -83,6 +88,7 @@ No modules.
8388
| [aws_lb_listener_rule.app](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_listener_rule) | resource |
8489
| [aws_lb_target_group.app](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lb_target_group) | resource |
8590
| [aws_route53_record.alb_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
91+
| [aws_route53_record.secondary_alb_record](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
8692
| [aws_route53_record.app_validation](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record) | resource |
8793
| [aws_s3_bucket.alb_access_logs](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
8894
| [aws_s3_bucket_acl.alb_access_logs_private](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
@@ -120,6 +126,11 @@ No modules.
120126
| target_group_healthcheck_port | Port to use to connect with the target. Valid values are any valid port or "traffic-port". Defaults to "traffic-port". | `string` | "traffic-port" | no |
121127
| target_group_healthcheck_protocol | Protocol to use to connect with the target. Defaults to "HTTP". | `string` | "HTTP" | no |
122128
| target_group_healthcheck_timeout | Amount of time, in seconds, during which no response means a failed health check. Defaults to 5. | `number` | 5 | no |
129+
| enable_failover_policy | Should enable/disable Failover policy for the subdomain record | `bool` | `false` | no |
130+
| primary_record_healthcheck_id | For Failover Routing policy only. Healthcheck Id of primary record. | `string` | `null` | no |
131+
| secondary_record_alias_name | For Failoverrouting policy only. Alias name for secondary record. | `string` | `null` | no |
132+
| secondary_record_healthcheck_id | For Failover Routing policy only. Healthcheck Id of secondary record. | `string` | `null` | no |
133+
| secondary_record_zone_id | For Failoverrouting policy only. Zone Id for secondary record. | `string` | `null` | no |
123134

124135
### Outputs
125136

route53.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,31 @@ resource "aws_route53_record" "alb_record" {
1111
name = aws_lb.alb.dns_name
1212
zone_id = aws_lb.alb.zone_id
1313
}
14+
dynamic "failover_routing_policy" {
15+
for_each = var.enable_failover_policy ? { value : "dummy_value" } : {}
16+
content {
17+
type = "PRIMARY"
18+
}
19+
}
20+
health_check_id = var.enable_failover_policy ? var.primary_record_healthcheck_id : null
21+
set_identifier = var.enable_failover_policy ? "primary_${var.app_subdomain_name}" : null
22+
}
23+
24+
resource "aws_route53_record" "secondary_alb_record" {
25+
count = var.enable_failover_policy ? 1 : 0
26+
name = var.app_subdomain_name
27+
type = "A"
28+
zone_id = data.aws_route53_zone.zone.zone_id
29+
alias {
30+
evaluate_target_health = false
31+
name = var.secondary_record_alias_name
32+
zone_id = var.secondary_record_zone_id
33+
}
34+
health_check_id = var.secondary_record_healthcheck_id
35+
set_identifier = "secondary_${var.app_subdomain_name}"
36+
failover_routing_policy {
37+
type = "SECONDARY"
38+
}
1439
}
1540

1641
resource "aws_route53_record" "app_validation" {

variables.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,33 @@ variable "target_group_deregistration_delay" {
113113
description = "Amount of time, in seconds, for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused"
114114
default = 300
115115
}
116+
117+
variable "enable_failover_policy" {
118+
type = bool
119+
description = "Should enable/disable Failover policy for the subdomain record"
120+
default = false
121+
}
122+
123+
variable "primary_record_healthcheck_id" {
124+
type = string
125+
description = "For Failover Routing policy only. Healthcheck Id of primary record."
126+
default = null
127+
}
128+
129+
variable "secondary_record_alias_name" {
130+
type = string
131+
description = "For Failoverrouting policy only. Alias name for secondary record."
132+
default = null
133+
}
134+
135+
variable "secondary_record_zone_id" {
136+
type = string
137+
description = "For Failoverrouting policy only. Zone Id for secondary record."
138+
default = null
139+
}
140+
141+
variable "secondary_record_healthcheck_id" {
142+
type = string
143+
description = "For Failover Routing policy only. Healthcheck Id of secondary record."
144+
default = null
145+
}

0 commit comments

Comments
 (0)