Merge pull request #1140 from Pallokala/topic_route53_support_hosted_zone_id

Add support for specifying unique hosted zone identifier
This commit is contained in:
Brian Coca 2015-07-06 12:28:48 -04:00
commit abdd96ed1e

View file

@ -35,6 +35,12 @@ options:
required: true required: true
default: null default: null
aliases: [] aliases: []
hosted_zone_id:
description:
- The Hosted Zone ID of the DNS zone to modify
required: false
version_added: 2.0
default: null
record: record:
description: description:
- The full DNS record to create or delete - The full DNS record to create or delete
@ -195,6 +201,28 @@ EXAMPLES = '''
alias=True alias=True
alias_hosted_zone_id="{{ elb_zone_id }}" alias_hosted_zone_id="{{ elb_zone_id }}"
# Add an AAAA record with Hosted Zone ID. Note that because there are colons in the value
# that the entire parameter list must be quoted:
- route53:
command: "create"
zone: "foo.com"
hostes_zone_id: "Z2AABBCCDDEEFF"
record: "localhost.foo.com"
type: "AAAA"
ttl: "7200"
value: "::1"
# Add an AAAA record with Hosted Zone ID. Note that because there are colons in the value
# that the entire parameter list must be quoted:
- route53:
command: "create"
zone: "foo.com"
hostes_zone_id: "Z2AABBCCDDEEFF"
record: "localhost.foo.com"
type: "AAAA"
ttl: "7200"
value: "::1"
# Use a routing policy to distribute traffic: # Use a routing policy to distribute traffic:
- route53: - route53:
command: "create" command: "create"
@ -222,13 +250,13 @@ try:
except ImportError: except ImportError:
HAS_BOTO = False HAS_BOTO = False
def get_zone_by_name(conn, module, zone_name, want_private): def get_zone_by_name(conn, module, zone_name, want_private, zone_id):
"""Finds a zone by name""" """Finds a zone by name or zone_id"""
for zone in conn.get_zones(): for zone in conn.get_zones():
# only save this zone id if the private status of the zone matches # only save this zone id if the private status of the zone matches
# the private_zone_in boolean specified in the params # the private_zone_in boolean specified in the params
private_zone = module.boolean(zone.config.get('PrivateZone', False)) private_zone = module.boolean(zone.config.get('PrivateZone', False))
if private_zone == want_private and zone.name == zone_name: if private_zone == want_private and ((zone.name == zone_name and zone_id == None) or zone.id.replace('/hostedzone/', '') == zone_id):
return zone return zone
return None return None
@ -252,6 +280,7 @@ def main():
argument_spec.update(dict( argument_spec.update(dict(
command = dict(choices=['get', 'create', 'delete'], required=True), command = dict(choices=['get', 'create', 'delete'], required=True),
zone = dict(required=True), zone = dict(required=True),
hosted_zone_id = dict(required=False, default=None),
record = dict(required=True), record = dict(required=True),
ttl = dict(required=False, type='int', default=3600), ttl = dict(required=False, type='int', default=3600),
type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True), type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True),
@ -275,6 +304,7 @@ def main():
command_in = module.params.get('command') command_in = module.params.get('command')
zone_in = module.params.get('zone').lower() zone_in = module.params.get('zone').lower()
hosted_zone_id_in = module.params.get('hosted_zone_id')
ttl_in = module.params.get('ttl') ttl_in = module.params.get('ttl')
record_in = module.params.get('record').lower() record_in = module.params.get('record').lower()
type_in = module.params.get('type') type_in = module.params.get('type')
@ -321,7 +351,7 @@ def main():
module.fail_json(msg = e.error_message) module.fail_json(msg = e.error_message)
# Find the named zone ID # Find the named zone ID
zone = get_zone_by_name(conn, module, zone_in, private_zone_in) zone = get_zone_by_name(conn, module, zone_in, private_zone_in, hosted_zone_id_in)
# Verify that the requested zone is already defined in Route53 # Verify that the requested zone is already defined in Route53
if zone is None: if zone is None:
@ -355,11 +385,15 @@ def main():
record['ttl'] = rset.ttl record['ttl'] = rset.ttl
record['value'] = ','.join(sorted(rset.resource_records)) record['value'] = ','.join(sorted(rset.resource_records))
record['values'] = sorted(rset.resource_records) record['values'] = sorted(rset.resource_records)
if hosted_zone_id_in:
record['hosted_zone_id'] = hosted_zone_id_in
record['identifier'] = rset.identifier record['identifier'] = rset.identifier
record['weight'] = rset.weight record['weight'] = rset.weight
record['region'] = rset.region record['region'] = rset.region
record['failover'] = rset.failover record['failover'] = rset.failover
record['health_check'] = rset.health_check record['health_check'] = rset.health_check
if hosted_zone_id_in:
record['hosted_zone_id'] = hosted_zone_id_in
if rset.alias_dns_name: if rset.alias_dns_name:
record['alias'] = True record['alias'] = True
record['value'] = rset.alias_dns_name record['value'] = rset.alias_dns_name