Add support for specifying unique hosted zone identifier
This commit is contained in:
parent
62b6cf85d3
commit
3f2d1e6bfa
1 changed files with 39 additions and 3 deletions
|
@ -35,6 +35,12 @@ options:
|
|||
required: true
|
||||
default: null
|
||||
aliases: []
|
||||
hosted_zone_id:
|
||||
description:
|
||||
- The Hosted Zone ID of the DNS zone to modify
|
||||
required: false
|
||||
default: null
|
||||
aliases: []
|
||||
record:
|
||||
description:
|
||||
- The full DNS record to create or delete
|
||||
|
@ -208,6 +214,17 @@ EXAMPLES = '''
|
|||
weight: 100
|
||||
health_check: "d994b780-3150-49fd-9205-356abdd42e75"
|
||||
|
||||
# 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"
|
||||
|
||||
'''
|
||||
|
||||
import time
|
||||
|
@ -251,6 +268,7 @@ def main():
|
|||
argument_spec.update(dict(
|
||||
command = dict(choices=['get', 'create', 'delete'], required=True),
|
||||
zone = dict(required=True),
|
||||
hosted_zone_id = dict(required=False),
|
||||
record = dict(required=True),
|
||||
ttl = dict(required=False, default=3600),
|
||||
type = dict(choices=['A', 'CNAME', 'MX', 'AAAA', 'TXT', 'PTR', 'SRV', 'SPF', 'NS'], required=True),
|
||||
|
@ -274,6 +292,7 @@ def main():
|
|||
|
||||
command_in = module.params.get('command')
|
||||
zone_in = module.params.get('zone').lower()
|
||||
hosted_zone_id_in = module.params.get('hosted_zone_id')
|
||||
ttl_in = int(module.params.get('ttl'))
|
||||
record_in = module.params.get('record').lower()
|
||||
type_in = module.params.get('type')
|
||||
|
@ -318,11 +337,26 @@ def main():
|
|||
except boto.exception.BotoServerError, e:
|
||||
module.fail_json(msg = e.error_message)
|
||||
|
||||
# Find the named zone ID
|
||||
zone = get_zone_by_name(conn, module, zone_in, private_zone_in)
|
||||
# Get all the existing hosted zones and save their ID's
|
||||
zones = {}
|
||||
results = conn.get_all_hosted_zones()
|
||||
for r53zone in results['ListHostedZonesResponse']['HostedZones']:
|
||||
# only save this zone id if the private status of the zone matches
|
||||
# the private_zone_in boolean specified in the params
|
||||
if module.boolean(r53zone['Config'].get('PrivateZone', False)) == private_zone_in:
|
||||
zone_id = r53zone['Id'].replace('/hostedzone/', '')
|
||||
# only save when unique hosted_zone_id is given and is equal
|
||||
# hosted_zone_id_in is specified in the params
|
||||
if hosted_zone_id_in and zone_id == hosted_zone_id_in:
|
||||
zones[r53zone['Name']] = zone_id
|
||||
elif not hosted_zone_id_in:
|
||||
zones[r53zone['Name']] = zone_id
|
||||
|
||||
# Verify that the requested zone is already defined in Route53
|
||||
if zone is None:
|
||||
if not zone_in in zones and hosted_zone_id_in:
|
||||
errmsg = "Hosted_zone_id %s does not exist in Route53" % hosted_zone_id_in
|
||||
module.fail_json(msg = errmsg)
|
||||
if not zone_in in zones:
|
||||
errmsg = "Zone %s does not exist in Route53" % zone_in
|
||||
module.fail_json(msg = errmsg)
|
||||
|
||||
|
@ -358,6 +392,8 @@ def main():
|
|||
record['region'] = rset.region
|
||||
record['failover'] = rset.failover
|
||||
record['health_check'] = rset.health_check
|
||||
if hosted_zone_id_in:
|
||||
record['hosted_zone_id'] = hosted_zone_id_in
|
||||
if rset.alias_dns_name:
|
||||
record['alias'] = True
|
||||
record['value'] = rset.alias_dns_name
|
||||
|
|
Loading…
Reference in a new issue