From 26d366d3047f437154946b2bb15935c2ee34a209 Mon Sep 17 00:00:00 2001 From: Blake Gentry Date: Thu, 16 Aug 2012 15:35:05 -0700 Subject: [PATCH] automatically figure out the elb hosted_zone_id if possible * Fixes #1098 --- .../dns/change_resource_record_sets.rb | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/fog/aws/requests/dns/change_resource_record_sets.rb b/lib/fog/aws/requests/dns/change_resource_record_sets.rb index 04463d13d..190725adc 100644 --- a/lib/fog/aws/requests/dns/change_resource_record_sets.rb +++ b/lib/fog/aws/requests/dns/change_resource_record_sets.rb @@ -106,8 +106,8 @@ module Fog alias_target_tag = '' if change_item[:alias_target] # Accept either underscore or camel case for hash keys. - hosted_zone_id = change_item[:alias_target][:hosted_zone_id] || change_item[:alias_target][:HostedZoneId] dns_name = change_item[:alias_target][:dns_name] || change_item[:alias_target][:DNSName] + hosted_zone_id = change_item[:alias_target][:hosted_zone_id] || change_item[:alias_target][:HostedZoneId] || AWS.hosted_zone_for_alias_target(dns_name) alias_target_tag += %Q{#{hosted_zone_id}#{dns_name}} end @@ -186,6 +186,25 @@ module Fog end end end + + def self.hosted_zone_for_alias_target(dns_name) + k = elb_hosted_zone_mapping.keys.find do |k| + dns_name =~ /\A.+\.#{k}\.elb\.amazonaws\.com\.?\z/ + end + elb_hosted_zone_mapping[k] + end + + def self.elb_hosted_zone_mapping + @elb_hosted_zone_mapping ||= { + "ap-northeast-1" => "Z2YN17T5R711GT", + "ap-southeast-1" => "Z1WI8VXHPB1R38", + "eu-west-1" => "Z3NF1Z3NOM5OY2", + "sa-east-1" => "Z2ES78Y61JGQKS", + "us-east-1" => "Z3DZXE0Q79N41H", + "us-west-1" => "Z1M58G0W56PQJA", + "us-west-2" => "Z33MTJ483KN6FU", + } + end end end end