1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

ec2_vpc_endpoint: make policy_path usable (#31801)

The current code flow precludes the use of the policy_path module
parameter that's documented.  It's actually called policy_file in the
code.

What's worse is that the policy_file branch actually tries to open the
file named by the policy parameter, even though policy and policy_file
are marked as mutually-exclusive.

This change fixes the logic bug in policy_file and updates the
documentation to reference policy_file.  The old parameter policy_path
is provided as an alias
This commit is contained in:
Michael Fenn 2017-10-17 14:34:29 -04:00 committed by Ryan Brown
parent efec43dd1e
commit eab9ca9a00

View file

@ -39,7 +39,7 @@ options:
- Option when creating an endpoint. If not provided AWS will - Option when creating an endpoint. If not provided AWS will
utilise a default policy which provides full access to the service. utilise a default policy which provides full access to the service.
required: false required: false
policy_path: policy_file:
description: description:
- The path to the properly json formatted policy file, see - The path to the properly json formatted policy file, see
U(https://github.com/ansible/ansible/issues/7005#issuecomment-42894813) U(https://github.com/ansible/ansible/issues/7005#issuecomment-42894813)
@ -47,6 +47,7 @@ options:
- Option when creating an endpoint. If not provided AWS will - Option when creating an endpoint. If not provided AWS will
utilise a default policy which provides full access to the service. utilise a default policy which provides full access to the service.
required: false required: false
aliases: [ "policy_path" ]
state: state:
description: description:
- present to ensure resource is created. - present to ensure resource is created.
@ -262,7 +263,7 @@ def create_vpc_endpoint(client, module):
elif module.params.get('policy_file'): elif module.params.get('policy_file'):
try: try:
with open(module.params.get('policy'), 'r') as json_data: with open(module.params.get('policy_file'), 'r') as json_data:
policy = json.load(json_data) policy = json.load(json_data)
except Exception as e: except Exception as e:
module.fail_json(msg=str(e), exception=traceback.format_exc(), module.fail_json(msg=str(e), exception=traceback.format_exc(),
@ -330,7 +331,7 @@ def main():
vpc_id=dict(), vpc_id=dict(),
service=dict(), service=dict(),
policy=dict(type='json'), policy=dict(type='json'),
policy_file=dict(type='path'), policy_file=dict(type='path', aliases=['policy_path']),
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
wait=dict(type='bool', default=False), wait=dict(type='bool', default=False),
wait_timeout=dict(type='int', default=320, required=False), wait_timeout=dict(type='int', default=320, required=False),