-
Notifications
You must be signed in to change notification settings - Fork 341
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 the possibility to upgrade/downgrade instance type o…
…n the fly (#2298) SUMMARY Closes #469 Add the possibiliy to upgrade/downgrade instance type on existing ec2 instances. The module will stop the instance, modify the instance and then ensure the instance is in the expected state set in state argument. ISSUE TYPE Feature Pull Request COMPONENT NAME ec2_instance Reviewed-by: Alina Buzachis Reviewed-by: GomathiselviS
- Loading branch information
Showing
10 changed files
with
397 additions
and
43 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/fragments/20240917-ec2_instance-upgrade-downgrade-instance-type.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,3 @@ | ||
--- | ||
minor_changes: | ||
- ec2_instance - add the possibility to upgrade / downgrade existing ec2 instance type (https://github.com/ansible-collections/amazon.aws/issues/469). |
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
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
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 @@ | ||
time=15m | ||
cloud/aws | ||
ec2_instance_info | ||
ec2_instance |
3 changes: 3 additions & 0 deletions
3
tests/integration/targets/ec2_instance_type/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,3 @@ | ||
--- | ||
ec2_instance_type_initial: t2.micro | ||
ec2_instance_type_updated: t3.nano |
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 @@ | ||
--- | ||
dependencies: | ||
- role: setup_ec2_facts | ||
- role: setup_ec2_instance_env |
43 changes: 43 additions & 0 deletions
43
tests/integration/targets/ec2_instance_type/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,43 @@ | ||
--- | ||
- module_defaults: | ||
group/aws: | ||
access_key: "{{ aws_access_key }}" | ||
secret_key: "{{ aws_secret_key }}" | ||
session_token: "{{ security_token | default(omit) }}" | ||
region: "{{ aws_region }}" | ||
block: | ||
- include_tasks: single_instance.yml | ||
vars: | ||
ec2_instance_name: "{{ resource_prefix }}-test-instance-type-single" | ||
|
||
- name: "Test update instance type using exact_count" | ||
vars: | ||
ec2_instance_name: "{{ resource_prefix }}-test-instance-type-multiple" | ||
block: | ||
- name: Create multiple ec2 instances | ||
amazon.aws.ec2_instance: | ||
state: present | ||
name: "{{ ec2_instance_name }}" | ||
image_id: "{{ ec2_ami_id }}" | ||
subnet_id: "{{ testing_subnet_a.subnet.id }}" | ||
instance_type: "{{ ec2_instance_type_initial }}" | ||
wait: false | ||
exact_count: 2 | ||
|
||
- name: Test upgrade instance type with various number of instances | ||
include_tasks: update_instance_type.yml | ||
with_items: | ||
- new_instance_type: "{{ ec2_instance_type_updated }}" | ||
new_instance_count: 2 | ||
- new_instance_type: "{{ ec2_instance_type_initial }}" | ||
new_instance_count: 3 | ||
- new_instance_type: "{{ ec2_instance_type_updated }}" | ||
new_instance_count: 2 | ||
|
||
always: | ||
- name: Delete ec2 instances | ||
amazon.aws.ec2_instance: | ||
state: absent | ||
instance_ids: "{{ _instances_info.instances | map(attribute='instance_id') | list }}" | ||
wait: false | ||
when: _instances_info is defined |
Oops, something went wrong.