Commit e87b6262 authored by Anton Babenko's avatar Anton Babenko Committed by GitHub

feat: added weighted routing policy (#23)

parent 42244d4d
......@@ -2,3 +2,4 @@
terraform.tfstate
*.tfstate*
terraform.tfvars
.terraform.lock.hcl
......@@ -63,6 +63,26 @@ module "records" {
zone_id = module.cloudfront.this_cloudfront_distribution_hosted_zone_id
}
},
{
name = "test"
type = "CNAME"
ttl = "5"
records = ["test.example.com."]
set_identifier = "test-primary"
weighted_routing_policy = {
weight = 90
}
},
{
name = "test"
type = "CNAME"
ttl = "5"
records = ["test2.example.com."]
set_identifier = "test-secondary"
weighted_routing_policy = {
weight = 10
}
}
]
depends_on = [module.zones]
......@@ -101,11 +121,9 @@ module "cloudfront" {
}
}
cache_behavior = {
default = {
target_origin_id = "s3_bucket"
viewer_protocol_policy = "allow-all"
}
default_cache_behavior = {
target_origin_id = "s3_bucket"
viewer_protocol_policy = "allow-all"
}
viewer_certificate = {
......
locals {
# convert from list to map with unique keys
recordsets = { for rs in var.records : "${rs.name} ${rs.type}" => rs }
recordsets = { for rs in var.records : join(" ", compact(["${rs.name} ${rs.type}", lookup(rs, "set_identifier", "")])) => rs }
}
data "aws_route53_zone" "this" {
......@@ -16,10 +16,11 @@ resource "aws_route53_record" "this" {
zone_id = data.aws_route53_zone.this[0].zone_id
name = each.value.name != "" ? "${each.value.name}.${data.aws_route53_zone.this[0].name}" : data.aws_route53_zone.this[0].name
type = each.value.type
ttl = lookup(each.value, "ttl", null)
records = lookup(each.value, "records", null)
name = each.value.name != "" ? "${each.value.name}.${data.aws_route53_zone.this[0].name}" : data.aws_route53_zone.this[0].name
type = each.value.type
ttl = lookup(each.value, "ttl", null)
records = lookup(each.value, "records", null)
set_identifier = lookup(each.value, "set_identifier", null)
dynamic "alias" {
for_each = length(keys(lookup(each.value, "alias", {}))) == 0 ? [] : [true]
......@@ -30,4 +31,12 @@ resource "aws_route53_record" "this" {
evaluate_target_health = lookup(each.value.alias, "evaluate_target_health", false)
}
}
dynamic "weighted_routing_policy" {
for_each = length(keys(lookup(each.value, "weighted_routing_policy", {}))) == 0 ? [] : [true]
content {
weight = each.value.weighted_routing_policy.weight
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment