Skip to content

Commit 52f883d

Browse files
authored
Merge pull request #2428 from ansible-collections/patchback/backports/stable-9/86b9182767c67b32627c3aeafc727ac582bebf21/pr-2391
[PR #2391/86b91827 backport][stable-9] cloudformation: Fix bug when updating stack's termination_protection with create_changeset set
2 parents e0ab101 + f9085ee commit 52f883d

File tree

6 files changed

+225
-79
lines changed

6 files changed

+225
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
bugfixes:
3+
- cloudformation - Fix bug where termination protection is not updated when create_changeset=true is used for stack updates (https://github.com/ansible-collections/amazon.aws/pull/2391).

plugins/modules/cloudformation.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ def update_stack(module, stack_params, cfn, events_limit):
514514

515515
def update_termination_protection(module, cfn, stack_name, desired_termination_protection_state):
516516
"""updates termination protection of a stack"""
517+
changed = False
517518
stack = get_stack_facts(module, cfn, stack_name)
518519
if stack:
519520
if stack["EnableTerminationProtection"] is not desired_termination_protection_state:
@@ -523,8 +524,10 @@ def update_termination_protection(module, cfn, stack_name, desired_termination_p
523524
EnableTerminationProtection=desired_termination_protection_state,
524525
StackName=stack_name,
525526
)
527+
changed = True
526528
except botocore.exceptions.ClientError as e:
527529
module.fail_json_aws(e)
530+
return changed
528531

529532

530533
def stack_operation(module, cfn, stack_name, operation, events_limit, op_token=None):
@@ -779,14 +782,17 @@ def main():
779782
if state == "present":
780783
if not stack_info:
781784
result = create_stack(module, stack_params, cfn, module.params.get("events_limit"))
782-
elif module.params.get("create_changeset"):
783-
result = create_changeset(module, stack_params, cfn, module.params.get("events_limit"))
784785
else:
786+
changeset_updated = False
787+
if module.params.get("create_changeset"):
788+
result = create_changeset(module, stack_params, cfn, module.params.get("events_limit"))
789+
changeset_updated = True
785790
if module.params.get("termination_protection") is not None:
786-
update_termination_protection(
791+
result["changed"] = update_termination_protection(
787792
module, cfn, stack_params["StackName"], bool(module.params.get("termination_protection"))
788793
)
789-
result = update_stack(module, stack_params, cfn, module.params.get("events_limit"))
794+
if not changeset_updated:
795+
result = update_stack(module, stack_params, cfn, module.params.get("events_limit"))
790796

791797
# format the stack output
792798

tests/integration/targets/cloudformation/defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
stack_name: "{{ resource_prefix }}"
33
stack_name_disable_rollback_true: "{{ resource_prefix }}-drb-true"
44
stack_name_disable_rollback_false: "{{ resource_prefix }}-drb-false"
5+
stack_name_update_termination_protection: "{{ resource_prefix }}-update-tp"
56

67
availability_zone: "{{ ec2_availability_zone_names[0] }}"
78

0 commit comments

Comments
 (0)