Skip to content

Commit

Permalink
ec2_instance - deprecate purge_tags=False (#849)
Browse files Browse the repository at this point in the history
ec2_instance - deprecate purge_tags=False

Depends-On: #844
SUMMARY
Deprecate purge_tags=False for ec2_instance
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
plugins/modules/ec2_instance.py
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
  • Loading branch information
tremble authored Jun 1, 2022
1 parent c724c17 commit 37a5812
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/849-ec2_instance-tagging-deprecate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deprecated_features:
- ec2_instance - the current default value of ``False`` for ``purge_tags`` has been deprecated and will be updated in release 5.0.0 to ``True`` (https://github.com/ansible-collections/amazon.aws/pull/849).
36 changes: 21 additions & 15 deletions plugins/modules/ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,6 @@
description:
- Host configuration secret key generated by the Tower job template.
type: str
tags:
description:
- A hash/dictionary of tags to add to the new instance or to add/remove from an existing one.
type: dict
purge_tags:
description:
- Delete any tags not specified in the task that are on the instance.
This means you have to specify all the desired tags on each task affecting an instance.
default: false
type: bool
image:
description:
- An image to use for the instance. The M(amazon.aws.ec2_ami_info) module may be used to retrieve images.
Expand Down Expand Up @@ -352,6 +342,7 @@
extends_documentation_fragment:
- amazon.aws.aws
- amazon.aws.ec2
- amazon.aws.tags.deprecated_purge
'''

Expand Down Expand Up @@ -1789,11 +1780,18 @@ def determine_iam_role(name_or_arn):


def handle_existing(existing_matches, state):
tags = dict(module.params.get('tags') or {})
tags = dict(module.params.get('tags', None))
purge_tags = module.params.get('purge_tags')
name = module.params.get('name')
purge_tags = module.params.get('purge_tags', False)

# Name is a tag rather than a direct parameter, we need to inject 'Name'
# into tags, but since tags isn't explicitly passed we'll treat it not being
# set as purge_tags == False
if name:
tags['Name'] = name
if purge_tags and tags is None:
purge_tags = False
tags = {}
tags.update({'Name': name})

changed = False
all_changes = list()
Expand Down Expand Up @@ -2004,8 +2002,8 @@ def main():
security_group=dict(type='str'),
instance_role=dict(type='str'),
name=dict(type='str'),
tags=dict(type='dict'),
purge_tags=dict(type='bool', default=False),
tags=dict(type='dict', aliases=['resource_tags']),
purge_tags=dict(type='bool'),
filters=dict(type='dict', default=None),
launch_template=dict(type='dict'),
key_name=dict(type='str'),
Expand Down Expand Up @@ -2048,6 +2046,14 @@ def main():
supports_check_mode=True
)

if module.params.get('purge_tags') is None:
module.deprecate(
'The purge_tags parameter currently defaults to False.'
' For consistency across the collection, this default value'
' will change to True in release 5.0.0.',
version='5.0.0', collection_name='amazon.aws')
module.params['purge_tags'] = False

if not module.params.get('instance_type') and not module.params.get('launch_template') and module.params.get('state') != 'absent':
module.deprecate("Default value instance_type has been deprecated, in the future you must set an instance_type or a launch_template",
date='2023-01-01', collection_name='amazon.aws')
Expand Down

0 comments on commit 37a5812

Please sign in to comment.