Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
Merge pull request #357 from chroju/add-failover-attr-to-r53r
Browse files Browse the repository at this point in the history
Add failover attributes to Route53 record.
  • Loading branch information
dtan4 authored Sep 18, 2017
2 parents a7a9367 + fdf6343 commit 04eeaaf
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/terraforming/resource/route53_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions lib/terraforming/template/tf/route53_record.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
89 changes: 89 additions & 0 deletions spec/lib/terraforming/resource/route53_record_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 04eeaaf

Please sign in to comment.