mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix check mode for adding/removing tags; boto's DryRun is not equivalent to check mode. Fixes #27490
This commit is contained in:
parent
c02deef454
commit
b0efbc5418
1 changed files with 19 additions and 2 deletions
|
@ -127,14 +127,26 @@ def ensure_tags(vpc_conn, resource_id, tags, add_only, check_mode):
|
|||
if cur_tags == 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)
|
||||
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])
|
||||
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)
|
||||
return {'changed': True, 'tags': latest_tags}
|
||||
except EC2ResponseError as e:
|
||||
|
@ -187,6 +199,11 @@ def ensure_igw_present(vpc_conn, vpc_id, tags, check_mode):
|
|||
igw.vpc_id = vpc_id
|
||||
|
||||
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)
|
||||
igw.tags = tags
|
||||
changed = True
|
||||
|
|
Loading…
Reference in a new issue