Fix argument spec for type and tags; return VGW info instead of raw response

reviewable/pr18780/r1
Brad Davidson 9 years ago
parent 2f56b3c8b4
commit ea8547c86a

@ -40,6 +40,7 @@ options:
description: description:
- type of the virtual gateway to be created - type of the virtual gateway to be created
required: false required: false
choices: [ "ipsec.1" ]
vpn_gateway_id: vpn_gateway_id:
description: description:
- vpn gateway id of an existing virtual gateway - vpn gateway id of an existing virtual gateway
@ -57,6 +58,8 @@ options:
description: description:
- dictionary of resource tags - dictionary of resource tags
required: false required: false
default: null
aliases: [ "resource_tags" ]
author: Nick Aslanidis (@naslanidis) author: Nick Aslanidis (@naslanidis)
extends_documentation_fragment: extends_documentation_fragment:
- aws - aws
@ -120,6 +123,26 @@ try:
except ImportError: except ImportError:
HAS_BOTO3 = False HAS_BOTO3 = False
def get_vgw_info(vgws):
if not isinstance(vgws, list):
return
for vgw in vgws:
vgw_info = {
'id': vgw['VpnGatewayId'],
'type': vgw['Type'],
'state': vgw['State'],
'vpc_id': None,
'tags': dict()
}
for tag in vgw['Tags']:
vgw_info['tags'][tag['Key']] = tag['Value']
if len(vgw['VpcAttachments']) != 0:
vgw_info['vpc_id'] = vgw['VpcAttachments'][0]['VpcId']
return vgw_info
def wait_for_status(client, module, vpn_gateway_id, status): def wait_for_status(client, module, vpn_gateway_id, status):
polling_increment_secs = 15 polling_increment_secs = 15
@ -425,7 +448,7 @@ def ensure_vgw_present(client, module):
changed = True changed = True
vgw = find_vgw(client, module, [vpn_gateway_id]) vgw = find_vgw(client, module, [vpn_gateway_id])
result = vgw result = get_vgw_info(vgw)
return changed, result return changed, result
@ -514,7 +537,7 @@ def ensure_vgw_absent(client, module):
changed = False changed = False
deleted_vgw = None deleted_vgw = None
result = deleted_vgw result = get_vgw_info(deleted_vgw)
return changed, result return changed, result
@ -526,9 +549,9 @@ def main():
name=dict(), name=dict(),
vpn_gateway_id=dict(), vpn_gateway_id=dict(),
vpc_id=dict(), vpc_id=dict(),
wait_timeout=dict(type='int', default=320, required=False), wait_timeout=dict(type='int', default=320),
type=dict(), type=dict(default='ipsec.1', choices=['ipsec.1']),
tags=dict(), tags=dict(default=None, required=False, type='dict', aliases=['resource_tags']),
) )
) )
module = AnsibleModule(argument_spec=argument_spec) module = AnsibleModule(argument_spec=argument_spec)
@ -548,7 +571,7 @@ def main():
(changed, results) = ensure_vgw_present(client, module) (changed, results) = ensure_vgw_present(client, module)
else: else:
(changed, results) = ensure_vgw_absent(client, module) (changed, results) = ensure_vgw_absent(client, module)
module.exit_json(changed=changed, result=results) module.exit_json(changed=changed, vgw=results)
# import module snippets # import module snippets

Loading…
Cancel
Save