From f376814c505a8f84429f2308772c7c51889c0f09 Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Thu, 30 Nov 2023 21:59:02 +0100 Subject: [PATCH 1/5] add --- plugins/modules/ec2_instance.py | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index e9e9efaf145..3f42fe17c47 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -1563,6 +1563,7 @@ def value_wrapper(v): param_mappings = [ ParamMapper("ebs_optimized", "EbsOptimized", "ebsOptimized", value_wrapper), ParamMapper("termination_protection", "DisableApiTermination", "disableApiTermination", value_wrapper), + ParamMapper('instance_type', 'InstanceType', 'instanceType', value_wrapper) # user data is an immutable property # ParamMapper('user_data', 'UserData', 'userData', value_wrapper), ] From 5c2fc101544e41bb09bcdd250c08710ee1bf750c Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Thu, 30 Nov 2023 22:02:26 +0100 Subject: [PATCH 2/5] add --- changelogs/fragments/1890-ec2-instance-change-instance-type.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/1890-ec2-instance-change-instance-type.yml diff --git a/changelogs/fragments/1890-ec2-instance-change-instance-type.yml b/changelogs/fragments/1890-ec2-instance-change-instance-type.yml new file mode 100644 index 00000000000..95ff7561103 --- /dev/null +++ b/changelogs/fragments/1890-ec2-instance-change-instance-type.yml @@ -0,0 +1,2 @@ +minor_changes: + - modules/ec2_instance - add the ability to change the ``instance-type`` (https://github.com/ansible-collections/amazon.aws/pull/1890). \ No newline at end of file From 8082cba52f2d28c3d11f2531a6328fa7d9dffbf6 Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Fri, 1 Dec 2023 10:25:07 +0100 Subject: [PATCH 3/5] add --- .../ec2_instance_cpu_options/tasks/main.yml | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml b/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml index 4aea79c047a..f864cf2adce 100644 --- a/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml +++ b/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml @@ -82,4 +82,61 @@ - name: "Confirm existence of instance id." assert: that: - - "{{ checkmode_instance_fact.instances | length }} == 0" + - checkmode_instance_fact.instances | length == 0 + + - name: "create t3.nano instance" + ec2_instance: + state: running + name: "{{ resource_prefix }}-test-t3nano-latest-t3micro" + image_id: "{{ ec2_ami_id }}" + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}" + instance_type: t3.nano + wait: true + + - name: "fact ec2 instance" + ec2_instance_info: + filters: + "tag:Name": "{{ resource_prefix }}-test-t3nano-latest-t3micro" + register: checkmode_instance_fact + + - name: "Confirm existence of instance id." + assert: + that: + - checkmode_instance_fact.instances | length == 1 + + - name: "stopp instance" + ec2_instance: + state: stopped + name: "{{ resource_prefix }}-test-t3nano-latest-t3micro" + image_id: "{{ ec2_ami_id }}" + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}" + instance_type: t3.nano + wait: true + register: stopped_instance + + - name: "Confirm instance is stopped" + assert: + that: + - stopped_instance.instances[0].msg == 'Instances stopped' + + - name: "start instance as t3.micro" + ec2_instance: + state: stopped + name: "{{ resource_prefix }}-test-t3nano-latest-t3micro" + image_id: "{{ ec2_ami_id }}" + tags: + TestId: "{{ ec2_instance_tag_TestId }}" + vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}" + instance_type: t3.micro + wait: true + register: micro_instance + + - name: "Confirm new instance type" + assert: + that: + - micro_instance.instances[0].instance_type == 't3.micro' + - changes[0].InstanceType.Value == 't3.micro' From c44e686597ebc5b26427071512a086f059f9e55e Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Fri, 1 Dec 2023 10:33:46 +0100 Subject: [PATCH 4/5] try --- plugins/modules/ec2_instance.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/modules/ec2_instance.py b/plugins/modules/ec2_instance.py index 3f42fe17c47..b7d4f0edf53 100644 --- a/plugins/modules/ec2_instance.py +++ b/plugins/modules/ec2_instance.py @@ -55,6 +55,7 @@ - Only required when instance is not already present. - At least one of I(instance_type) or I(launch_template) must be specificed when launching an instance. + - To change the I(instance_type), the instance must be in I(state=stopped). type: str count: description: @@ -1563,7 +1564,7 @@ def value_wrapper(v): param_mappings = [ ParamMapper("ebs_optimized", "EbsOptimized", "ebsOptimized", value_wrapper), ParamMapper("termination_protection", "DisableApiTermination", "disableApiTermination", value_wrapper), - ParamMapper('instance_type', 'InstanceType', 'instanceType', value_wrapper) + ParamMapper('instance_type', 'InstanceType', 'instanceType', value_wrapper), # user data is an immutable property # ParamMapper('user_data', 'UserData', 'userData', value_wrapper), ] From 967f57a1b69b8d2718f7b384bec358ac54c62d2e Mon Sep 17 00:00:00 2001 From: Markus Bergholz Date: Fri, 1 Dec 2023 19:43:51 +0100 Subject: [PATCH 5/5] complete --- .../targets/ec2_instance_cpu_options/tasks/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml b/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml index f864cf2adce..71a41ccbf7c 100644 --- a/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml +++ b/tests/integration/targets/ec2_instance_cpu_options/tasks/main.yml @@ -121,7 +121,7 @@ - name: "Confirm instance is stopped" assert: that: - - stopped_instance.instances[0].msg == 'Instances stopped' + - stopped_instance.msg == 'Instances stopped' - name: "start instance as t3.micro" ec2_instance: @@ -138,5 +138,5 @@ - name: "Confirm new instance type" assert: that: - - micro_instance.instances[0].instance_type == 't3.micro' - - changes[0].InstanceType.Value == 't3.micro' + - micro_instance.instances.0.instance_type == 't3.micro' + - micro_instance.changes[0].InstanceType.Value == 't3.micro' \ No newline at end of file