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

ec2_instance: Use "vpc_subnet_id" from module.params when subnet_id is missing from network interface #2488

Merged

Conversation

mandar242
Copy link
Contributor

@mandar242 mandar242 commented Jan 28, 2025

SUMMARY

Fixes https://issues.redhat.com/browse/ACA-2123

  • This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below
fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}
  • The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group.
  • The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.
ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_instance

ADDITIONAL INFORMATION

According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0)
Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.

Playbook used for testing/reproducing the issue.

---
- name: EC2 instance
  hosts: localhost
  gather_facts: no
  vars:
    instance_type: "t2.micro"
    subnet_id: "subnet-xxxxxxx"
    region: "ap-northeast-2"
     image_id: "ami-xxxxxxx"
  tasks:
    - name: Create the EC2 instance with proper tags
      amazon.aws.ec2_instance:
        image_id: "{{ image_id }}"
        instance_type: "{{ instance_type }}"
        network:
          assign_public_ip: false
          private_ip_address: "{{ ec2_private_ip | default(omit) }}"
        purge_tags: false
        region: "{{ region }}"
        security_groups: "{{ security_group | default('default') }}"
        tags:
          Owner: mandkulk
          Persistent: False
          Name: xxxxx-test-instance
        vpc_subnet_id: "{{ subnet_id }}"
        wait: true
        state: present
      register: ec2

Copy link
Contributor

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

✔️ ansible-galaxy-importer SUCCESS in 4m 46s
✔️ build-ansible-collection SUCCESS in 10m 16s
✔️ ansible-test-splitter SUCCESS in 3m 51s
✔️ integration-amazon.aws-1 SUCCESS in 23m 35s
✔️ integration-amazon.aws-2 SUCCESS in 17m 46s
✔️ integration-amazon.aws-3 SUCCESS in 7m 33s
✔️ integration-amazon.aws-4 SUCCESS in 13m 01s
✔️ integration-amazon.aws-5 SUCCESS in 14m 01s
✔️ integration-amazon.aws-6 SUCCESS in 8m 48s
✔️ integration-amazon.aws-7 SUCCESS in 5m 21s
✔️ integration-amazon.aws-8 SUCCESS in 7m 15s
✔️ integration-amazon.aws-9 SUCCESS in 14m 18s
✔️ integration-amazon.aws-10 SUCCESS in 7m 52s
✔️ integration-amazon.aws-11 SUCCESS in 8m 50s
✔️ integration-amazon.aws-12 SUCCESS in 9m 00s
✔️ integration-amazon.aws-13 SUCCESS in 13m 23s
✔️ integration-amazon.aws-14 SUCCESS in 11m 01s
✔️ integration-amazon.aws-15 SUCCESS in 11m 27s
✔️ integration-amazon.aws-16 SUCCESS in 7m 10s
✔️ integration-amazon.aws-17 SUCCESS in 7m 13s
✔️ integration-amazon.aws-18 SUCCESS in 6m 21s
✔️ integration-amazon.aws-19 SUCCESS in 6m 43s
✔️ integration-amazon.aws-20 SUCCESS in 8m 21s
✔️ integration-amazon.aws-21 SUCCESS in 6m 25s
✔️ integration-amazon.aws-22 SUCCESS in 13m 01s
Skipped 22 jobs

Copy link
Contributor

@tremble tremble left a comment

Choose a reason for hiding this comment

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

I think this behaviour needs documenting, the whole logic chain around subnets and security groups is messy.

  1. Changelog ;)
  2. in the module documentation it should reference using vpc_subnet_id as a default

Copy link

github-actions bot commented Jan 28, 2025

Docs Build 📝

Thank you for contribution!✨

This PR has been merged and your docs changes will be incorporated when they are next published.

@mandar242 mandar242 requested a review from tremble January 28, 2025 16:52
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
plugins/modules/ec2_instance.py Outdated Show resolved Hide resolved
Copy link
Contributor

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

✔️ ansible-galaxy-importer SUCCESS in 4m 53s
✔️ build-ansible-collection SUCCESS in 11m 39s
✔️ ansible-test-splitter SUCCESS in 5m 18s
✔️ integration-amazon.aws-1 SUCCESS in 22m 38s
✔️ integration-amazon.aws-2 SUCCESS in 19m 15s
✔️ integration-amazon.aws-3 SUCCESS in 8m 57s
✔️ integration-amazon.aws-4 SUCCESS in 15m 34s
✔️ integration-amazon.aws-5 SUCCESS in 13m 47s
✔️ integration-amazon.aws-6 SUCCESS in 7m 09s
✔️ integration-amazon.aws-7 SUCCESS in 8m 51s
✔️ integration-amazon.aws-8 SUCCESS in 6m 45s
✔️ integration-amazon.aws-9 SUCCESS in 8m 30s
✔️ integration-amazon.aws-10 SUCCESS in 9m 45s
✔️ integration-amazon.aws-11 SUCCESS in 6m 23s
✔️ integration-amazon.aws-12 SUCCESS in 10m 44s
✔️ integration-amazon.aws-13 SUCCESS in 10m 13s
✔️ integration-amazon.aws-14 SUCCESS in 6m 30s
✔️ integration-amazon.aws-15 SUCCESS in 10m 46s
✔️ integration-amazon.aws-16 SUCCESS in 6m 11s
✔️ integration-amazon.aws-17 SUCCESS in 9m 19s
✔️ integration-amazon.aws-18 SUCCESS in 9m 15s
✔️ integration-amazon.aws-19 SUCCESS in 8m 41s
✔️ integration-amazon.aws-20 SUCCESS in 8m 43s
✔️ integration-amazon.aws-21 SUCCESS in 8m 43s
✔️ integration-amazon.aws-22 SUCCESS in 12m 25s
Skipped 22 jobs

Copy link
Contributor

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

✔️ ansible-galaxy-importer SUCCESS in 11m 51s
✔️ build-ansible-collection SUCCESS in 10m 23s
✔️ ansible-test-splitter SUCCESS in 3m 57s
✔️ integration-amazon.aws-1 SUCCESS in 25m 05s
✔️ integration-amazon.aws-2 SUCCESS in 21m 00s
✔️ integration-amazon.aws-3 SUCCESS in 11m 26s
✔️ integration-amazon.aws-4 SUCCESS in 8m 42s
✔️ integration-amazon.aws-5 SUCCESS in 10m 50s
✔️ integration-amazon.aws-6 SUCCESS in 6m 41s
✔️ integration-amazon.aws-7 SUCCESS in 5m 19s
✔️ integration-amazon.aws-8 SUCCESS in 6m 03s
✔️ integration-amazon.aws-9 SUCCESS in 12m 03s
✔️ integration-amazon.aws-10 SUCCESS in 10m 27s
✔️ integration-amazon.aws-11 SUCCESS in 9m 58s
✔️ integration-amazon.aws-12 SUCCESS in 7m 04s
✔️ integration-amazon.aws-13 SUCCESS in 11m 02s
✔️ integration-amazon.aws-14 SUCCESS in 9m 51s
✔️ integration-amazon.aws-15 SUCCESS in 8m 20s
✔️ integration-amazon.aws-16 SUCCESS in 7m 27s
✔️ integration-amazon.aws-17 SUCCESS in 9m 37s
✔️ integration-amazon.aws-18 SUCCESS in 8m 33s
✔️ integration-amazon.aws-19 SUCCESS in 6m 58s
✔️ integration-amazon.aws-20 SUCCESS in 8m 21s
✔️ integration-amazon.aws-21 SUCCESS in 8m 30s
✔️ integration-amazon.aws-22 SUCCESS in 13m 27s
Skipped 22 jobs

Copy link
Contributor

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

✔️ ansible-galaxy-importer SUCCESS in 5m 24s
✔️ build-ansible-collection SUCCESS in 10m 03s
✔️ ansible-test-splitter SUCCESS in 3m 59s
✔️ integration-amazon.aws-1 SUCCESS in 22m 12s
✔️ integration-amazon.aws-2 SUCCESS in 18m 46s
✔️ integration-amazon.aws-3 SUCCESS in 8m 28s
✔️ integration-amazon.aws-4 SUCCESS in 11m 14s
✔️ integration-amazon.aws-5 SUCCESS in 7m 06s
✔️ integration-amazon.aws-6 SUCCESS in 7m 27s
✔️ integration-amazon.aws-7 SUCCESS in 8m 11s
✔️ integration-amazon.aws-8 SUCCESS in 8m 49s
✔️ integration-amazon.aws-9 SUCCESS in 8m 05s
✔️ integration-amazon.aws-10 SUCCESS in 9m 38s
✔️ integration-amazon.aws-11 SUCCESS in 6m 50s
✔️ integration-amazon.aws-12 SUCCESS in 7m 09s
✔️ integration-amazon.aws-13 SUCCESS in 14m 25s
✔️ integration-amazon.aws-14 SUCCESS in 10m 03s
✔️ integration-amazon.aws-15 SUCCESS in 10m 38s
✔️ integration-amazon.aws-16 SUCCESS in 7m 33s
✔️ integration-amazon.aws-17 SUCCESS in 8m 43s
✔️ integration-amazon.aws-18 SUCCESS in 7m 19s
✔️ integration-amazon.aws-19 SUCCESS in 8m 43s
✔️ integration-amazon.aws-20 SUCCESS in 8m 39s
✔️ integration-amazon.aws-21 SUCCESS in 6m 19s
✔️ integration-amazon.aws-22 SUCCESS in 14m 28s
Skipped 22 jobs

@mandar242 mandar242 added the mergeit Merge the PR (SoftwareFactory) label Jan 29, 2025
@github-actions github-actions bot added backport-9 backport-8 PR should be backported to the stable-8 branch labels Jan 29, 2025
Copy link
Contributor

Build succeeded (gate pipeline).
https://ansible.softwarefactory-project.io/zuul/buildset/c0918200a02b48cc8dc383c725849f1b

✔️ ansible-galaxy-importer SUCCESS in 4m 44s
✔️ build-ansible-collection SUCCESS in 10m 09s
✔️ ansible-test-splitter SUCCESS in 4m 05s
✔️ integration-amazon.aws-1 SUCCESS in 27m 50s
✔️ integration-amazon.aws-2 SUCCESS in 18m 26s
✔️ integration-amazon.aws-3 SUCCESS in 8m 51s
✔️ integration-amazon.aws-4 SUCCESS in 8m 51s
✔️ integration-amazon.aws-5 SUCCESS in 8m 11s
✔️ integration-amazon.aws-6 SUCCESS in 7m 54s
✔️ integration-amazon.aws-7 SUCCESS in 5m 53s
✔️ integration-amazon.aws-8 SUCCESS in 8m 33s
✔️ integration-amazon.aws-9 SUCCESS in 8m 55s
✔️ integration-amazon.aws-10 SUCCESS in 7m 19s
✔️ integration-amazon.aws-11 SUCCESS in 10m 43s
✔️ integration-amazon.aws-12 SUCCESS in 8m 00s
✔️ integration-amazon.aws-13 SUCCESS in 13m 52s
✔️ integration-amazon.aws-14 SUCCESS in 8m 25s
✔️ integration-amazon.aws-15 SUCCESS in 10m 27s
✔️ integration-amazon.aws-16 SUCCESS in 11m 30s
✔️ integration-amazon.aws-17 SUCCESS in 7m 29s
✔️ integration-amazon.aws-18 SUCCESS in 7m 15s
✔️ integration-amazon.aws-19 SUCCESS in 7m 37s
✔️ integration-amazon.aws-20 SUCCESS in 9m 52s
✔️ integration-amazon.aws-21 SUCCESS in 8m 45s
✔️ integration-amazon.aws-22 SUCCESS in 16m 41s
Skipped 22 jobs

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 2fb1661 into ansible-collections:main Jan 29, 2025
49 checks passed
Copy link

patchback bot commented Jan 29, 2025

Backport to stable-8: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 2fb1661 on top of patchback/backports/stable-8/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488

Backporting merged PR #2488 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/amazon.aws.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-8/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488 upstream/stable-8
  4. Now, cherry-pick PR ec2_instance: Use "vpc_subnet_id" from module.params when subnet_id is missing from network interface #2488 contents into that branch:
    $ git cherry-pick -x 2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a
    If it'll yell at you with something like fatal: Commit 2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR ec2_instance: Use "vpc_subnet_id" from module.params when subnet_id is missing from network interface #2488 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-8/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

Copy link

patchback bot commented Jan 29, 2025

Backport to stable-9: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 2fb1661 on top of patchback/backports/stable-9/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488

Backporting merged PR #2488 into main

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/ansible-collections/amazon.aws.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/stable-9/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488 upstream/stable-9
  4. Now, cherry-pick PR ec2_instance: Use "vpc_subnet_id" from module.params when subnet_id is missing from network interface #2488 contents into that branch:
    $ git cherry-pick -x 2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a
    If it'll yell at you with something like fatal: Commit 2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR ec2_instance: Use "vpc_subnet_id" from module.params when subnet_id is missing from network interface #2488 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/stable-9/2fb1661c4fdefdf8c383a5449b55b2cbe34ad71a/pr-2488
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@github-actions github-actions bot added the backport_failed Backport failed, needs review label Jan 29, 2025
mandar242 added a commit to mandar242/amazon.aws that referenced this pull request Jan 29, 2025
…s missing from network interface (ansible-collections#2488)

SUMMARY

Fixes https://issues.redhat.com/browse/ACA-2123

This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below

fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}

The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group.
The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION

According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0)
Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.

Playbook used for testing/reproducing the issue.
---
- name: EC2 instance
  hosts: localhost
  gather_facts: no
  vars:
    instance_type: "t2.micro"
    subnet_id: "subnet-xxxxxxx"
    region: "ap-northeast-2"
     image_id: "ami-xxxxxxx"
  tasks:
    - name: Create the EC2 instance with proper tags
      amazon.aws.ec2_instance:
        image_id: "{{ image_id }}"
        instance_type: "{{ instance_type }}"
        network:
          assign_public_ip: false
          private_ip_address: "{{ ec2_private_ip | default(omit) }}"
        purge_tags: false
        region: "{{ region }}"
        security_groups: "{{ security_group | default('default') }}"
        tags:
          Owner: mandkulk
          Persistent: False
          Name: xxxxx-test-instance
        vpc_subnet_id: "{{ subnet_id }}"
        wait: true
        state: present
      register: ec2

Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 2fb1661)
mandar242 added a commit to mandar242/amazon.aws that referenced this pull request Jan 29, 2025
…s missing from network interface (ansible-collections#2488)

SUMMARY

Fixes https://issues.redhat.com/browse/ACA-2123

This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below

fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}

The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group.
The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.

ISSUE TYPE

Bugfix Pull Request

COMPONENT NAME

ec2_instance
ADDITIONAL INFORMATION

According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0)
Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.

Playbook used for testing/reproducing the issue.
---
- name: EC2 instance
  hosts: localhost
  gather_facts: no
  vars:
    instance_type: "t2.micro"
    subnet_id: "subnet-xxxxxxx"
    region: "ap-northeast-2"
     image_id: "ami-xxxxxxx"
  tasks:
    - name: Create the EC2 instance with proper tags
      amazon.aws.ec2_instance:
        image_id: "{{ image_id }}"
        instance_type: "{{ instance_type }}"
        network:
          assign_public_ip: false
          private_ip_address: "{{ ec2_private_ip | default(omit) }}"
        purge_tags: false
        region: "{{ region }}"
        security_groups: "{{ security_group | default('default') }}"
        tags:
          Owner: mandkulk
          Persistent: False
          Name: xxxxx-test-instance
        vpc_subnet_id: "{{ subnet_id }}"
        wait: true
        state: present
      register: ec2

Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 2fb1661)
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Jan 30, 2025
…s missing from network interface (#2488) (#2491)

Manual backport of #2488
SUMMARY
Fixes https://issues.redhat.com/browse/ACA-2123
This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below
fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}
The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group. The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION
According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0) Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.
Playbook used for testing/reproducing the issue.

name: EC2 instance hosts: localhost gather_facts: no vars: instance_type: "t2.micro" subnet_id: "subnet-xxxxxxx" region: "ap-northeast-2" image_id: "ami-xxxxxxx" tasks:

name: Create the EC2 instance with proper tags amazon.aws.ec2_instance: image_id: "{{ image_id }}" instance_type: "{{ instance_type }}" network: assign_public_ip: false private_ip_address: "{{ ec2_private_ip | default(omit) }}" purge_tags: false region: "{{ region }}" security_groups: "{{ security_group | default('default') }}" tags: Owner: mandkulk Persistent: False Name: xxxxx-test-instance vpc_subnet_id: "{{ subnet_id }}" wait: true state: present register: ec2



Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 2fb1661)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis
Reviewed-by: GomathiselviS <[email protected]>
softwarefactory-project-zuul bot pushed a commit that referenced this pull request Jan 30, 2025
…s missing from network interface (#2488) (#2490)

Manual backport of #2488
SUMMARY
Fixes https://issues.redhat.com/browse/ACA-2123
This PR addresses an issue where module tries to attach all security groups in the region that default SGs for any VPC in the region. Causing error below
fatal: [localhost]: FAILED! => {"boto3_version": "1.34.144", "botocore_version": "1.34.144", "changed": false,
"msg": "Could not apply change {'Groups': ['sg-xxxx', 'sg-yyyy', 'sg-zzzz']} to existing instance.: Failed to modify instance attribute"}
The subnet_id was previously passed as None when not found in the network_interface, causing failures when applying security group. The logic was updated to use module.params.get("vpc_subnet_id") when provided in task, as a fallback, preventing None from being passed to discover_security_groups() and ensuring the correct subnet is used when the default security group is specified.
ISSUE TYPE
Bugfix Pull Request
COMPONENT NAME
ec2_instance
ADDITIONAL INFORMATION
According to jira, the issue was introduced after 8.1.0 onwards (worked fine until and including 8.1.0) Issue was only seen (during testing/reproducing) when network and vpc_subnet_id were both specified in the task.
Playbook used for testing/reproducing the issue.

name: EC2 instance hosts: localhost gather_facts: no vars: instance_type: "t2.micro" subnet_id: "subnet-xxxxxxx" region: "ap-northeast-2" image_id: "ami-xxxxxxx" tasks:

name: Create the EC2 instance with proper tags amazon.aws.ec2_instance: image_id: "{{ image_id }}" instance_type: "{{ instance_type }}" network: assign_public_ip: false private_ip_address: "{{ ec2_private_ip | default(omit) }}" purge_tags: false region: "{{ region }}" security_groups: "{{ security_group | default('default') }}" tags: Owner: mandkulk Persistent: False Name: xxxxx-test-instance vpc_subnet_id: "{{ subnet_id }}" wait: true state: present register: ec2



Reviewed-by: Mark Chappell
Reviewed-by: Alina Buzachis
(cherry picked from commit 2fb1661)
SUMMARY


ISSUE TYPE


Bugfix Pull Request
Docs Pull Request
Feature Pull Request
New Module Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: GomathiselviS <[email protected]>
@GomathiselviS GomathiselviS removed the backport_failed Backport failed, needs review label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8 PR should be backported to the stable-8 branch backport-9 mergeit Merge the PR (SoftwareFactory)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants