From fdf6343cbfb43bfcf9572171473cac98805da191 Mon Sep 17 00:00:00 2001 From: chroju Date: Thu, 24 Aug 2017 23:19:49 +0900 Subject: [PATCH] Add failover settings to Route53 record. * Add "failover_routing_policy" to Route53 record tf and tfstate files. * Add "health_check_id" to Route53 record tf and tfstate files. --- lib/terraforming/resource/route53_record.rb | 6 ++ .../template/tf/route53_record.erb | 9 ++ .../resource/route53_record_spec.rb | 89 +++++++++++++++++++ 3 files changed, 104 insertions(+) diff --git a/lib/terraforming/resource/route53_record.rb b/lib/terraforming/resource/route53_record.rb index a6bda324..f15965f9 100644 --- a/lib/terraforming/resource/route53_record.rb +++ b/lib/terraforming/resource/route53_record.rb @@ -44,7 +44,13 @@ def tfstate attributes["subdivision"] = record.geo_location.subdivision_code if record.geo_location.subdivision_code end + if record.failover + attributes["failover_routing_policy.#"] = "1" + attributes["failover_routing_policy.0.type"] = record.failover + end + attributes["set_identifier"] = record.set_identifier if record.set_identifier + attributes["health_check_id"] = record.health_check_id if record.health_check_id resources["aws_route53_record.#{module_name_of(record, counter)}"] = { "type" => "aws_route53_record", diff --git a/lib/terraforming/template/tf/route53_record.erb b/lib/terraforming/template/tf/route53_record.erb index 4e200e89..d352309a 100644 --- a/lib/terraforming/template/tf/route53_record.erb +++ b/lib/terraforming/template/tf/route53_record.erb @@ -38,6 +38,15 @@ resource "aws_route53_record" "<%= module_name_of(record, counter) %>" { <%- if record.set_identifier -%> set_identifier = "<%= record.set_identifier %>" <%- end -%> +<%- if record.health_check_id -%> + health_check_id = "<%= record.health_check_id %>" +<%- end -%> + <%- if record.failover -%> + + failover_routing_policy { + type = "<%= record.failover %>" + } + <%- end -%> <%- if record.alias_target -%> alias { diff --git a/spec/lib/terraforming/resource/route53_record_spec.rb b/spec/lib/terraforming/resource/route53_record_spec.rb index 1a9de3df..10f8845e 100644 --- a/spec/lib/terraforming/resource/route53_record_spec.rb +++ b/spec/lib/terraforming/resource/route53_record_spec.rb @@ -96,6 +96,29 @@ module Resource weight: nil, set_identifier: nil, }, + { + name: "failover.example.net.", + type: "A", + ttl: 3600, + weight: nil, + set_identifier: "failover_group", + health_check_id: "1234abcd-56ef-78gh-90ij-123456klmnop", + resource_records: [ + { value: "192.0.2.101" } + ], + failover: "PRIMARY" + }, + { + name: "failover.example.net.", + type: "A", + ttl: 3600, + weight: nil, + set_identifier: "failover_group", + resource_records: [ + { value: "192.0.2.102" } + ], + failover: "SECONDARY" + }, ] end @@ -165,6 +188,35 @@ module Resource type = "A" ttl = "60" +} + +resource "aws_route53_record" "failover-example-net-A-0" { + zone_id = "CDEFGHIJKLMNOP" + name = "failover.example.net" + type = "A" + records = ["192.0.2.101"] + ttl = "3600" + set_identifier = "failover_group" + health_check_id = "1234abcd-56ef-78gh-90ij-123456klmnop" + + failover_routing_policy { + type = "PRIMARY" + } + +} + +resource "aws_route53_record" "failover-example-net-A-1" { + zone_id = "CDEFGHIJKLMNOP" + name = "failover.example.net" + type = "A" + records = ["192.0.2.102"] + ttl = "3600" + set_identifier = "failover_group" + + failover_routing_policy { + type = "SECONDARY" + } + } EOS @@ -249,6 +301,43 @@ module Resource }, } }, + "aws_route53_record.failover-example-net-A-0" => { + "type" => "aws_route53_record", + "primary" => { + "id" => "CDEFGHIJKLMNOP_failover.example.net_A", + "attributes" => { + "failover_routing_policy.#" => "1", + "failover_routing_policy.0.type" => "PRIMARY", + "health_check_id" => "1234abcd-56ef-78gh-90ij-123456klmnop", + "id" => "CDEFGHIJKLMNOP_failover.example.net_A", + "name" => "failover.example.net", + "type" => "A", + "zone_id" => "CDEFGHIJKLMNOP", + "records.#" => "1", + "weight" => "-1", + "ttl" => "3600", + "set_identifier" => "failover_group", + }, + } + }, + "aws_route53_record.failover-example-net-A-1" => { + "type" => "aws_route53_record", + "primary" => { + "id" => "CDEFGHIJKLMNOP_failover.example.net_A", + "attributes" => { + "failover_routing_policy.#" => "1", + "failover_routing_policy.0.type" => "SECONDARY", + "id" => "CDEFGHIJKLMNOP_failover.example.net_A", + "name" => "failover.example.net", + "type" => "A", + "zone_id" => "CDEFGHIJKLMNOP", + "records.#" => "1", + "weight" => "-1", + "ttl" => "3600", + "set_identifier" => "failover_group", + }, + } + }, }) end end