lib/terraforming/resource/route53_zone.rb in terraforming-0.1.6 vs lib/terraforming/resource/route53_zone.rb in terraforming-0.2.0
- old
+ new
@@ -20,16 +20,19 @@
end
def tfstate
hosted_zones.inject({}) do |resources, hosted_zone|
zone_id = zone_id_of(hosted_zone)
+ vpc = vpc_of(hosted_zone)
attributes = {
"id"=> zone_id,
"name"=> name_of(hosted_zone),
"name_servers.#" => name_servers_of(hosted_zone).length.to_s,
"tags.#" => tags_of(hosted_zone).length.to_s,
+ "vpc_id" => vpc ? vpc.vpc_id : "",
+ "vpc_region" => vpc ? vpc.vpc_region : "",
"zone_id" => zone_id,
}
resources["aws_route53_zone.#{module_name_of(hosted_zone)}"] = {
"type" => "aws_route53_zone",
"primary" => {
@@ -43,30 +46,39 @@
end
private
def hosted_zones
- @client.list_hosted_zones.hosted_zones
+ @client.list_hosted_zones.hosted_zones.map { |hosted_zone| @client.get_hosted_zone(id: hosted_zone.id) }
end
def tags_of(hosted_zone)
@client.list_tags_for_resource(resource_type: "hostedzone", resource_id: zone_id_of(hosted_zone)).resource_tag_set.tags
end
def name_of(hosted_zone)
- hosted_zone.name.gsub(/\.\z/, "")
+ hosted_zone.hosted_zone.name.gsub(/\.\z/, "")
end
def name_servers_of(hosted_zone)
- @client.get_hosted_zone(id: hosted_zone.id).delegation_set.name_servers
+ delegation_set = hosted_zone.delegation_set
+ delegation_set ? delegation_set.name_servers : []
end
def module_name_of(hosted_zone)
- normalize_module_name(name_of(hosted_zone))
+ normalize_module_name(name_of(hosted_zone)) << "-#{private_hosted_zone?(hosted_zone) ? 'private' : 'public'}"
end
+ def private_hosted_zone?(hosted_zone)
+ hosted_zone.hosted_zone.config.private_zone
+ end
+
+ def vpc_of(hosted_zone)
+ hosted_zone.vp_cs[0]
+ end
+
def zone_id_of(hosted_zone)
- hosted_zone.id.gsub(/\A\/hostedzone\//, "")
+ hosted_zone.hosted_zone.id.gsub(/\A\/hostedzone\//, "")
end
end
end
end