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 @@ ...@@ -2,3 +2,4 @@
terraform.tfstate terraform.tfstate
*.tfstate* *.tfstate*
terraform.tfvars terraform.tfvars
.terraform.lock.hcl
...@@ -63,6 +63,26 @@ module "records" { ...@@ -63,6 +63,26 @@ module "records" {
zone_id = module.cloudfront.this_cloudfront_distribution_hosted_zone_id 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] depends_on = [module.zones]
...@@ -101,12 +121,10 @@ module "cloudfront" { ...@@ -101,12 +121,10 @@ module "cloudfront" {
} }
} }
cache_behavior = { default_cache_behavior = {
default = {
target_origin_id = "s3_bucket" target_origin_id = "s3_bucket"
viewer_protocol_policy = "allow-all" viewer_protocol_policy = "allow-all"
} }
}
viewer_certificate = { viewer_certificate = {
cloudfront_default_certificate = true cloudfront_default_certificate = true
......
locals { locals {
# convert from list to map with unique keys # 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" { data "aws_route53_zone" "this" {
...@@ -20,6 +20,7 @@ resource "aws_route53_record" "this" { ...@@ -20,6 +20,7 @@ resource "aws_route53_record" "this" {
type = each.value.type type = each.value.type
ttl = lookup(each.value, "ttl", null) ttl = lookup(each.value, "ttl", null)
records = lookup(each.value, "records", null) records = lookup(each.value, "records", null)
set_identifier = lookup(each.value, "set_identifier", null)
dynamic "alias" { dynamic "alias" {
for_each = length(keys(lookup(each.value, "alias", {}))) == 0 ? [] : [true] for_each = length(keys(lookup(each.value, "alias", {}))) == 0 ? [] : [true]
...@@ -30,4 +31,12 @@ resource "aws_route53_record" "this" { ...@@ -30,4 +31,12 @@ resource "aws_route53_record" "this" {
evaluate_target_health = lookup(each.value.alias, "evaluate_target_health", false) 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