diff --git a/changelogs/fragments/849-ec2_instance-tagging-deprecate.yml b/changelogs/fragments/849-ec2_instance-tagging-deprecate.yml new file mode 100644 index 00000000000..11212caf3d6 --- /dev/null +++ b/changelogs/fragments/849-ec2_instance-tagging-deprecate.yml @@ -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). diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 81d0e86b087..2bc65d9a729 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -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. @@ -352,6 +342,7 @@ extends_documentation_fragment: - amazon.aws.aws - amazon.aws.ec2 +- amazon.aws.tags.deprecated_purge ''' @@ -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() @@ -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'), @@ -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')