I am tried creating a failover policy for a domain on AWS using terraform, The issue is It is attaching only one elb dns name behind both route53 resource as PRIMARY and SECONDARY. I actually want it to use North-Virginia elb name as PRIMARY and Oregon as SECONDARY.
This is a multi-region architecture and I have created the modules with the same source directory.
Filename: route53.tf
resource "aws_route53_record" "www1" {
zone_id = "Zone-ID"
name = "www1"
type = "A"
#ttl = "5"
failover_routing_policy {
type = "PRIMARY"
}
set_identifier = "www1"
#records = ["${aws_elb.web.dns_name}"]
alias {
name = "${aws_elb.web.dns_name}"
zone_id = "${aws_elb.web.zone_id}"
evaluate_target_health = true
}
}
resource "aws_route53_record" "www2" {
zone_id = "Zone-ID"
name = "www2"
type = "A"
#ttl = "5"
failover_routing_policy {
type = "SECONDARY"
}
set_identifier = "www2"
#records = ["${aws_elb.web.dns_name}"]
alias {
name = "${aws_elb.web.dns_name}"
zone_id = "${aws_elb.web.zone_id}"
evaluate_target_health = true
}
}
FileName: alb_elb.tf
resource "aws_elb" "web" {
name = "web-elb"
availability_zones = "${var.az}"
listener {
instance_port = 8000
instance_protocol = "http"
lb_port = 80
lb_protocol = "http"
}
health_check {
healthy_threshold = 2
unhealthy_threshold = 2
timeout = 3
target = "HTTP:8000/"
interval = 30
}
instances = ["${aws_instance.web.*.id}"]
cross_zone_load_balancing = true
idle_timeout = 400
connection_draining = true
connection_draining_timeout = 400
tags {
Name = "foobar-terraform-elb"
}
}
Filename: main.tf.
module "north-virginia" {
source = "./modules/production"
region = "us-east-1"
az = ["us-east-1a", "us-east-1b", "us-east-1c"]
}
module "oregon" {
source = "./modules/production"
region = "us-west-2"
az = ["us-west-2a", "us-west-2b", "us-west-2c"]
}
Filename: ./production/module/main.tf
variable region { }
variable az {
type = "list"
}
provider "aws" {
region = "${var.region}"
profile = "personal"
shared_credentials_file = "~/.aws/credentials"
}
data "aws_caller_identity" "current" {}
output "account_id" {
value = "${data.aws_caller_identity.current.account_id}"
}
Directory Tree:
.
├── main.tf
└── modules
├── dev
│ ├── ec2.tf
│ ├── main.tf
│ └── route53.tf
├── production
│ ├── aws_elb.tf
│ ├── aws_instance.tf
│ ├── main.tf
│ └── route53.tf
└── qa
├── ec2.tf
├── main.tf
└── route53.tf
alb_elb.tf
androute53.tf
in the module? What are you doing with the region variable? Are you using that to configure the provider blocks as well? Can you show that part too? – ydaetskcoR