Skip to content

Commit

Permalink
add changelog file
Browse files Browse the repository at this point in the history
  • Loading branch information
abikouo committed Oct 15, 2024
1 parent 4495c26 commit f76958a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 10 deletions.
5 changes: 5 additions & 0 deletions changelogs/fragments/migrate_ec2_vpc_egress_igw.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
major_changes:
- ec2_vpc_egress_igw - The module has been migrated from the ``community.aws`` collection.
Playbooks using the Fully Qualified Collection Name for this module should be
updated to use ``amazon.aws.ec2_vpc_egress_igw`` (https://api.github.com/repos/ansible-collections/amazon.aws/pulls/2327).
7 changes: 3 additions & 4 deletions plugins/modules/ec2_vpc_egress_igw.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@
description: The ID of the Egress Only Internet Gateway or Null.
returned: always
type: str
sample: eigw-0e00cf111ba5bc11e
sample: "eigw-0e00cf111ba5bc11e"
vpc_id:
description: The ID of the VPC to attach or detach gateway from.
returned: always
type: str
sample: vpc-012345678
sample: "vpc-012345678"
tags:
description: Any tags assigned to the internet gateway.
returned: always
Expand All @@ -80,9 +80,8 @@
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import delete_egress_only_internet_gateway
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import describe_egress_only_internet_gateways
from ansible_collections.amazon.aws.plugins.module_utils.ec2 import ensure_ec2_tags
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict

from ansible_collections.amazon.aws.plugins.module_utils.modules import AnsibleAWSModule
from ansible_collections.amazon.aws.plugins.module_utils.tagging import boto3_tag_list_to_ansible_dict


def delete_eigw(module: AnsibleAWSModule, connection, eigw_id: str) -> Dict[str, Union[str, bool]]:
Expand Down
1 change: 1 addition & 0 deletions tests/integration/targets/ec2_vpc_egress_igw/aliases
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cloud/aws
ec2_vpc_egress_igw_info
68 changes: 62 additions & 6 deletions tests/integration/targets/ec2_vpc_egress_igw/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
ignore_errors: true

- name: Assert failure with no parameters
ansible.builtin.assert:
assert:
that:
- result is failed
- 'result.msg == "missing required arguments: vpc_id"'
Expand All @@ -29,7 +29,7 @@
ignore_errors: true

- name: Assert failure with non-existent VPC ID
ansible.builtin.assert:
assert:
that:
- result is failed
- e_msg in result.exception
Expand All @@ -55,10 +55,15 @@
register: vpc_eigw_create_check_mode
check_mode: true

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert module returned changed and the Egress IGW was not created
ansible.builtin.assert:
assert:
that:
- vpc_eigw_create_check_mode is changed
- egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list == []

# # ============================================================
- name: Create egress-only internet gateway (expected changed=true)
Expand All @@ -67,10 +72,15 @@
vpc_id: "{{ vpc_result.vpc.id }}"
register: vpc_eigw_create

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert module returned changed and the Egress IGW was not created
ansible.builtin.assert:
that:
- vpc_eigw_create is changed
- egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list | length == 1

# # ============================================================
- name: Create egress-only internet gateway once again (idempotency)
Expand All @@ -79,25 +89,35 @@
vpc_id: "{{ vpc_result.vpc.id }}"
register: vpc_eigw_create_idempotency

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert module returned changed and the Egress IGW was not created
assert:
ansible.builtin.assert:
that:
- vpc_eigw_create_idempotency is not changed
- vpc_eigw_create_idempotency.gateway_id == vpc_eigw_create.gateway_id
- egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list | length == 1

# # ============================================================
- name: Delete egress-only internet gateway (check_mode)
ec2_vpc_egress_igw:
amazon.aws.ec2_vpc_egress_igw:
state: absent
vpc_id: "{{ vpc_result.vpc.id }}"
register: vpc_eigw_delete_check_mode
check_mode: true

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert module returned changed and the Egress IGW was not created
ansible.builtin.assert:
that:
- vpc_eigw_delete_check_mode is changed
- vpc_eigw_create_idempotency.gateway_id == vpc_eigw_delete_check_mode.gateway_id
- egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list | length == 1

# # ============================================================
- name: Delete egress-only internet gateway once again (idempotency)
Expand All @@ -106,15 +126,20 @@
vpc_id: "{{ vpc_result.vpc.id }}"
register: vpc_eigw_delete

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert module returned changed and the Egress IGW was not created
ansible.builtin.assert:
that:
- vpc_eigw_delete is changed
- vpc_eigw_create_idempotency.gateway_id == vpc_eigw_delete.gateway_id
- egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list == []

# # ============================================================
- name: Delete egress-only internet gateway
ec2_vpc_egress_igw:
amazon.aws.ec2_vpc_egress_igw:
state: absent
vpc_id: "{{ vpc_result.vpc.id }}"
register: vpc_eigw_delete_idempotency
Expand All @@ -134,10 +159,20 @@
VpcId: "{{ vpc_result.vpc.id }}"
register: create_with_tags

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert that the Egress IGW was created with tags
ansible.builtin.assert:
that:
- create_with_tags is changed
- egress_info.tags == resource_tags
vars:
egress_info: "{{ egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list | first }}"
resource_tags:
ResourcePrefix: "{{ resource_prefix }}"
VpcId: "{{ vpc_result.vpc.id }}"

- name: Trying to update tags (no change)
amazon.aws.ec2_vpc_egress_igw:
Expand All @@ -147,10 +182,20 @@
VpcId: "{{ vpc_result.vpc.id }}"
register: update_tags

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert that the Egress IGW was not updated
ansible.builtin.assert:
that:
- update_tags is not changed
- egress_info.tags == resource_tags
vars:
egress_info: "{{ egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list | first }}"
resource_tags:
ResourcePrefix: "{{ resource_prefix }}"
VpcId: "{{ vpc_result.vpc.id }}"

- name: Add tag to existing tags
amazon.aws.ec2_vpc_egress_igw:
Expand All @@ -160,10 +205,21 @@
purge_tags: false
register: add_tag

- name: List all Egress only internet gateway
amazon.aws.ec2_vpc_egress_igw_info:
register: egress_only_igws

- name: Assert that the Egress IGW was created with tags
ansible.builtin.assert:
that:
- add_tag is changed
- egress_info.tags == resource_tags
vars:
egress_info: "{{ egress_only_igws.egress_only_internet_gateways | selectattr('attachments.0.vpc_id', 'equalto', vpc_result.vpc.id) | list | first }}"
resource_tags:
ResourcePrefix: "{{ resource_prefix }}"
VpcId: "{{ vpc_result.vpc.id }}"
Phase: integration

always:
# ============================================================
Expand Down

0 comments on commit f76958a

Please sign in to comment.