add boto3_tag_list_to_ansible_dict to ec2_vpc_peering_facts.py, and parameter checking to ec2_vpc_peer.py (#52307)

* add boto3_tag_list_to_ansible_dict to ec2_vpc_peering_facts.py

* Add parameter checking to ec2_vpc_peer and give helpful error message

* Fixed modules --> module typo in ec2_vpc_peer

* Added required_if logic and fixed incorrect boolean check for absent peering connection

* Changed error message to one of the following is

* Added changelog fragments for ec2_vpc_peer changes

* Changed changelog fragment as per request
This commit is contained in:
Brandon Bui
2019-02-27 01:19:34 -05:00
committed by Will Thames
parent 861446b2a6
commit 1aae196cfa
4 changed files with 24 additions and 2 deletions

View File

@@ -403,11 +403,20 @@ def main():
state=dict(default='present', choices=['present', 'absent', 'accept', 'reject'])
)
)
module = AnsibleModule(argument_spec=argument_spec)
required_if = [
('state', 'present', ['vpc_id', 'peer_vpc_id']),
('state', 'accept', ['peering_id']),
('state', 'reject', ['peering_id'])
]
module = AnsibleModule(argument_spec=argument_spec, required_if=required_if)
if not HAS_BOTO3:
module.fail_json(msg='json, botocore and boto3 are required.')
state = module.params.get('state')
peering_id = module.params.get('peering_id')
vpc_id = module.params.get('vpc_id')
peer_vpc_id = module.params.get('peer_vpc_id')
try:
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
client = boto3_conn(module, conn_type='client', resource='ec2',
@@ -419,6 +428,9 @@ def main():
(changed, results) = create_peer_connection(client, module)
module.exit_json(changed=changed, peering_id=results)
elif state == 'absent':
if not peering_id and (not vpc_id or not peer_vpc_id):
module.fail_json(msg='state is absent but one of the following is missing: peering_id or [vpc_id, peer_vpc_id]')
remove_peer_connection(client, module)
else:
(changed, results) = accept_reject(state, client, module)