Skip to content

Commit

Permalink
ec2_instance don't change termination protection in check mode (ansib…
Browse files Browse the repository at this point in the history
…le-collections#505)

* ec2_instance don't change termination protection in check mode

Fixes: ansible/ansible/issues/67716
Extend termination protection tests

* Set the path for the aws CLI tool - setting ansible_python_interpreter updates the python search path but not the shell search path

* changelog

Co-authored-by: Mark Chappell <[email protected]>
  • Loading branch information
2 people authored and abikouo committed Sep 18, 2023
1 parent 0ffee90 commit 2913b14
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ec2_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,7 @@ def change_instance_state(filters, desired_state, ec2=None):
unchanged = set()
failure_reason = ""

# TODO: better check_moding in here https://github.com/ansible-collections/community.aws/issues/16
for inst in instances:
try:
if desired_state == 'TERMINATED':
Expand Down Expand Up @@ -1588,7 +1589,8 @@ def handle_existing(existing_matches, changed, ec2, state):
)
changes = diff_instance_and_params(existing_matches[0], module.params)
for c in changes:
ec2.modify_instance_attribute(aws_retry=True, **c)
if not module.check_mode:
ec2.modify_instance_attribute(aws_retry=True, **c)
changed |= bool(changes)
changed |= add_or_update_instance_profile(existing_matches[0], module.params.get('instance_role'))
changed |= change_network_attachments(existing_matches[0], module.params, ec2)
Expand Down

0 comments on commit 2913b14

Please sign in to comment.