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

[cloud] ec2_vpc_igw: fix check mode - fixes #27490 (#27637)

Fix check mode for adding/removing tags; boto's DryRun is not equivalent to check mode.

Fixes #27490
This commit is contained in:
Sloane Hertel 2017-08-02 13:47:13 -04:00 committed by Ryan Brown
parent c02deef454
commit b0efbc5418

View file

@ -127,14 +127,26 @@ def ensure_tags(vpc_conn, resource_id, tags, add_only, check_mode):
if cur_tags == tags: if cur_tags == tags:
return {'changed': False, 'tags': cur_tags} return {'changed': False, 'tags': cur_tags}
if check_mode:
latest_check_mode_tags = cur_tags
to_delete = dict((k, cur_tags[k]) for k in cur_tags if k not in tags) to_delete = dict((k, cur_tags[k]) for k in cur_tags if k not in tags)
if to_delete and not add_only: if to_delete and not add_only:
vpc_conn.delete_tags(resource_id, to_delete, dry_run=check_mode) if check_mode:
# just overwriting latest_check_mode_tags instead of deleting keys
latest_check_mode_tags = dict((k, cur_tags[k]) for k in cur_tags if k not in to_delete)
else:
vpc_conn.delete_tags(resource_id, to_delete)
to_add = dict((k, tags[k]) for k in tags if k not in cur_tags or cur_tags[k] != tags[k]) to_add = dict((k, tags[k]) for k in tags if k not in cur_tags or cur_tags[k] != tags[k])
if to_add: if to_add:
vpc_conn.create_tags(resource_id, to_add, dry_run=check_mode) if check_mode:
latest_check_mode_tags.update(to_add)
else:
vpc_conn.create_tags(resource_id, to_add)
if check_mode:
return {'changed': True, 'tags': latest_check_mode_tags}
latest_tags = get_resource_tags(vpc_conn, resource_id) latest_tags = get_resource_tags(vpc_conn, resource_id)
return {'changed': True, 'tags': latest_tags} return {'changed': True, 'tags': latest_tags}
except EC2ResponseError as e: except EC2ResponseError as e:
@ -187,6 +199,11 @@ def ensure_igw_present(vpc_conn, vpc_id, tags, check_mode):
igw.vpc_id = vpc_id igw.vpc_id = vpc_id
if tags != igw.tags: if tags != igw.tags:
if check_mode:
check_mode_tags = ensure_tags(vpc_conn, igw.id, tags, False, check_mode)
igw_info = get_igw_info(igw)
igw_info.get('tags', {}).update(check_mode_tags.get('tags', {}))
return {'changed': True, 'gateway': igw_info}
ensure_tags(vpc_conn, igw.id, tags, False, check_mode) ensure_tags(vpc_conn, igw.id, tags, False, check_mode)
igw.tags = tags igw.tags = tags
changed = True changed = True