-
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.
ec2_instance : Add hibernation_options and volumes->ebs->encrypted k…
…eys (#972) ec2_instance : Add hibernation_options and volumes->ebs->encrypted keys Signed-off-by: GomathiselviS [email protected] SUMMARY May Fix #969 In order to support Stop-hibernate behavior for an ec2 instance the following keys are added to the ec2_instance module "hibernation_option": true "volumes": [ { "ebs": { "encrypted": true } } ], ISSUE TYPE Bugfix Pull Request Docs Pull Request Feature Pull Request New Module Pull Request COMPONENT NAME ADDITIONAL INFORMATION Reviewed-by: Alina Buzachis <None> Reviewed-by: GomathiselviS <None> Reviewed-by: Mike Graves <[email protected]> Reviewed-by: Gonéri Le Bouder <[email protected]> Reviewed-by: Mark Chappell <None>
- Loading branch information
1 parent
a079a0d
commit 7ca694f
Showing
6 changed files
with
181 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minor_changes: | ||
- ec2_instance - Add hibernation_options and volumes->ebs->encrypted keys to support stop-hibernate instance (https://github.com/ansible-collections/amazon.aws/pull/972). |
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
3 changes: 3 additions & 0 deletions
3
tests/integration/targets/ec2_instance_hibernation_options/aliases
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
cloud/aws | ||
ec2_instance_info | ||
ec2_instance |
4 changes: 4 additions & 0 deletions
4
tests/integration/targets/ec2_instance_hibernation_options/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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
# defaults file for ec2_instance | ||
ec2_instance_type: 't3.micro' | ||
ec2_instance_tag_TestId: '{{ resource_prefix }}-instance-hibernation-options' |
9 changes: 9 additions & 0 deletions
9
tests/integration/targets/ec2_instance_hibernation_options/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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# 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: hibernation_options | ||
- role: setup_botocore_pip | ||
vars: | ||
boto3_version: "1.20.30" |
145 changes: 145 additions & 0 deletions
145
tests/integration/targets/ec2_instance_hibernation_options/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 |
---|---|---|
@@ -0,0 +1,145 @@ | ||
- module_defaults: | ||
group/aws: | ||
aws_access_key: "{{ aws_access_key }}" | ||
aws_secret_key: "{{ aws_secret_key }}" | ||
security_token: "{{ security_token | default(omit) }}" | ||
region: "{{ aws_region }}" | ||
block: | ||
- name: Create instance with hibernation option (check mode) | ||
ec2_instance: | ||
name: "{{ resource_prefix }}-hibernation-options" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ resource_prefix }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
hibernation_options: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
volumes: | ||
- device_name: /dev/sda1 | ||
ebs: | ||
delete_on_termination: true | ||
encrypted: true | ||
state: running | ||
wait: yes | ||
check_mode: yes | ||
register: create_instance_check_mode_results | ||
|
||
- name: Check the returned value for the earlier task | ||
assert: | ||
that: | ||
- create_instance_check_mode_results is changed | ||
- create_instance_check_mode_results.spec.HibernationOptions.Configured == True | ||
|
||
- name: Create instance with hibernation config | ||
ec2_instance: | ||
name: "{{ resource_prefix }}-hibernation-options" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ resource_prefix }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
hibernation_options: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
volumes: | ||
- device_name: /dev/sda1 | ||
ebs: | ||
delete_on_termination: true | ||
encrypted: true | ||
state: running | ||
wait: yes | ||
register: create_instance_results | ||
|
||
- set_fact: | ||
instance_id: '{{ create_instance_results.instances[0].instance_id }}' | ||
|
||
- name: Check return values of the create instance task | ||
assert: | ||
that: | ||
- "{{ create_instance_results.instances | length }} > 0" | ||
- "'{{ create_instance_results.instances.0.state.name }}' == 'running'" | ||
- "'{{ create_instance_results.spec.HibernationOptions.Configured }}'" | ||
|
||
- name: Gather information about the instance to get the hibernation status | ||
ec2_instance_info: | ||
filters: | ||
"tag:Name": "{{ resource_prefix }}-hibernation-options" | ||
register: instance_hibernation_status | ||
|
||
- name: Assert hibernation options is true | ||
assert: | ||
that: | ||
- instance_hibernation_status.instances[0].hibernation_options.configured == true | ||
|
||
- name: Create instance with hibernation option (check mode) (idempotent) | ||
ec2_instance: | ||
name: "{{ resource_prefix }}-hibernation-options" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ resource_prefix }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
hibernation_options: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
volumes: | ||
- device_name: /dev/sda1 | ||
ebs: | ||
delete_on_termination: true | ||
encrypted: true | ||
state: running | ||
wait: yes | ||
check_mode: yes | ||
register: create_instance_check_mode_results | ||
|
||
- name: Check the returned value for the earlier task | ||
assert: | ||
that: | ||
- create_instance_check_mode_results is not changed | ||
|
||
- name: Create instance with hibernation options configured (idempotent) | ||
ec2_instance: | ||
name: "{{ resource_prefix }}-hibernation-options" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ resource_prefix }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
hibernation_options: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
volumes: | ||
- device_name: /dev/sda1 | ||
ebs: | ||
delete_on_termination: true | ||
encrypted: true | ||
state: running | ||
wait: yes | ||
register: create_instance_results | ||
|
||
- name: Check return values of the create instance task | ||
assert: | ||
that: | ||
- "{{ not create_instance_results.changed }}" | ||
- "{{ create_instance_results.instances | length }} > 0" | ||
|
||
- name: Create instance with hibernation options configured with unencrypted volume | ||
ec2_instance: | ||
name: "{{ resource_prefix }}-hibernation-options-error" | ||
image_id: "{{ ec2_ami_id }}" | ||
tags: | ||
TestId: "{{ resource_prefix }}" | ||
security_groups: "{{ sg.group_id }}" | ||
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}" | ||
hibernation_options: true | ||
instance_type: "{{ ec2_instance_type }}" | ||
volumes: | ||
- device_name: /dev/sda1 | ||
ebs: | ||
delete_on_termination: true | ||
register: create_instance_results | ||
failed_when: "'Hibernation prerequisites not satisfied' not in create_instance_results.msg" | ||
|
||
- name: Terminate the instance | ||
ec2_instance: | ||
filters: | ||
tag:TestId: "{{ resource_prefix }}" | ||
state: absent |