-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return order of block devices not guaranteed.
- Loading branch information
Showing
5 changed files
with
218 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/integration/targets/ec2_instance_state_config_updates/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
# defaults file for ec2_instance_state_config_updates | ||
ec2_instance_type: 't3.micro' | ||
ec2_instance_tag_TestId: '{{ resource_prefix }}-state-config-updates' | ||
ec2_instance_type: t3.micro | ||
ec2_instance_tag_TestId: "{{ resource_prefix }}-state-config-updates" |
9 changes: 5 additions & 4 deletions
9
tests/integration/targets/ec2_instance_state_config_updates/meta/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
--- | ||
# this just makes sure they're in the right place | ||
dependencies: | ||
- role: setup_ec2_facts | ||
- role: setup_ec2_instance_env | ||
vars: | ||
ec2_instance_test_name: state_config_updates | ||
- role: setup_ec2_facts | ||
- role: setup_ec2_instance_env | ||
vars: | ||
ec2_instance_test_name: state_config_updates |
233 changes: 120 additions & 113 deletions
233
tests/integration/targets/ec2_instance_state_config_updates/tasks/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,133 +1,140 @@ | ||
--- | ||
# Test that configuration changes, like security groups and instance attributes, | ||
# are updated correctly when the instance has different states, and also when | ||
# changing the state of an instance. | ||
# https://github.com/ansible-collections/community.aws/issues/16 | ||
- module_defaults: | ||
- name: Wrap tests in block to set module defaults | ||
module_defaults: | ||
group/aws: | ||
access_key: "{{ aws_access_key }}" | ||
secret_key: "{{ aws_secret_key }}" | ||
session_token: "{{ security_token | default(omit) }}" | ||
region: "{{ aws_region }}" | ||
block: | ||
- name: "Make instance with sg and termination protection enabled" | ||
ec2_instance: | ||
state: running | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: False | ||
instance_type: "{{ ec2_instance_type }}" | ||
wait: True | ||
register: create_result | ||
- name: Make instance with sg and termination protection enabled | ||
amazon.aws.ec2_instance: | ||
state: running | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: false | ||
instance_type: "{{ ec2_instance_type }}" | ||
wait: true | ||
register: create_result | ||
|
||
- assert: | ||
that: | ||
- create_result is not failed | ||
- create_result.changed | ||
- '"instances" in create_result' | ||
- '"instance_ids" in create_result' | ||
- '"spec" in create_result' | ||
- create_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" | ||
- create_result.spec.DisableApiTermination == False | ||
- name: Verify creation | ||
ansible.builtin.assert: | ||
that: | ||
- create_result is not failed | ||
- create_result.changed | ||
- '"instances" in create_result' | ||
- '"instance_ids" in create_result' | ||
- '"spec" in create_result' | ||
- create_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" | ||
- create_result.spec.DisableApiTermination == False | ||
|
||
- name: "Change sg and termination protection while instance is in state running" | ||
ec2_instance: | ||
state: running | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg2.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: True | ||
instance_type: "{{ ec2_instance_type }}" | ||
register: change_params_result | ||
- name: Change sg and termination protection while instance is in state running | ||
amazon.aws.ec2_instance: | ||
state: running | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg2.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
register: change_params_result | ||
|
||
- assert: | ||
that: | ||
- change_params_result is not failed | ||
- change_params_result.changed | ||
- '"instances" in change_params_result' | ||
- '"instance_ids" in change_params_result' | ||
- '"changes" in change_params_result' | ||
- change_params_result.instances[0].security_groups[0].group_id == "{{ sg2.group_id }}" | ||
- change_params_result.changes[0].DisableApiTermination.Value == True | ||
- change_params_result.changes[1].Groups[0] == "{{ sg2.group_id }}" # TODO fix this to be less fragile | ||
- name: Verify changes | ||
ansible.builtin.assert: | ||
that: | ||
- change_params_result is not failed | ||
- change_params_result.changed | ||
- '"instances" in change_params_result' | ||
- '"instance_ids" in change_params_result' | ||
- '"changes" in change_params_result' | ||
- change_params_result.instances[0].security_groups[0].group_id == "{{ sg2.group_id }}" | ||
- change_params_result.changes[0].DisableApiTermination.Value == True | ||
- change_params_result.changes[1].Groups[0] == "{{ sg2.group_id }}" | ||
|
||
|
||
- name: "Change instance state from running to stopped, and change sg and termination protection" | ||
ec2_instance: | ||
state: stopped | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: False | ||
instance_type: "{{ ec2_instance_type }}" | ||
register: change_state_params_result | ||
- name: Change instance state from running to stopped, and change sg and termination protection | ||
amazon.aws.ec2_instance: | ||
state: stopped | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: false | ||
instance_type: "{{ ec2_instance_type }}" | ||
register: change_state_params_result | ||
|
||
- assert: | ||
that: | ||
- change_state_params_result is not failed | ||
- change_state_params_result.changed | ||
- '"instances" in change_state_params_result' | ||
- '"instance_ids" in change_state_params_result' | ||
- '"changes" in change_state_params_result' | ||
- '"stop_success" in change_state_params_result' | ||
- '"stop_failed" in change_state_params_result' | ||
- change_state_params_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" | ||
- change_state_params_result.changes[0].DisableApiTermination.Value == False | ||
- name: Verify changes | ||
ansible.builtin.assert: | ||
that: | ||
- change_state_params_result is not failed | ||
- change_state_params_result.changed | ||
- '"instances" in change_state_params_result' | ||
- '"instance_ids" in change_state_params_result' | ||
- '"changes" in change_state_params_result' | ||
- '"stop_success" in change_state_params_result' | ||
- '"stop_failed" in change_state_params_result' | ||
- change_state_params_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" | ||
- change_state_params_result.changes[0].DisableApiTermination.Value == False | ||
|
||
- name: "Change sg and termination protection while instance is in state stopped" | ||
ec2_instance: | ||
state: stopped | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg2.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: True | ||
instance_type: "{{ ec2_instance_type }}" | ||
register: change_params_stopped_result | ||
- name: Change sg and termination protection while instance is in state stopped | ||
amazon.aws.ec2_instance: | ||
state: stopped | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg2.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
register: change_params_stopped_result | ||
|
||
- assert: | ||
that: | ||
- change_params_stopped_result is not failed | ||
- change_params_stopped_result.changed | ||
- '"instances" in change_params_stopped_result' | ||
- '"instance_ids" in change_params_stopped_result' | ||
- '"changes" in change_params_stopped_result' | ||
- change_params_stopped_result.instances[0].security_groups[0].group_id == "{{ sg2.group_id }}" | ||
- change_params_stopped_result.changes[0].DisableApiTermination.Value == True | ||
- name: Verify changes | ||
ansible.builtin.assert: | ||
that: | ||
- change_params_stopped_result is not failed | ||
- change_params_stopped_result.changed | ||
- '"instances" in change_params_stopped_result' | ||
- '"instance_ids" in change_params_stopped_result' | ||
- '"changes" in change_params_stopped_result' | ||
- change_params_stopped_result.instances[0].security_groups[0].group_id == "{{ sg2.group_id }}" | ||
- change_params_stopped_result.changes[0].DisableApiTermination.Value == True | ||
|
||
- name: "Change instance state from stopped to running, and change sg and termination protection" | ||
ec2_instance: | ||
state: running | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: False | ||
instance_type: "{{ ec2_instance_type }}" | ||
wait: True | ||
register: change_params_start_result | ||
- name: Change instance state from stopped to running, and change sg and termination protection | ||
amazon.aws.ec2_instance: | ||
state: running | ||
name: "{{ resource_prefix }}-test-state-param-changes" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ ec2_instance_tag_TestId }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
termination_protection: false | ||
instance_type: "{{ ec2_instance_type }}" | ||
wait: true | ||
register: change_params_start_result | ||
|
||
- assert: | ||
that: | ||
- change_params_start_result is not failed | ||
- change_params_start_result.changed | ||
- '"instances" in change_params_start_result' | ||
- '"instance_ids" in change_params_start_result' | ||
- '"changes" in change_params_start_result' | ||
- '"start_success" in change_params_start_result' | ||
- '"start_failed" in change_params_start_result' | ||
- change_params_start_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" | ||
- change_params_start_result.changes[0].DisableApiTermination.Value == False | ||
- name: Verify changes | ||
ansible.builtin.assert: | ||
that: | ||
- change_params_start_result is not failed | ||
- change_params_start_result.changed | ||
- '"instances" in change_params_start_result' | ||
- '"instance_ids" in change_params_start_result' | ||
- '"changes" in change_params_start_result' | ||
- '"start_success" in change_params_start_result' | ||
- '"start_failed" in change_params_start_result' | ||
- change_params_start_result.instances[0].security_groups[0].group_id == "{{ sg.group_id }}" | ||
- change_params_start_result.changes[0].DisableApiTermination.Value == False |
Oops, something went wrong.