-
Notifications
You must be signed in to change notification settings - Fork 659
Fixes for route53_records #303
Changes from 3 commits
cf8e0ca
4207655
07c7ad8
9e9a1ff
3031af9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ def tf | |
def tfstate | ||
records.inject({}) do |resources, r| | ||
record, zone_id = r[:record], r[:zone_id] | ||
counter = r[:counter] | ||
record_id = record_id_of(record, zone_id) | ||
|
||
attributes = { | ||
|
@@ -35,9 +36,15 @@ def tfstate | |
attributes["records.#"] = record.resource_records.length.to_s unless record.resource_records.empty? | ||
attributes["ttl"] = record.ttl.to_s if record.ttl | ||
attributes["weight"] = record.weight ? record.weight.to_s : "-1" | ||
attributes["region"] = record.region if record.region | ||
if record.geo_location | ||
attributes["continent"] = record.geo_location.continent_code if record.geo_location.continent_code | ||
attributes["country"] = record.geo_location.country_code if record.geo_location.country_code | ||
attributes["subdivision"] = record.geo_location.subdivision_code if record.geo_location.subdivision_code | ||
end | ||
attributes["set_identifier"] = record.set_identifier if record.set_identifier | ||
|
||
resources["aws_route53_record.#{module_name_of(record)}"] = { | ||
resources["aws_route53_record.#{module_name_of(record, counter)}"] = { | ||
"type" => "aws_route53_record", | ||
"primary" => { | ||
"id" => record_id, | ||
|
@@ -66,18 +73,32 @@ def record_sets_of(hosted_zone) | |
end | ||
|
||
def records | ||
hosted_zones.map do |hosted_zone| | ||
to_return = hosted_zones.map do |hosted_zone| | ||
record_sets_of(hosted_zone).map { |record| { record: record, zone_id: zone_id_of(hosted_zone) } } | ||
end.flatten | ||
count = {} | ||
dups = to_return.group_by{ |record| module_name_of(record[:record], nil) }.select { |k, v| v.size > 1 }.map(&:first) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [rubocop]
|
||
to_return.each do |r| | ||
module_name = module_name_of(r[:record], nil) | ||
if dups.include?(module_name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [rubocop]
|
||
if count[module_name] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [rubocop]
|
||
count[module_name] = count[module_name] + 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [rubocop]
|
||
else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [rubocop]
|
||
count[module_name] = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [rubocop]
|
||
end | ||
r[:counter] = count[module_name] | ||
end | ||
end | ||
to_return | ||
end | ||
|
||
# TODO(dtan4): change method name... | ||
def name_of(dns_name) | ||
dns_name.gsub(/\.\z/, "") | ||
end | ||
|
||
def module_name_of(record) | ||
normalize_module_name(name_of(record.name) + "-" + record.type) | ||
def module_name_of(record, counter) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [method_definition_validator]
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears as though each resource type has its own There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [method_definition_validator]
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [method_definition_validator]
|
||
normalize_module_name(name_of(record.name) + "-" + record.type + (!counter.nil? ? "-" + counter.to_s : "")) | ||
end | ||
|
||
def zone_id_of(hosted_zone) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,9 @@ module Resource | |
zone_id = "OPQRSTUVWXYZAB" | ||
name = "www.fuga.net" | ||
type = "A" | ||
weight = 10 | ||
weighted_routing_policy { | ||
weight = 10 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use 4-spaces indention, like |
||
} | ||
|
||
alias { | ||
name = "fuga.net" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add empty lines before
if
and afterend
.