Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] ec2_instance: ability to change the instance type #1890

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

markuman
Copy link
Member

@markuman markuman commented Nov 30, 2023

SUMMARY

Currently the ec2_instance module ignores changes on instance_type parameter.
Furthermore, changes on instance_type is only possible when the state is stopped.

ISSUE TYPE
  • Bugfix Pull Request
  • Docs Pull Request
  • Feature Pull Request
COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION
---
- hosts: localhost
  tasks:
  - name: new instance
    amazon.aws.ec2_instance:
      name: ansible-one1
      key_name: popnuc
      vpc_subnet_id: subnet-943ad4d8
      instance_type: t4g.nano
      security_group: default
      image_id: "{{ lookup('aws_ssm', '/aws/service/canonical/ubuntu/server-minimal/22.04/stable/current/arm64/hvm/ebs-gp2/ami-id') }}"
      wait: true
    register: bla

  - name: stopp instance
    amazon.aws.ec2_instance:
      name: ansible-one1
      key_name: popnuc
      instance_ids: "{{ bla.instance_ids }}"
      state: stopped
      wait: true

  - name: start different size
    amazon.aws.ec2_instance:
      name: ansible-one1
      key_name: popnuc
      instance_ids: "{{ bla.instance_ids }}"
      state: started
      instance_type: t4g.micro
      wait: true

Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/e7ff648235f2416e9312c9c080cc1ebd

✔️ ansible-galaxy-importer SUCCESS in 5m 37s
✔️ build-ansible-collection SUCCESS in 14m 12s
✔️ ansible-test-splitter SUCCESS in 6m 11s
✔️ integration-amazon.aws-1 SUCCESS in 28m 54s
✔️ integration-amazon.aws-2 SUCCESS in 21m 04s
✔️ integration-amazon.aws-3 SUCCESS in 16m 13s
✔️ integration-amazon.aws-4 SUCCESS in 15m 12s
✔️ integration-amazon.aws-5 SUCCESS in 11m 09s
✔️ integration-amazon.aws-6 SUCCESS in 7m 06s
✔️ integration-amazon.aws-7 SUCCESS in 10m 28s
✔️ integration-amazon.aws-8 SUCCESS in 13m 21s
✔️ integration-amazon.aws-9 SUCCESS in 15m 48s
✔️ integration-amazon.aws-10 SUCCESS in 8m 38s
✔️ integration-amazon.aws-11 SUCCESS in 7m 12s
✔️ integration-amazon.aws-12 SUCCESS in 10m 08s
✔️ integration-amazon.aws-13 SUCCESS in 11m 02s
✔️ integration-amazon.aws-14 SUCCESS in 11m 00s
✔️ integration-amazon.aws-15 SUCCESS in 8m 49s
✔️ integration-amazon.aws-16 SUCCESS in 10m 31s
✔️ integration-amazon.aws-17 SUCCESS in 7m 59s
✔️ integration-amazon.aws-18 SUCCESS in 11m 58s
✔️ integration-amazon.aws-19 SUCCESS in 11m 18s
Skipped 25 jobs

Copy link

github-actions bot commented Dec 1, 2023

Docs Build 📝

Thank you for contribution!✨

The docsite for this PR is available for download as an artifact from this run:
https://github.com/ansible-collections/amazon.aws/actions/runs/7063915464

You can compare to the docs for the main branch here:
https://ansible-collections.github.io/amazon.aws/branch/main

File changes:

  • M collections/amazon/aws/ec2_instance_module.html
Click to see the diff comparison.

NOTE: only file modifications are shown here. New and deleted files are excluded.
See the file list and check the published docs to see those files.

diff --git a/home/runner/work/amazon.aws/amazon.aws/docsbuild/base/collections/amazon/aws/ec2_instance_module.html b/home/runner/work/amazon.aws/amazon.aws/docsbuild/head/collections/amazon/aws/ec2_instance_module.html
index 18ddcd2..362f4b5 100644
--- a/home/runner/work/amazon.aws/amazon.aws/docsbuild/base/collections/amazon/aws/ec2_instance_module.html
+++ b/home/runner/work/amazon.aws/amazon.aws/docsbuild/head/collections/amazon/aws/ec2_instance_module.html
@@ -506,6 +506,7 @@ see <a class="reference internal" href="#ansible-collections-amazon-aws-ec2-inst
 <td><div class="ansible-option-cell"><p>Instance type to use for the instance, see <a class="reference external" href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html</a>.</p>
 <p>Only required when instance is not already present.</p>
 <p>At least one of <em>instance_type</em> or <em>launch_template</em> must be specificed when launching an instance.</p>
+<p>To change the <em>instance_type</em>, the instance must be in <em>state=stopped</em>.</p>
 </div></td>
 </tr>
 <tr class="row-even"><td><div class="ansible-option-cell">

Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/bd885c438884406aa78afa66e57b3bdb

✔️ ansible-galaxy-importer SUCCESS in 8m 51s
✔️ build-ansible-collection SUCCESS in 15m 45s
✔️ ansible-test-splitter SUCCESS in 5m 53s
✔️ integration-amazon.aws-1 SUCCESS in 27m 12s
✔️ integration-amazon.aws-2 SUCCESS in 26m 20s
✔️ integration-amazon.aws-3 SUCCESS in 12m 53s
✔️ integration-amazon.aws-4 SUCCESS in 12m 51s
✔️ integration-amazon.aws-5 SUCCESS in 12m 27s
✔️ integration-amazon.aws-6 SUCCESS in 15m 40s
✔️ integration-amazon.aws-7 SUCCESS in 7m 13s
integration-amazon.aws-8 FAILURE in 20m 14s
✔️ integration-amazon.aws-9 SUCCESS in 13m 53s
✔️ integration-amazon.aws-10 SUCCESS in 15m 24s
✔️ integration-amazon.aws-11 SUCCESS in 8m 57s
✔️ integration-amazon.aws-12 SUCCESS in 14m 40s
✔️ integration-amazon.aws-13 SUCCESS in 11m 52s
✔️ integration-amazon.aws-14 SUCCESS in 13m 25s
✔️ integration-amazon.aws-15 SUCCESS in 10m 37s
✔️ integration-amazon.aws-16 SUCCESS in 18m 24s
✔️ integration-amazon.aws-17 SUCCESS in 9m 23s
integration-amazon.aws-18 RETRY_LIMIT in 1m 47s
✔️ integration-amazon.aws-19 SUCCESS in 17m 49s
Skipped 25 jobs

Copy link
Contributor

Build failed.
https://ansible.softwarefactory-project.io/zuul/buildset/c049cd71255f488eb4439bf8407e25ff

✔️ ansible-galaxy-importer SUCCESS in 5m 02s
✔️ build-ansible-collection SUCCESS in 15m 28s
✔️ ansible-test-splitter SUCCESS in 5m 14s
✔️ integration-amazon.aws-1 SUCCESS in 26m 56s
✔️ integration-amazon.aws-2 SUCCESS in 19m 46s
✔️ integration-amazon.aws-3 SUCCESS in 12m 15s
✔️ integration-amazon.aws-4 SUCCESS in 12m 34s
✔️ integration-amazon.aws-5 SUCCESS in 10m 55s
✔️ integration-amazon.aws-6 SUCCESS in 10m 33s
✔️ integration-amazon.aws-7 SUCCESS in 10m 12s
integration-amazon.aws-8 FAILURE in 15m 38s
✔️ integration-amazon.aws-9 SUCCESS in 13m 46s
✔️ integration-amazon.aws-10 SUCCESS in 13m 58s
✔️ integration-amazon.aws-11 SUCCESS in 8m 29s
integration-amazon.aws-12 RETRY_LIMIT in 6m 44s
✔️ integration-amazon.aws-13 SUCCESS in 11m 07s
✔️ integration-amazon.aws-14 SUCCESS in 13m 32s
✔️ integration-amazon.aws-15 SUCCESS in 9m 37s
✔️ integration-amazon.aws-16 SUCCESS in 10m 03s
✔️ integration-amazon.aws-17 SUCCESS in 8m 51s
✔️ integration-amazon.aws-18 SUCCESS in 8m 30s
✔️ integration-amazon.aws-19 SUCCESS in 11m 42s
✔️ integration-community.aws-1 SUCCESS in 24m 50s
✔️ integration-community.aws-2 SUCCESS in 56m 47s
✔️ integration-community.aws-3 SUCCESS in 24m 20s
✔️ integration-community.aws-4 SUCCESS in 17m 19s
✔️ integration-community.aws-5 SUCCESS in 16m 20s
✔️ integration-community.aws-6 SUCCESS in 13m 45s
✔️ integration-community.aws-7 SUCCESS in 21m 23s
✔️ integration-community.aws-8 SUCCESS in 6m 50s
✔️ integration-community.aws-9 SUCCESS in 14m 42s
✔️ integration-community.aws-10 SUCCESS in 22m 21s
✔️ integration-community.aws-11 SUCCESS in 9m 24s
✔️ integration-community.aws-12 SUCCESS in 10m 12s
✔️ integration-community.aws-13 SUCCESS in 15m 04s
✔️ integration-community.aws-14 SUCCESS in 9m 38s
Skipped 11 jobs

@markuman
Copy link
Member Author

markuman commented Dec 2, 2023

Something weird happens here, while the local integration test succeeds.
The assert for task ec2_instance_cpu_options : start instance as t3.micro is failing.

I'm not sure what happens here.
t3.nano and t3.micro should be allowed https://github.com/mattclay/aws-terminator/blob/8512bb30ce115dc00128ff93cbacb6ab48c606b5/aws/policy/compute.yaml#L27-L28

do you have any ideas @tremble


- name: "start instance as t3.micro"
ec2_instance:
state: stopped
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to not matching the name of the task I suspect this is the cause of the CI failure. state: stopped probably introduces a race condition: since the instance is already in the stopped state there's no actual waiting and the change may not yet be reflected in the fetched instance description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants