Skip to content

Commit

Permalink
ec2_asg_lifecycle_hook: Add check_mode support (ansible-collections#1060
Browse files Browse the repository at this point in the history
)

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 <[email protected]>
Reviewed-by: Joseph Torcasso <None>
  • Loading branch information
mandar242 authored and abikouo committed Sep 18, 2023
1 parent fdda10f commit 047516c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions ec2_asg_lifecycle_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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}
Expand All @@ -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')
Expand Down

0 comments on commit 047516c

Please sign in to comment.