From d80ab5b2edacefb558ba74404a98d92590ecdcba Mon Sep 17 00:00:00 2001 From: rbobrowicz Date: Tue, 6 Sep 2022 05:10:38 -0600 Subject: [PATCH] Fix deprecation warning on instance_type (#983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix deprecation warning on instance_type SUMMARY Specifying instance_type should not be required unless count or exact_count are specified. If the user is just trying to start/stop instances then we don't need to ask for size. Fixes #980 ISSUE TYPE Bugfix Pull Request COMPONENT NAME ec2_instance ADDITIONAL INFORMATION Reviewed-by: Gonéri Le Bouder Reviewed-by: Alina Buzachis Reviewed-by: Brian Scholer --- .../fragments/980-instance-type-deprecation-warning.yml | 2 ++ plugins/modules/ec2_instance.py | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 changelogs/fragments/980-instance-type-deprecation-warning.yml diff --git a/changelogs/fragments/980-instance-type-deprecation-warning.yml b/changelogs/fragments/980-instance-type-deprecation-warning.yml new file mode 100644 index 00000000000..d9965871727 --- /dev/null +++ b/changelogs/fragments/980-instance-type-deprecation-warning.yml @@ -0,0 +1,2 @@ +bugfixes: +- ec2_instance - Only show the deprecation warning for the default value of ``instance_type`` when ``count`` or ``exact_count`` are specified (https://github.com//issues/980). diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 230a93fda65..2125ab5a42a 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -2050,9 +2050,11 @@ def main(): supports_check_mode=True ) - 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') + if not module.params.get('instance_type') and not module.params.get('launch_template'): + if module.params.get('state') not in ('absent', 'stopped'): + if module.params.get('count') or module.params.get('exact_count'): + 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') result = dict() if module.params.get('network'):