From 047516c7671a3a1b394ffff7f4c0363f7f43e5b4 Mon Sep 17 00:00:00 2001 From: Mandar Kulkarni Date: Wed, 13 Apr 2022 15:23:07 -0700 Subject: [PATCH] ec2_asg_lifecycle_hook: Add check_mode support (#1060) ec2_asg_lifecycle_hook: Add check_mode support SUMMARY Add check_mode support to ec2_asg_lifecycle_hook. ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_asg_lifecycle_hook Reviewed-by: Markus Bergholz Reviewed-by: Joseph Torcasso --- ec2_asg_lifecycle_hook.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ec2_asg_lifecycle_hook.py b/ec2_asg_lifecycle_hook.py index 713a147872f..351bba5b84d 100644 --- a/ec2_asg_lifecycle_hook.py +++ b/ec2_asg_lifecycle_hook.py @@ -185,6 +185,8 @@ def create_lifecycle_hook(connection, module): if not existing_hook: try: + if module.check_mode: + module.exit_json(changed=True, msg="Would have created AutoScalingGroup Lifecycle Hook if not in check_mode.") return_object['changed'] = True connection.put_lifecycle_hook(**lch_params) return_object['lifecycle_hook_info'] = connection.describe_lifecycle_hooks( @@ -196,6 +198,8 @@ def create_lifecycle_hook(connection, module): added, removed, modified, same = dict_compare(lch_params, existing_hook[0]) if modified: try: + if module.check_mode: + module.exit_json(changed=True, msg="Would have modified AutoScalingGroup Lifecycle Hook if not in check_mode.") return_object['changed'] = True connection.put_lifecycle_hook(**lch_params) return_object['lifecycle_hook_info'] = connection.describe_lifecycle_hooks( @@ -245,6 +249,8 @@ def delete_lifecycle_hook(connection, module): } try: + if module.check_mode: + module.exit_json(changed=True, msg="Would have deleted AutoScalingGroup Lifecycle Hook if not in check_mode.") connection.delete_lifecycle_hook(**lch_params) return_object['changed'] = True return_object['lifecycle_hook_removed'] = {'LifecycleHookName': lch_name, 'AutoScalingGroupName': asg_name} @@ -269,8 +275,12 @@ def main(): state=dict(default='present', choices=['present', 'absent']) ) - module = AnsibleAWSModule(argument_spec=argument_spec, - required_if=[['state', 'present', ['transition']]]) + module = AnsibleAWSModule( + argument_spec=argument_spec, + supports_check_mode=True, + required_if=[['state', 'present', ['transition']]], + ) + state = module.params.get('state') connection = module.client('autoscaling')