Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mandar242 authored and hakbailey committed Sep 1, 2023
1 parent 4c5afff commit 5aafc37
Showing 1 changed file with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,78 @@
- "stack_info.cloudformation | length == 1"
- "stack_info.cloudformation[stack_name].stack_description.disable_rollback == false"

# =============================================================================================
# Test Scenario
# 1. create a cloudformation stack
# 2. try update, FAILED by providing wrong ami id (disable_rollback=true, do not delete failed stack)
# 3. Fix the ami id, retry update, fails as disable_rollback=False
# 4. Try (3) with disable_rollback=true, update completes
# =============================================================================================

- name: Create a cloudformation stack
amazon.aws.cloudformation:
stack_name: "{{ stack_name }}-failtest"
state: present
template_body: "{{ lookup('file','cf_template.json') }}"
disable_rollback: false
template_parameters:
InstanceType: "t3.nano"
ImageId: "{{ ec2_ami_id }}"
SubnetId: "{{ testing_subnet.subnet.id }}"
register: cf_stack
ignore_errors: true

- name: Update the cloudformation stack with wrong ami (fails, does not delete failed as disable_rollback=true)
amazon.aws.cloudformation:
stack_name: "{{ stack_name }}-failtest"
state: present
template_body: "{{ lookup('file','cf_template.json') }}"
disable_rollback: true
template_parameters:
InstanceType: "t3.nano"
ImageId: "{{ ec2_ami_id }}1" # wrong ami provided
SubnetId: "{{ testing_subnet.subnet.id }}"
register: cf_stack
ignore_errors: true

# update stack by correcting AMI ID
- name: Fix the AMI ID and retry updating the cloudformation stack (fails with disable_rollback=false)
amazon.aws.cloudformation:
stack_name: "{{ stack_name }}-failtest"
state: present
template_body: "{{ lookup('file','cf_template.json') }}"
disable_rollback: false
template_parameters:
InstanceType: "t3.nano"
ImageId: "{{ ec2_ami_id }}"
SubnetId: "{{ testing_subnet.subnet.id }}"
register: cf_stack
ignore_errors: true

- name: Fix the AMI ID and retry updating the cloudformation stack (passes with disable_rollback=true)
amazon.aws.cloudformation:
stack_name: "{{ stack_name }}-failtest"
state: present
template_body: "{{ lookup('file','cf_template.json') }}"
disable_rollback: true
template_parameters:
InstanceType: "t3.nano"
ImageId: "{{ ec2_ami_id }}"
SubnetId: "{{ testing_subnet.subnet.id }}"
register: cf_stack

- name: get stack details
cloudformation_info:
stack_name: "{{ stack_name }}-failtest"
register: stack_info

- name: Assert that update was successful
assert:
that:
- cf_stack.changed
- cf_stack.output == "Stack UPDATE complete"
- stack_info.cloudformation["{{ stack_name }}-failtest"].stack_description.stack_status == "UPDATE_COMPLETE"

always:

- name: delete stack
Expand All @@ -142,4 +214,5 @@
with_items:
- "{{ stack_name_disable_rollback_true }}"
- "{{ stack_name_disable_rollback_false }}"
- "{{ stack_name }}-failtest"
- "{{ stack_name }}"

0 comments on commit 5aafc37

Please sign in to comment.