Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ec2_instance - deprecate purge_tags=False #849

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1778,11 +1769,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 @@ -1993,8 +1991,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 @@ -2037,6 +2035,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