terraform的路由53故障切换策略
我正在尝试使用terraform为AWS上的域创建故障切换策略,问题是它只在route53资源后面附加一个elb dns名称作为主资源和辅助资源。我真的想让它以北弗吉尼亚厄尔巴托的名字为主,俄勒冈州为辅 这是一个多区域架构,我用相同的源目录创建了模块 文件名:route53.tfterraform的路由53故障切换策略,terraform,amazon-route53,terraform-provider-aws,Terraform,Amazon Route53,Terraform Provider Aws,我正在尝试使用terraform为AWS上的域创建故障切换策略,问题是它只在route53资源后面附加一个elb dns名称作为主资源和辅助资源。我真的想让它以北弗吉尼亚厄尔巴托的名字为主,俄勒冈州为辅 这是一个多区域架构,我用相同的源目录创建了模块 文件名:route53.tf resource "aws_route53_record" "www1" { zone_id = "Zone-ID" name = "www1" type = "A" #ttl =
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
}
}
文件名: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"
}
}
文件名: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"]
}
文件名:./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}"
}
目录树:
.
├── 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中添加以下内容:
output "dns_name" {
value = "${aws_elb.web.dns_name}"
}
这将输出DNS名称。在main.tf中,为route53创建一个单独的模块。
该模块应如下所示:
module "route53" {
source = "./modules/route53"
name1 = "${module.north-virginia.dns_name}"
name2 = "${module.oregon.dns_name}"
}
您的route53.tf应该类似于:
variable "name1" ()
varibale "name2" ()
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 = "${var.name1}"
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 = "${var.name2}"
zone_id = "${aws_elb.web.zone_id}"
evaluate_target_health = true
}
}
这个问题没有提供足够的信息来帮助回答它。你能举一个更完整的例子来说明你在做什么吗?它将有助于查看所有相关的(但不是更多的)地形代码以及代码库中的任何特定结构。现在我们还需要了解您是如何创建两个ELB的,因为您的示例似乎显示了两个完全独立的DNS记录,其中主记录集和次记录集(错误)都指向同一个ELB。如果您试图创建一个新的代码,我建议您首先运行它来检查它是否显示与您的真实代码相同的问题。我已经为elb和main.tf添加了代码。模块中的
alb_elb.tf
和route53.tf
?您使用区域变量做什么?您是否也使用它来配置提供程序块?你能把那个部分也展示一下吗?是的,它们是模块的一部分。我使用region变量从main.tf获取区域名称,该名称将与模块一起使用。是的,我正在与提供者块一起使用它。我已经用目录树和main.tf更新了这个问题。