ansible/test/integration/targets/ec2_instance/tasks/checkmode_tests.yml
Mark Chappell 145b79ef0e ec2_instance test cleanup (#63708)
* ec2_instance/ec2_instance_info : Fixup sanity test errors

* Move ec2_instance integration tests to use aws_defaults

* Search for the AMI instead of hardcoding an AMI

* Make our VPC CIDR variable

* Remove AZ assumptions - no guarantees about specific AZs being available

* Make sure we terminate instances when we're done with them.

* Add a 10 second pause for IAM roles to become available before using them

* Wait on instance changes by default

* Switch out t2 instances for t3 they're cheaper and have more CPU available

* Pull t3.nano instance info a little earlier

* rework vpc_name and vpc_cidr a little

* Mark ec2_instance tests unsupported for now, they take too long
2019-10-21 14:55:44 +02:00

156 lines
5 KiB
YAML

- block:
- name: Make basic instance
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
image_id: "{{ ec2_ami_image }}"
security_groups: "{{ sg.group_id }}"
instance_type: "{{ ec2_instance_type }}"
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
wait: false
register: basic_instance
- name: Make basic instance(check mode)
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison-checkmode"
image_id: "{{ ec2_ami_image }}"
security_groups: "{{ sg.group_id }}"
instance_type: "{{ ec2_instance_type }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
check_mode: yes
- name: fact presented ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: presented_instance_fact
- name: fact checkmode ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison-checkmode"
register: checkmode_instance_fact
- name: Confirm whether the check mode is working normally.
assert:
that:
- "{{ presented_instance_fact.instances | length }} > 0"
- "{{ checkmode_instance_fact.instances | length }} == 0"
- name: Stop instance in check mode.
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
state: stopped
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
check_mode: yes
- name: fact ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: confirm_checkmode_stopinstance_fact
- name: Verify that it was not stopped.
assert:
that:
- '"{{ confirm_checkmode_stopinstance_fact.instances[0].state.name }}" != "stopped"'
- name: Stop instance.
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
state: stopped
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
register: instance_stop
until: not instance_stop.failed
retries: 10
- name: fact stopped ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: confirm_stopinstance_fact
- name: Verify that it was stopped.
assert:
that:
- '"{{ confirm_stopinstance_fact.instances[0].state.name }}" in ["stopped", "stopping"]'
- name: Running instance in check mode.
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
state: running
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
check_mode: yes
- name: fact ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: confirm_checkmode_runninginstance_fact
- name: Verify that it was not running.
assert:
that:
- '"{{ confirm_checkmode_runninginstance_fact.instances[0].state.name }}" != "running"'
- name: Running instance.
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
state: running
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
- name: fact ec2 instance.
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: confirm_runninginstance_fact
- name: Verify that it was running.
assert:
that:
- '"{{ confirm_runninginstance_fact.instances[0].state.name }}" == "running"'
- name: Terminate instance in check mode.
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
state: absent
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
check_mode: yes
- name: fact ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: confirm_checkmode_terminatedinstance_fact
- name: Verify that it was not terminated,
assert:
that:
- '"{{ confirm_checkmode_terminatedinstance_fact.instances[0].state.name }}" != "terminated"'
- name: Terminate instance.
ec2_instance:
name: "{{ resource_prefix }}-checkmode-comparison"
state: absent
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
- name: fact ec2 instance
ec2_instance_info:
filters:
"tag:Name": "{{ resource_prefix }}-checkmode-comparison"
register: confirm_terminatedinstance_fact
- name: Verify that it was terminated,
assert:
that:
- '"{{ confirm_terminatedinstance_fact.instances[0].state.name }}" == "terminated"'
always:
- name: Terminate instance
ec2:
instance_ids: "{{ basic_instance.instance_ids }}"
state: absent
wait: false
register: removed
until: removed is not failed
ignore_errors: yes
retries: 10