diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b647ddb7cd9..1d33db08302 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -63,7 +63,7 @@ jobs: - name: list changes for pull request id: compute - uses: ansible/cloud-content-ci-automation/.github/actions/ansible_test_splitter@0b891487c4170ef856f02313c66cb1c776814c42 + uses: ansible/cloud-content-ci-automation/.github/actions/ansible_test_splitter@6659b608aab58bf1d20641b805eb9cb4fd2b771f with: collections_to_test: "${{ env.source_dir }}" total_jobs: 24 @@ -110,7 +110,7 @@ jobs: - name: Read job targets id: read-targets - uses: ansible/cloud-content-ci-automation/.github/actions/ansible_read_targets@0b891487c4170ef856f02313c66cb1c776814c42 + uses: ansible/cloud-content-ci-automation/.github/actions/ansible_read_targets@6659b608aab58bf1d20641b805eb9cb4fd2b771f with: job_id: "${{ matrix.job-id }}" all_targets: "${{ env.all_targets }}" diff --git a/changelogs/fragments/2457-randomise-test-cidrs.yml b/changelogs/fragments/2457-randomise-test-cidrs.yml new file mode 100644 index 00000000000..57bd937b979 --- /dev/null +++ b/changelogs/fragments/2457-randomise-test-cidrs.yml @@ -0,0 +1,9 @@ +trivial: + - integration tests - add setup_ec2_instance_env and setup_ec2_vpc infrastructure roles from amazon.aws for comprehensive VPC setup/cleanup with ENI handling (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - fix elb_target Lambda state polling and ENI cleanup timing to prevent test failures (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - fix glue_job to use supported Glue versions (4.0, 5.0) instead of deprecated versions (0.9, 2.0) (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - migrate all VPC and subnet CIDR definitions from task files into defaults files for consistency (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - randomise VPC and subnet CIDR allocations across 24 integration tests using pattern ``10.{{ 256 | random(seed=resource_prefix) }}.Y.0/Z`` to prevent collisions when running tests in parallel (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - distribute third octets from 252 down in decrements of 4 (252, 248, 244, ..., 160) mirroring amazon.aws pattern from opposite end of range (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - reduce VPC size from /16 to /22 for more appropriate test environment resource usage (https://github.com/ansible-collections/community.aws/pull/2457). + - integration tests - update ansible_test_splitter to match amazon.aws version with fix for correctly ignoring infrastructure roles in test target detection (https://github.com/ansible-collections/community.aws/pull/2457). diff --git a/tests/integration/targets/autoscaling_complete_lifecycle_action/defaults/main.yml b/tests/integration/targets/autoscaling_complete_lifecycle_action/defaults/main.yml index e656194302a..830335f991f 100644 --- a/tests/integration/targets/autoscaling_complete_lifecycle_action/defaults/main.yml +++ b/tests/integration/targets/autoscaling_complete_lifecycle_action/defaults/main.yml @@ -7,13 +7,13 @@ asg_name: '{{ tiny_prefix }}-{{ resource_sufix }}' vpc_name: '{{ tiny_prefix }}-{{ resource_sufix }}' vpc_seed: '{{ resource_prefix }}' -vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.0.0/16' +vpc_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.252.0/22' rtb_name: '{{ tiny_prefix }}-{{ resource_sufix }}' sg_name: '{{ tiny_prefix }}-{{ resource_sufix }}' lc_name: '{{ tiny_prefix }}-{{ resource_sufix }}' subnet_az: '{{ ec2_availability_zone_names[0] }}' -subnet_cidr: '10.{{ 256 | random(seed=vpc_seed) }}.157.0/24' -subnet_startswith: '10.{{ 256 | random(seed=vpc_seed) }}.157.' +subnet_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_startswith: "{{ (subnet_cidr.split('.')[:3] + ['']) | join('.') }}" subnet_name: '{{ tiny_prefix }}-{{ resource_sufix }}' diff --git a/tests/integration/targets/autoscaling_launch_config/defaults/main.yml b/tests/integration/targets/autoscaling_launch_config/defaults/main.yml index db5c2b6f551..fa0c5cb74d6 100644 --- a/tests/integration/targets/autoscaling_launch_config/defaults/main.yml +++ b/tests/integration/targets/autoscaling_launch_config/defaults/main.yml @@ -4,3 +4,8 @@ ec2_instance_name: '{{ resource_prefix }}-node' ec2_instance_owner: 'integration-run-{{ resource_prefix }}' ec2_instance_type: t2.micro alarm_prefix: "ansible-test" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.248.0/23 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" diff --git a/tests/integration/targets/autoscaling_launch_config/tasks/env_cleanup.yml b/tests/integration/targets/autoscaling_launch_config/tasks/env_cleanup.yml index ce626b69c3d..abbab9ac1d4 100644 --- a/tests/integration/targets/autoscaling_launch_config/tasks/env_cleanup.yml +++ b/tests/integration/targets/autoscaling_launch_config/tasks/env_cleanup.yml @@ -64,7 +64,7 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.0/24 + cidr: "{{ subnet_a_cidr }}" register: removed until: removed is not failed ignore_errors: yes @@ -74,7 +74,7 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.33.0/24 + cidr: "{{ subnet_b_cidr }}" register: removed until: removed is not failed ignore_errors: yes @@ -83,7 +83,7 @@ - name: remove the VPC ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" state: absent tags: Name: Ansible Testing VPC diff --git a/tests/integration/targets/autoscaling_launch_config/tasks/env_setup.yml b/tests/integration/targets/autoscaling_launch_config/tasks/env_setup.yml index d48bae66c83..3a2d882eae4 100644 --- a/tests/integration/targets/autoscaling_launch_config/tasks/env_setup.yml +++ b/tests/integration/targets/autoscaling_launch_config/tasks/env_setup.yml @@ -1,7 +1,7 @@ - name: Create VPC for use in testing ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" tags: Name: Ansible ec2_lc Testing VPC tenancy: default @@ -19,7 +19,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.0/24 + cidr: "{{ subnet_a_cidr }}" az: "{{ aws_region }}a" resource_tags: Name: "{{ resource_prefix }}-subnet-a" @@ -29,7 +29,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.33.0/24 + cidr: "{{ subnet_b_cidr }}" az: "{{ aws_region }}b" resource_tags: Name: "{{ resource_prefix }}-subnet-b" diff --git a/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/defaults/main.yml b/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/defaults/main.yml index 1bbe062afa9..d901d9eb4f6 100644 --- a/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/defaults/main.yml +++ b/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/defaults/main.yml @@ -2,3 +2,7 @@ # defaults file for ec2_asg_lifecycle_hook # Amazon Linux 2 AMI 2019.06.12 (HVM), GP2 Volume Type load_balancer_name: "{{ tiny_prefix }}-lb" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.244.0/24 +subnet_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" diff --git a/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_cleanup.yml b/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_cleanup.yml index 1befe278a54..db5a99b88d8 100644 --- a/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_cleanup.yml +++ b/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_cleanup.yml @@ -107,7 +107,7 @@ amazon.aws.ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.55.77.0/24 + cidr: "{{ subnet_cidr }}" register: removed until: removed is not failed ignore_errors: true @@ -116,7 +116,7 @@ - name: Remove the VPC amazon.aws.ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.55.77.0/24 + cidr_block: "{{ vpc_cidr }}" state: absent register: removed until: removed is not failed diff --git a/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_setup.yml b/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_setup.yml index d516543100b..4906d827239 100644 --- a/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_setup.yml +++ b/tests/integration/targets/autoscaling_lifecycle_hook/roles/ec2_asg_lifecycle_hook/tasks/env_setup.yml @@ -8,7 +8,7 @@ - name: Create VPC for use in testing amazon.aws.ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.55.77.0/24 + cidr_block: "{{ vpc_cidr }}" tenancy: default register: testing_vpc @@ -22,7 +22,7 @@ amazon.aws.ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.55.77.0/24 + cidr: "{{ subnet_cidr }}" az: "{{ aws_region }}a" resource_tags: Name: "{{ resource_prefix }}-subnet" diff --git a/tests/integration/targets/autoscaling_scheduled_action/defaults/main.yml b/tests/integration/targets/autoscaling_scheduled_action/defaults/main.yml index ed97d539c09..9b6a249e444 100644 --- a/tests/integration/targets/autoscaling_scheduled_action/defaults/main.yml +++ b/tests/integration/targets/autoscaling_scheduled_action/defaults/main.yml @@ -1 +1,5 @@ --- + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.240.0/24 +subnet_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" diff --git a/tests/integration/targets/autoscaling_scheduled_action/tasks/main.yml b/tests/integration/targets/autoscaling_scheduled_action/tasks/main.yml index 4c0e97220af..081fb9e9338 100644 --- a/tests/integration/targets/autoscaling_scheduled_action/tasks/main.yml +++ b/tests/integration/targets/autoscaling_scheduled_action/tasks/main.yml @@ -14,7 +14,7 @@ - name: Create VPC for use in testing ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.55.77.0/24 + cidr_block: "{{ vpc_cidr }}" tenancy: default register: testing_vpc @@ -22,7 +22,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.55.77.0/24 + cidr: "{{ vpc_cidr }}" az: "{{ aws_region }}a" resource_tags: Name: "{{ resource_prefix }}-subnet" @@ -318,7 +318,7 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.55.77.0/24 + cidr: "{{ vpc_cidr }}" register: removed until: removed is not failed ignore_errors: yes @@ -327,7 +327,7 @@ - name: Remove the VPC ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.55.77.0/24 + cidr_block: "{{ vpc_cidr }}" state: absent register: removed until: removed is not failed diff --git a/tests/integration/targets/dms_replication_subnet_group/defaults/main.yml b/tests/integration/targets/dms_replication_subnet_group/defaults/main.yml index 2c12e7703d7..779c4cf26c1 100644 --- a/tests/integration/targets/dms_replication_subnet_group/defaults/main.yml +++ b/tests/integration/targets/dms_replication_subnet_group/defaults/main.yml @@ -1,2 +1,7 @@ dms_sg_identifier: "{{ resource_prefix }}-dms" dms_role_role_name: dms-vpc-role + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.236.0/23 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(28, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(28, 1) }}" diff --git a/tests/integration/targets/dms_replication_subnet_group/tasks/main.yml b/tests/integration/targets/dms_replication_subnet_group/tasks/main.yml index 712bc82bed1..aa3026813e5 100644 --- a/tests/integration/targets/dms_replication_subnet_group/tasks/main.yml +++ b/tests/integration/targets/dms_replication_subnet_group/tasks/main.yml @@ -24,7 +24,7 @@ - name: Create VPC for use in testing ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" tags: Name: Ansible ec2_instance Testing VPC tenancy: default @@ -47,7 +47,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.16/28 + cidr: "{{ subnet_a_cidr }}" az: "{{ az_one }}" register: subnet1 @@ -55,7 +55,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.32/28 + cidr: "{{ subnet_b_cidr }}" az: "{{ az_two }}" register: subnet2 @@ -142,20 +142,20 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.16/28 + cidr: "{{ subnet_a_cidr }}" az: "{{ az_one }}" - name: delete subnet2 ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.32/28 + cidr: "{{ subnet_b_cidr }}" az: "{{ az_two }}" - name: delete VPC for use in testing ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" tags: Name: Ansible ec2_instance Testing VPC tenancy: default diff --git a/tests/integration/targets/ecs_cluster/defaults/main.yml b/tests/integration/targets/ecs_cluster/defaults/main.yml index 77a9efb07a0..7a384c79f17 100644 --- a/tests/integration/targets/ecs_cluster/defaults/main.yml +++ b/tests/integration/targets/ecs_cluster/defaults/main.yml @@ -1,4 +1,10 @@ ecs_cluster_name: "{{ resource_prefix }}" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.232.0/22 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" + user_data: | #!/bin/bash echo ECS_CLUSTER={{ ecs_cluster_name }} >> /etc/ecs/ecs.config diff --git a/tests/integration/targets/ecs_cluster/tasks/01_create_requirements.yml b/tests/integration/targets/ecs_cluster/tasks/01_create_requirements.yml index 14c1b6337b7..1d21262c0c0 100644 --- a/tests/integration/targets/ecs_cluster/tasks/01_create_requirements.yml +++ b/tests/integration/targets/ecs_cluster/tasks/01_create_requirements.yml @@ -36,7 +36,7 @@ - name: create a VPC to work in ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: present name: '{{ resource_prefix }}_ecs_cluster' resource_tags: @@ -61,9 +61,9 @@ register: setup_subnet with_items: - zone: a - cidr: 10.0.1.0/24 + cidr: "{{ subnet_a_cidr }}" - zone: b - cidr: 10.0.2.0/24 + cidr: "{{ subnet_b_cidr }}" - name: create an internet gateway so that ECS agents can talk to ECS ec2_vpc_igw: diff --git a/tests/integration/targets/ecs_cluster/tasks/99_terminate_everything.yml b/tests/integration/targets/ecs_cluster/tasks/99_terminate_everything.yml index 55a75c2972d..186183abb1a 100644 --- a/tests/integration/targets/ecs_cluster/tasks/99_terminate_everything.yml +++ b/tests/integration/targets/ecs_cluster/tasks/99_terminate_everything.yml @@ -364,14 +364,14 @@ state: absent with_items: - zone: a - cidr: 10.0.1.0/24 + cidr: "{{ subnet_a_cidr }}" - zone: b - cidr: 10.0.2.0/24 + cidr: "{{ subnet_b_cidr }}" ignore_errors: true - name: remove setup VPC ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: absent name: '{{ resource_prefix }}_ecs_cluster' ignore_errors: true diff --git a/tests/integration/targets/efs/defaults/main.yml b/tests/integration/targets/efs/defaults/main.yml index 11df6135096..c5161d0ca3a 100644 --- a/tests/integration/targets/efs/defaults/main.yml +++ b/tests/integration/targets/efs/defaults/main.yml @@ -1 +1,5 @@ -efs_name: "ansible-test-{{ tiny_prefix }}" \ No newline at end of file +efs_name: "ansible-test-{{ tiny_prefix }}" +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.228.0/23 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" diff --git a/tests/integration/targets/efs/tasks/main.yml b/tests/integration/targets/efs/tasks/main.yml index 407766131ca..75da0fd6304 100644 --- a/tests/integration/targets/efs/tasks/main.yml +++ b/tests/integration/targets/efs/tasks/main.yml @@ -14,7 +14,7 @@ - name: Create VPC for testing ec2_vpc_net: name: "{{ efs_name }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" tags: Name: Ansible ec2_instance Testing VPC tenancy: default @@ -24,7 +24,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.0/24 + cidr: "{{ subnet_a_cidr }}" az: "{{ aws_region }}a" resource_tags: Name: "{{ efs_name }}-subnet-a" @@ -34,7 +34,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.33.0/24 + cidr: "{{ subnet_b_cidr }}" az: "{{ aws_region }}b" resource_tags: Name: "{{ efs_name }}-subnet-b" @@ -589,7 +589,7 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.32.0/24 + cidr: "{{ subnet_a_cidr }}" az: "{{ aws_region }}a" resource_tags: Name: "{{ efs_name }}-subnet-a" @@ -602,7 +602,7 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.22.33.0/24 + cidr: "{{ subnet_b_cidr }}" az: "{{ aws_region }}b" resource_tags: Name: "{{ efs_name }}-subnet-b" @@ -614,7 +614,7 @@ - name: remove the VPC ec2_vpc_net: name: "{{ efs_name }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" state: absent register: removed until: removed is not failed diff --git a/tests/integration/targets/eks_cluster/defaults/main.yml b/tests/integration/targets/eks_cluster/defaults/main.yml index a7f6a40c606..c767438ecc8 100644 --- a/tests/integration/targets/eks_cluster/defaults/main.yml +++ b/tests/integration/targets/eks_cluster/defaults/main.yml @@ -1,12 +1,16 @@ eks_cluster_name: "{{ resource_prefix }}" eks_cluster_short_name: "{{ lookup('password', '/dev/null chars=ascii_lowercase length=5') }}" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.224.0/22 + eks_subnets: - zone: a - cidr: 10.0.1.0/24 + cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" - zone: b - cidr: 10.0.2.0/24 + cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" - zone: c - cidr: 10.0.3.0/24 + cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 2) }}" eks_security_groups: - name: "{{ eks_cluster_name }}-control-plane-sg" diff --git a/tests/integration/targets/eks_cluster/tasks/full_test.yml b/tests/integration/targets/eks_cluster/tasks/full_test.yml index d3f7dfbe6fd..391f94eb3f5 100644 --- a/tests/integration/targets/eks_cluster/tasks/full_test.yml +++ b/tests/integration/targets/eks_cluster/tasks/full_test.yml @@ -44,7 +44,7 @@ - name: create a VPC to work in ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: present name: '{{ resource_prefix }}_aws_eks' resource_tags: @@ -247,7 +247,7 @@ - name: remove setup VPC ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: absent name: '{{ resource_prefix }}_aws_eks' ignore_errors: yes diff --git a/tests/integration/targets/eks_fargate_profile/defaults/main.yaml b/tests/integration/targets/eks_fargate_profile/defaults/main.yaml index 005db76ae04..a50eb4d860c 100644 --- a/tests/integration/targets/eks_fargate_profile/defaults/main.yaml +++ b/tests/integration/targets/eks_fargate_profile/defaults/main.yaml @@ -9,13 +9,16 @@ tags: foo: bar env: test +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.156.0/22 + eks_subnets: - zone: a - cidr: 10.0.1.0/24 + cidr: "10.{{ 256 | random(seed=resource_prefix) }}.156.0/24" type: private tag: internal-elb - zone: b - cidr: 10.0.2.0/24 + cidr: "10.{{ 256 | random(seed=resource_prefix) }}.157.0/24" type: public tag: elb diff --git a/tests/integration/targets/eks_fargate_profile/tasks/cleanup_eks_cluster.yml b/tests/integration/targets/eks_fargate_profile/tasks/cleanup_eks_cluster.yml index 21adb30a8b7..bd5f0d70728 100644 --- a/tests/integration/targets/eks_fargate_profile/tasks/cleanup_eks_cluster.yml +++ b/tests/integration/targets/eks_fargate_profile/tasks/cleanup_eks_cluster.yml @@ -73,7 +73,7 @@ - name: remove setup VPC ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: absent name: '{{ resource_prefix }}_aws_eks' ignore_errors: 'yes' diff --git a/tests/integration/targets/eks_fargate_profile/tasks/create_eks_cluster.yml b/tests/integration/targets/eks_fargate_profile/tasks/create_eks_cluster.yml index 1402ad0a137..0b8f4865c2b 100644 --- a/tests/integration/targets/eks_fargate_profile/tasks/create_eks_cluster.yml +++ b/tests/integration/targets/eks_fargate_profile/tasks/create_eks_cluster.yml @@ -13,7 +13,7 @@ - name: create a VPC to work in ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: present name: '{{ resource_prefix }}_aws_eks' resource_tags: diff --git a/tests/integration/targets/eks_nodegroup/defaults/main.yml b/tests/integration/targets/eks_nodegroup/defaults/main.yml index 26ccce3a4a1..49d9b9201d3 100644 --- a/tests/integration/targets/eks_nodegroup/defaults/main.yml +++ b/tests/integration/targets/eks_nodegroup/defaults/main.yml @@ -2,12 +2,15 @@ eks_cluster_name: "{{ resource_prefix }}" eks_nodegroup_name_a: "ng-template-{{ tiny_prefix }}-a" eks_nodegroup_name_lt: "ng-template-{{ tiny_prefix }}-lt" +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.220.0/22 + eks_subnets: - zone: a - cidr: 10.0.1.0/24 + cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" type: private - zone: b - cidr: 10.0.2.0/24 + cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" type: public eks_nodegroup_ami_type: "AL2_x86_64" diff --git a/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml b/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml index a71bc570d85..82db194b26d 100644 --- a/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml +++ b/tests/integration/targets/eks_nodegroup/tasks/cleanup.yml @@ -77,7 +77,7 @@ - name: remove setup VPC ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: absent name: '{{ resource_prefix }}_aws_eks' ignore_errors: true diff --git a/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml b/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml index 0aeb9faeed0..d39d51b93f0 100644 --- a/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml +++ b/tests/integration/targets/eks_nodegroup/tasks/dependecies.yml @@ -13,7 +13,7 @@ - name: create a VPC to work in ec2_vpc_net: - cidr_block: 10.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: present name: '{{ resource_prefix }}_aws_eks' resource_tags: diff --git a/tests/integration/targets/elasticache/defaults/main.yml b/tests/integration/targets/elasticache/defaults/main.yml index 1e1f60c90bd..c702f8c3be4 100644 --- a/tests/integration/targets/elasticache/defaults/main.yml +++ b/tests/integration/targets/elasticache/defaults/main.yml @@ -2,7 +2,9 @@ vpc_name: "{{ resource_prefix }}-elasticache-test-vpc" vpc_seed: '{{ resource_prefix }}' -vpc_cidr_prefix: '10.{{ 256 | random(seed=vpc_seed) }}' +vpc_cidr: 10.{{ 256 | random(seed=vpc_seed) }}.216.0/22 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" elasticache_redis_sg_name: "{{ resource_prefix }}-elasticache-test-redis-sg" elasticache_redis_test_name: "{{ resource_prefix }}-redis-test" diff --git a/tests/integration/targets/elasticache/tasks/main.yml b/tests/integration/targets/elasticache/tasks/main.yml index 9664a70f14e..9a3902db501 100644 --- a/tests/integration/targets/elasticache/tasks/main.yml +++ b/tests/integration/targets/elasticache/tasks/main.yml @@ -15,14 +15,14 @@ - name: Create VPC to launch Elasticache instances into ec2_vpc_net: name: "{{ vpc_name }}" - cidr_block: "{{ vpc_cidr_prefix }}.0.0/16" + cidr_block: "{{ vpc_cidr }}" state: present register: elasticache_vpc - name: Create subnet 1 in this VPC to launch Elasticache instances into ec2_vpc_subnet: vpc_id: "{{ elasticache_vpc.vpc.id }}" - cidr: "{{ vpc_cidr_prefix }}.1.0/24" + cidr: "{{ subnet_a_cidr }}" state: present register: elasticache_vpc_subnet_1 @@ -72,7 +72,7 @@ - proto: tcp from_port: "{{ elasticache_redis_port }}" to_port: "{{ elasticache_redis_port }}" - cidr_ip: 10.31.0.0/16 + cidr_ip: "{{ vpc_cidr }}" register: elasticache_redis_sg - name: Update Redis Elasticache config with security group (to if changes to existing setup work) @@ -193,7 +193,7 @@ - name: Make sure VPC subnet 1 is deleted again ec2_vpc_subnet: vpc_id: "{{ elasticache_vpc.vpc.id }}" - cidr: "{{ vpc_cidr_prefix }}.1.0/24" + cidr: "{{ subnet_a_cidr }}" state: absent - name: Make sure VPC subnet 2 is deleted again @@ -205,5 +205,5 @@ - name: Make sure VPC is deleted again (only works if subnets were deleted) ec2_vpc_net: name: "{{ vpc_name }}" - cidr_block: "{{ vpc_cidr_prefix }}.0.0/16" + cidr_block: "{{ vpc_cidr }}" state: absent diff --git a/tests/integration/targets/elasticache_subnet_group/defaults/main.yml b/tests/integration/targets/elasticache_subnet_group/defaults/main.yml index ea8921880a9..49f8ae5a146 100644 --- a/tests/integration/targets/elasticache_subnet_group/defaults/main.yml +++ b/tests/integration/targets/elasticache_subnet_group/defaults/main.yml @@ -7,11 +7,11 @@ subnet_name_b: '{{ resource_prefix }}-b' subnet_name_c: '{{ resource_prefix }}-c' subnet_name_d: '{{ resource_prefix }}-d' -vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' -subnet_cidr_a: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24' -subnet_cidr_b: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24' -subnet_cidr_c: '10.{{ 256 | random(seed=resource_prefix) }}.3.0/24' -subnet_cidr_d: '10.{{ 256 | random(seed=resource_prefix) }}.4.0/24' +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.212.0/22' +subnet_cidr_a: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_cidr_b: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" +subnet_cidr_c: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 2) }}" +subnet_cidr_d: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 3) }}" subnet_zone_a: '{{ ec2_availability_zone_names[0] }}' subnet_zone_b: '{{ ec2_availability_zone_names[1] }}' diff --git a/tests/integration/targets/elb_instance/defaults/main.yml b/tests/integration/targets/elb_instance/defaults/main.yml index 25817c110f3..0b62cbbd938 100644 --- a/tests/integration/targets/elb_instance/defaults/main.yml +++ b/tests/integration/targets/elb_instance/defaults/main.yml @@ -4,9 +4,9 @@ elb_name_1: 'ansible-test-{{ tiny_prefix }}-1' elb_name_2: 'ansible-test-{{ tiny_prefix }}-2' -vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' -subnet_cidr_1: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24' -subnet_cidr_2: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24' +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.208.0/22' +subnet_cidr_1: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_cidr_2: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" instance_name_1: 'ansible-test-{{ tiny_prefix }}-elb-instance-1' instance_name_2: 'ansible-test-{{ tiny_prefix }}-elb-instance-2' diff --git a/tests/integration/targets/elb_network_lb/defaults/main.yml b/tests/integration/targets/elb_network_lb/defaults/main.yml index 83e9440412c..07008c1fb5d 100644 --- a/tests/integration/targets/elb_network_lb/defaults/main.yml +++ b/tests/integration/targets/elb_network_lb/defaults/main.yml @@ -5,3 +5,10 @@ nlb_name: "nlb-{{ tiny_prefix }}" tg_name: "nlb-{{ tiny_prefix }}" tg_tcpudp_name: "nlb-tcp-udp-{{ tiny_prefix }}" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.204.0/22 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" +subnet_c_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 2) }}" +subnet_d_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 3) }}" diff --git a/tests/integration/targets/elb_network_lb/tasks/main.yml b/tests/integration/targets/elb_network_lb/tasks/main.yml index e277fffd713..2b0844d857a 100644 --- a/tests/integration/targets/elb_network_lb/tasks/main.yml +++ b/tests/integration/targets/elb_network_lb/tasks/main.yml @@ -14,12 +14,21 @@ - name: create VPC ec2_vpc_net: - cidr_block: 10.228.228.0/22 + cidr_block: "{{ vpc_cidr }}" name: "{{ resource_prefix }}_vpc" ipv6_cidr: true state: present register: vpc + - name: set VPC IPv6 CIDR fact + ansible.builtin.set_fact: + vpc_ipv6_cidr: "{{ vpc.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block }}" + + - name: set IPv6 subnet CIDRs + ansible.builtin.set_fact: + subnet_ipv6_a: '{{ vpc_ipv6_cidr | ansible.utils.ipaddr("0") | ansible.utils.ipsubnet(64, 0) }}' + subnet_ipv6_b: '{{ vpc_ipv6_cidr | ansible.utils.ipaddr("0") | ansible.utils.ipsubnet(64, 1) }}' + - name: create internet gateway ec2_vpc_igw: vpc_id: "{{ vpc.vpc.id }}" @@ -38,10 +47,10 @@ Created_By: "{{ resource_prefix }}" Public: "{{ item.public }}" with_items: - - cidr: 10.228.230.0/24 + - cidr: "{{ subnet_c_cidr }}" az: "a" public: False - - cidr: 10.228.231.0/24 + - cidr: "{{ subnet_d_cidr }}" az: "b" public: False register: subnets @@ -58,14 +67,14 @@ Name: '{{ item.public|ternary(''public'', ''private'') }}-{{ item.az }}' Created_By: "{{ resource_prefix }}" with_items: - - cidr: 10.228.228.0/24 + - cidr: "{{ subnet_a_cidr }}" az: "a" public: True - vpc_ipv6_cidr: "{{ vpc.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block | replace('0::/56','0::/64') }}" - - cidr: 10.228.229.0/24 + vpc_ipv6_cidr: "{{ subnet_ipv6_a }}" + - cidr: "{{ subnet_b_cidr }}" az: "b" public: True - vpc_ipv6_cidr: "{{ vpc.vpc.ipv6_cidr_block_association_set[0].ipv6_cidr_block | replace('0::/56','1::/64') }}" + vpc_ipv6_cidr: "{{ subnet_ipv6_b }}" - ec2_vpc_subnet_info: filters: @@ -101,7 +110,7 @@ cidr_ip: 0.0.0.0/0 - proto: all ports: 80 - cidr_ip: 10.228.228.0/22 + cidr_ip: "{{ vpc_cidr }}" register: sec_group - name: create a target group for testing @@ -206,10 +215,10 @@ delay: 5 until: remove_subnet is success with_items: - - cidr: 10.228.228.0/24 - - cidr: 10.228.229.0/24 - - cidr: 10.228.230.0/24 - - cidr: 10.228.231.0/24 + - cidr: "{{ subnet_a_cidr }}" + - cidr: "{{ subnet_b_cidr }}" + - cidr: "{{ subnet_b_cidr }}" + - cidr: "{{ subnet_c_cidr }}" ignore_errors: yes - name: destroy internet gateway @@ -226,7 +235,7 @@ - name: destroy VPC ec2_vpc_net: - cidr_block: 10.228.228.0/22 + cidr_block: "{{ vpc_cidr }}" name: "{{ resource_prefix }}_vpc" state: absent register: remove_vpc diff --git a/tests/integration/targets/elb_target/defaults/main.yml b/tests/integration/targets/elb_target/defaults/main.yml index 5c21c956c9c..6f97d968708 100644 --- a/tests/integration/targets/elb_target/defaults/main.yml +++ b/tests/integration/targets/elb_target/defaults/main.yml @@ -1,5 +1,12 @@ unique_id: "ansible-test-{{ tiny_prefix }}" +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.200.0/22 + +# IP address for IP-type target group testing +# Uses RFC 1918 private range with randomisation to avoid conflicts +test_target_ip: "192.168.{{ 256 | random(seed=resource_prefix) }}.32" + # Defaults used by the lambda based test lambda_role_name: '{{ unique_id }}-elb-target' diff --git a/tests/integration/targets/elb_target/meta/main.yml b/tests/integration/targets/elb_target/meta/main.yml index fcadd50dc68..a5a3dedfb13 100644 --- a/tests/integration/targets/elb_target/meta/main.yml +++ b/tests/integration/targets/elb_target/meta/main.yml @@ -1,3 +1,5 @@ --- dependencies: - setup_ec2_facts + - setup_ec2_instance_env + - setup_ec2_vpc diff --git a/tests/integration/targets/elb_target/tasks/alb_target.yml b/tests/integration/targets/elb_target/tasks/alb_target.yml index 446b5903159..386233f3b84 100644 --- a/tests/integration/targets/elb_target/tasks/alb_target.yml +++ b/tests/integration/targets/elb_target/tasks/alb_target.yml @@ -1,70 +1,40 @@ --- - name: test elb_target_group with target_type = alb block: - - name: set up testing VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - state: present - cidr_block: 20.0.0.0/16 - tags: - Name: "{{ resource_prefix }}-vpc" - Description: "Created by ansible-test" - register: vpc - - - name: set up testing internet gateway + - name: set up VPC and networking infrastructure + include_role: + name: setup_ec2_instance_env + vars: + ec2_instance_test_name: elb_target_alb + vpc_name: "{{ resource_prefix }}-vpc-alb" + vpc_seed: "{{ resource_prefix }}-elb-target-alb" + + - name: create testing internet gateway ec2_vpc_igw: - vpc_id: "{{ vpc.vpc.id }}" + vpc_id: "{{ testing_vpc.vpc.id }}" state: present register: igw - - name: set up testing subnet - ec2_vpc_subnet: - state: present - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.0.0/18 - az: "{{ aws_region }}a" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: subnet_1 - - - name: set up testing subnet - ec2_vpc_subnet: - state: present - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.64.0/18 - az: "{{ aws_region }}b" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: subnet_2 - - name: create routing rules ec2_vpc_route_table: - vpc_id: "{{ vpc.vpc.id }}" + vpc_id: "{{ testing_vpc.vpc.id }}" tags: created: "{{ resource_prefix }}-route" routes: - dest: 0.0.0.0/0 gateway_id: "{{ igw.gateway_id }}" subnets: - - "{{ subnet_1.subnet.id }}" - - "{{ subnet_2.subnet.id }}" + - "{{ testing_subnet_a.subnet.id }}" + - "{{ testing_subnet_b.subnet.id }}" register: route_table - - name: create testing security group - ec2_security_group: - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ vpc.vpc.id }}" - rules: - - proto: tcp - from_port: 80 - to_port: 80 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 22 - to_port: 22 - cidr_ip: 0.0.0.0/0 - register: sg + # Alias variables for compatibility with existing test code + - name: set compatibility variables + set_fact: + vpc: "{{ testing_vpc }}" + subnet_1: "{{ testing_subnet_a }}" + subnet_2: "{{ testing_subnet_b }}" + # sg is already set by setup_ec2_instance_env - name: set up testing target group for NLB (type=alb) elb_target_group: @@ -154,52 +124,18 @@ until: removed is not failed ignore_errors: true - - name: remove testing subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.0.0/18 - az: "{{ aws_region }}a" - register: removed - retries: 10 - until: removed is not failed + - name: wait for load balancer ENIs to be deleted after LB removal + amazon.aws.ec2_eni_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + description: "ELB*" + register: lb_enis + until: lb_enis.network_interfaces | length == 0 + retries: 60 + delay: 5 ignore_errors: true - - name: remove testing subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.64.0/18 - az: "{{ aws_region }}b" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true - - - name: remove testing security group - ec2_security_group: - state: absent - name: "{{ resource_prefix }}-sg" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true - - - name: remove testing internet gateway - ec2_vpc_igw: - vpc_id: "{{ vpc.vpc.id }}" - state: absent - register: removed - retries: 2 - until: removed is not failed - ignore_errors: true - - - name: remove testing VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - cidr_block: 20.0.0.0/16 - state: absent - register: removed - retries: 2 - until: removed is not failed - ignore_errors: true \ No newline at end of file + - name: cleanup VPC and associated resources + include_role: + name: setup_ec2_instance_env + tasks_from: cleanup \ No newline at end of file diff --git a/tests/integration/targets/elb_target/tasks/ec2_target.yml b/tests/integration/targets/elb_target/tasks/ec2_target.yml index be46031e63f..0ed690ec5f7 100644 --- a/tests/integration/targets/elb_target/tasks/ec2_target.yml +++ b/tests/integration/targets/elb_target/tasks/ec2_target.yml @@ -8,70 +8,41 @@ # ============================================================ - - name: set up testing VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - state: present - cidr_block: 20.0.0.0/16 - tags: - Name: "{{ resource_prefix }}-vpc" - Description: "Created by ansible-test" - register: vpc - - - name: set up testing internet gateway + - name: set up VPC and networking infrastructure + include_role: + name: setup_ec2_instance_env + vars: + ec2_instance_test_name: elb_target + vpc_name: "{{ resource_prefix }}-vpc" + vpc_seed: "{{ resource_prefix }}-elb-target" + + - name: create testing internet gateway ec2_vpc_igw: - vpc_id: "{{ vpc.vpc.id }}" + vpc_id: "{{ testing_vpc.vpc.id }}" state: present register: igw - - name: set up testing subnet - ec2_vpc_subnet: - state: present - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.0.0/18 - az: "{{ aws_region }}a" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: subnet_1 - - - name: set up testing subnet - ec2_vpc_subnet: - state: present - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.64.0/18 - az: "{{ aws_region }}b" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: subnet_2 - - name: create routing rules ec2_vpc_route_table: - vpc_id: "{{ vpc.vpc.id }}" + vpc_id: "{{ testing_vpc.vpc.id }}" tags: created: "{{ resource_prefix }}-route" routes: - dest: 0.0.0.0/0 gateway_id: "{{ igw.gateway_id }}" subnets: - - "{{ subnet_1.subnet.id }}" - - "{{ subnet_2.subnet.id }}" + - "{{ testing_subnet_a.subnet.id }}" + - "{{ testing_subnet_b.subnet.id }}" register: route_table - - name: create testing security group - ec2_security_group: - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ vpc.vpc.id }}" - rules: - - proto: tcp - from_port: 80 - to_port: 80 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 22 - to_port: 22 - cidr_ip: 0.0.0.0/0 - register: sg + # Note: setup_ec2_instance_env already sets sg, sg2, testing_vpc, + # testing_subnet_a, testing_subnet_b - create aliases for compatibility + - name: set compatibility variables + set_fact: + vpc: "{{ testing_vpc }}" + subnet_1: "{{ testing_subnet_a }}" + subnet_2: "{{ testing_subnet_b }}" + # sg is already set by setup_ec2_instance_env - name: set up testing target group (type=instance) elb_target_group: @@ -506,7 +477,7 @@ wait: false modify_targets: true targets: - - Id: 192.168.178.32 + - Id: "{{ test_target_ip }}" Port: 443 AvailabilityZone: all register: result @@ -573,64 +544,20 @@ - "{{ tg_name }}-ip" ignore_errors: true - - name: remove routing rules - ec2_vpc_route_table: - state: absent - lookup: id - route_table_id: "{{ route_table.route_table.id }}" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true - - - name: remove testing subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.0.0/18 - az: "{{ aws_region }}a" - register: removed - retries: 15 - until: removed is not failed - ignore_errors: true - - - name: remove testing subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.64.0/18 - az: "{{ aws_region }}b" - register: removed - retries: 15 - until: removed is not failed - ignore_errors: true - - - name: remove testing security group - ec2_security_group: - state: absent - name: "{{ resource_prefix }}-sg" - register: removed - retries: 15 - until: removed is not failed - ignore_errors: true - - - name: remove testing internet gateway - ec2_vpc_igw: - vpc_id: "{{ vpc.vpc.id }}" - state: absent - register: removed - retries: 10 - until: removed is not failed + - name: wait for load balancer ENIs to be deleted after LB removal + amazon.aws.ec2_eni_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + description: "ELB*" + register: lb_enis + until: lb_enis.network_interfaces | length == 0 + retries: 60 + delay: 5 ignore_errors: true - - name: remove testing VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - cidr_block: 20.0.0.0/16 - state: absent - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true + - name: cleanup VPC and associated resources + include_role: + name: setup_ec2_instance_env + tasks_from: cleanup # ============================================================ diff --git a/tests/integration/targets/elb_target/tasks/etg_protocol_version.yml b/tests/integration/targets/elb_target/tasks/etg_protocol_version.yml index 7d417713189..6056bf212d8 100644 --- a/tests/integration/targets/elb_target/tasks/etg_protocol_version.yml +++ b/tests/integration/targets/elb_target/tasks/etg_protocol_version.yml @@ -7,7 +7,7 @@ ec2_vpc_net: name: "{{ resource_prefix }}-etg-protocol-version-vpc" state: present - cidr_block: 20.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" tags: Name: "{{ resource_prefix }}-etg-protocol-version-vpc" Description: "Created by ansible-test" @@ -63,7 +63,7 @@ - name: remove testing VPC ec2_vpc_net: name: "{{ resource_prefix }}-etg-protocol-version-vpc" - cidr_block: 20.0.0.0/16 + cidr_block: "{{ vpc_cidr }}" state: absent register: removed retries: 10 diff --git a/tests/integration/targets/elb_target/tasks/lambda_target.yml b/tests/integration/targets/elb_target/tasks/lambda_target.yml index 7e6b54cef5d..ed0a5a47840 100644 --- a/tests/integration/targets/elb_target/tasks/lambda_target.yml +++ b/tests/integration/targets/elb_target/tasks/lambda_target.yml @@ -55,6 +55,14 @@ principal: elasticloadbalancing.amazonaws.com source_arn: "{{ elb_target_group.target_group_arn }}" + - name: wait for lambda function to be active + lambda_info: + name: "{{ lambda_name }}" + register: lambda_state + until: lambda_state.functions[0].state == "Active" + retries: 30 + delay: 2 + - name: add lambda to elb target elb_target_group: name: "{{ elb_target_group_name }}" diff --git a/tests/integration/targets/elb_target_info/tasks/main.yml b/tests/integration/targets/elb_target_info/tasks/main.yml index fadce2135e2..fe0e04695a0 100644 --- a/tests/integration/targets/elb_target_info/tasks/main.yml +++ b/tests/integration/targets/elb_target_info/tasks/main.yml @@ -16,70 +16,40 @@ - name: debug: msg="********** Setting up elb_target_info test dependencies **********" - - name: set up testing VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - state: present - cidr_block: 20.0.0.0/16 - tags: - Name: "{{ resource_prefix }}-vpc" - Description: "Created by ansible-test" - register: vpc + - name: set up VPC and networking infrastructure + include_role: + name: setup_ec2_instance_env + vars: + ec2_instance_test_name: elb_target_info + vpc_name: "{{ resource_prefix }}-vpc" + vpc_seed: "{{ resource_prefix }}-elb-target-info" - name: set up testing internet gateway ec2_vpc_igw: - vpc_id: "{{ vpc.vpc.id }}" + vpc_id: "{{ testing_vpc.vpc.id }}" state: present register: igw - - name: set up testing subnet - ec2_vpc_subnet: - state: present - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.0.0/18 - az: "{{ aws_region }}a" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: subnet_1 - - - name: set up testing subnet - ec2_vpc_subnet: - state: present - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.64.0/18 - az: "{{ aws_region }}b" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: subnet_2 - - name: create routing rules ec2_vpc_route_table: - vpc_id: "{{ vpc.vpc.id }}" + vpc_id: "{{ testing_vpc.vpc.id }}" tags: created: "{{ resource_prefix }}-route" routes: - dest: 0.0.0.0/0 gateway_id: "{{ igw.gateway_id }}" subnets: - - "{{ subnet_1.subnet.id }}" - - "{{ subnet_2.subnet.id }}" + - "{{ testing_subnet_a.subnet.id }}" + - "{{ testing_subnet_b.subnet.id }}" register: route_table - - name: create testing security group - ec2_security_group: - name: "{{ resource_prefix }}-sg" - description: a security group for ansible tests - vpc_id: "{{ vpc.vpc.id }}" - rules: - - proto: tcp - from_port: 80 - to_port: 80 - cidr_ip: 0.0.0.0/0 - - proto: tcp - from_port: 22 - to_port: 22 - cidr_ip: 0.0.0.0/0 - register: sg + # Alias variables for compatibility with existing test code + - name: set compatibility variables + set_fact: + vpc: "{{ testing_vpc }}" + subnet_1: "{{ testing_subnet_a }}" + subnet_2: "{{ testing_subnet_b }}" + # sg is already set by setup_ec2_instance_env - name: set up testing target group (type=instance) register: alb_target_group @@ -426,62 +396,20 @@ until: removed is not failed ignore_errors: true - - name: remove routing rules - ec2_vpc_route_table: - state: absent - lookup: id - route_table_id: "{{ route_table.route_table.id }}" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true - - - name: remove testing subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.0.0/18 - az: "{{ aws_region }}a" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true - - - name: remove testing subnet - ec2_vpc_subnet: - state: absent - vpc_id: "{{ vpc.vpc.id }}" - cidr: 20.0.64.0/18 - az: "{{ aws_region }}b" - resource_tags: - Name: "{{ resource_prefix }}-subnet" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: true - - - name: remove testing internet gateway - ec2_vpc_igw: - vpc_id: "{{ vpc.vpc.id }}" - state: absent - register: removed - retries: 10 - until: removed is not failed + - name: wait for load balancer ENIs to be deleted after LB removal + amazon.aws.ec2_eni_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + description: "ELB*" + register: lb_enis + until: lb_enis.network_interfaces | length == 0 + retries: 60 + delay: 5 ignore_errors: true - - name: remove testing VPC - ec2_vpc_net: - name: "{{ resource_prefix }}-vpc" - state: absent - cidr_block: 20.0.0.0/16 - tags: - Name: "{{ resource_prefix }}-vpc" - Description: "Created by ansible-test" - register: removed - retries: 10 - until: removed is not failed - ignore_errors: True + - name: cleanup VPC and associated resources + include_role: + name: setup_ec2_instance_env + tasks_from: cleanup # ============================================================ diff --git a/tests/integration/targets/glue_connection/defaults/main.yml b/tests/integration/targets/glue_connection/defaults/main.yml new file mode 100644 index 00000000000..92ebaf7d74e --- /dev/null +++ b/tests/integration/targets/glue_connection/defaults/main.yml @@ -0,0 +1,4 @@ +--- +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.196.0/23 +subnet_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" diff --git a/tests/integration/targets/glue_connection/tasks/test_connection_network.yml b/tests/integration/targets/glue_connection/tasks/test_connection_network.yml index bc7d5cb4cf9..2494b38ff09 100644 --- a/tests/integration/targets/glue_connection/tasks/test_connection_network.yml +++ b/tests/integration/targets/glue_connection/tasks/test_connection_network.yml @@ -9,7 +9,7 @@ - name: Create VPC ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" tags: Name: Ansible ec2_instance Testing VPC tenancy: default @@ -18,7 +18,7 @@ - name: Create default subnet in zone A ec2_vpc_subnet: az: "{{ aws_region }}a" - cidr: 10.22.32.0/24 + cidr: "{{ subnet_cidr }}" vpc_id: "{{ glue_vpc.vpc.id }}" resource_tags: Name: "{{ resource_prefix }}-subnet-a" @@ -324,7 +324,7 @@ - name: Delete default subnet in zone A ec2_vpc_subnet: az: "{{ aws_region }}a" - cidr: 10.22.32.0/24 + cidr: "{{ subnet_cidr }}" vpc_id: "{{ glue_vpc.vpc.id }}" state: absent register: glue_subnet_a @@ -332,6 +332,6 @@ - name: Delete VPC ec2_vpc_net: name: "{{ resource_prefix }}-vpc" - cidr_block: 10.22.32.0/23 + cidr_block: "{{ vpc_cidr }}" state: absent ignore_errors: true diff --git a/tests/integration/targets/glue_job/tasks/main.yml b/tests/integration/targets/glue_job/tasks/main.yml index ebce89949c2..79ca23b7ac0 100644 --- a/tests/integration/targets/glue_job/tasks/main.yml +++ b/tests/integration/targets/glue_job/tasks/main.yml @@ -36,7 +36,7 @@ default_arguments: "--TempDir": "{{ glue_job_temp_dir }}" description: "{{ glue_job_description }}" - glue_version: "2.0" + glue_version: "4.0" role: "{{ glue_job_role_name }}" tags: Environment: Test @@ -59,7 +59,7 @@ default_arguments: "--TempDir": "{{ glue_job_temp_dir }}" description: "{{ glue_job_description }}" - glue_version: "2.0" + glue_version: "4.0" role: "{{ glue_job_role_name }}" tags: Environment: Test @@ -99,7 +99,7 @@ default_arguments: "--TempDir": "{{ glue_job_temp_dir }}" description: "{{ glue_job_description }}" - glue_version: "2.0" + glue_version: "4.0" role: "{{ glue_job_role_name }}" tags: Environment: Test @@ -141,7 +141,7 @@ default_arguments: "--TempDir": "{{ glue_job_temp_dir }}" description: "{{ glue_job_description }}" - glue_version: "2.0" + glue_version: "4.0" role: "{{ glue_job_role_name }}" tags: Environment: Test @@ -182,7 +182,7 @@ default_arguments: "--TempDir": "{{ glue_job_temp_dir }}subfolder/" description: "{{ glue_job_description }}" - glue_version: "0.9" + glue_version: "5.0" role: "{{ glue_job_role_name }}" tags: Environment: Test @@ -222,7 +222,7 @@ default_arguments: "--TempDir": "{{ glue_job_temp_dir }}subfolder/" description: "{{ glue_job_description }}" - glue_version: "0.9" + glue_version: "5.0" role: "{{ glue_job_role_name }}" tags: Environment: Test diff --git a/tests/integration/targets/mq/defaults/main.yml b/tests/integration/targets/mq/defaults/main.yml index b589d1e1d61..7dd2eadcd10 100644 --- a/tests/integration/targets/mq/defaults/main.yml +++ b/tests/integration/targets/mq/defaults/main.yml @@ -2,8 +2,11 @@ # default files for mq_* broker_name: 'ansible-test-{{ tiny_prefix }}-mq' vpc_name: "{{ resource_prefix }}-vpc" -vpc_cidr: "10.0.0.0/16" -subnet_cidr: "10.0.1.0/24" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: "10.{{ 256 | random(seed=resource_prefix) }}.192.0/22" +subnet_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" + sg_name: "{{resource_prefix}}-sg" tags: workload_type: other \ No newline at end of file diff --git a/tests/integration/targets/msk_cluster-auth/defaults/main.yml b/tests/integration/targets/msk_cluster-auth/defaults/main.yml index 471fdc56398..31c370e0976 100644 --- a/tests/integration/targets/msk_cluster-auth/defaults/main.yml +++ b/tests/integration/targets/msk_cluster-auth/defaults/main.yml @@ -1,9 +1,9 @@ --- vpc_name: "{{ resource_prefix }}-mskc-a" -vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.188.0/22' vpc_subnets: - - '10.{{ 256 | random(seed=resource_prefix) }}.100.0/24' - - '10.{{ 256 | random(seed=resource_prefix) }}.101.0/24' + - "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" + - "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" vpc_subnet_name_prefix: "{{ resource_prefix }}" msk_config_name: "{{ resource_prefix }}-msk-cluster-auth" diff --git a/tests/integration/targets/msk_cluster/defaults/main.yml b/tests/integration/targets/msk_cluster/defaults/main.yml index e8318cd9b6d..b6a3b1efebf 100644 --- a/tests/integration/targets/msk_cluster/defaults/main.yml +++ b/tests/integration/targets/msk_cluster/defaults/main.yml @@ -1,9 +1,9 @@ --- vpc_name: "{{ resource_prefix }}" -vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.184.0/22' vpc_subnets: - - '10.{{ 256 | random(seed=resource_prefix) }}.100.0/24' - - '10.{{ 256 | random(seed=resource_prefix) }}.101.0/24' + - "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" + - "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" vpc_subnet_name_prefix: "{{ resource_prefix }}" msk_config_name: "{{ resource_prefix }}-msk-cluster" diff --git a/tests/integration/targets/networkfirewall/defaults/main.yml b/tests/integration/targets/networkfirewall/defaults/main.yml index d5fe55074a2..dddb7e6f307 100644 --- a/tests/integration/targets/networkfirewall/defaults/main.yml +++ b/tests/integration/targets/networkfirewall/defaults/main.yml @@ -6,20 +6,19 @@ firewall_name_prefix: '{{ _resource_prefix }}' firewall_name: '{{ firewall_name_prefix }}' -cidr_prefix: '10.{{ 255 | random(seed=_resource_prefix) }}' tgw_name: '{{ _resource_prefix }}' tgw_name_2: '{{ _resource_prefix }}-2' vpc_name_a: '{{ _resource_prefix }}-1' vpc_name_b: '{{ _resource_prefix }}-2' -vpc_cidr_a: '{{ cidr_prefix }}.1.0/24' -vpc_cidr_b: '{{ cidr_prefix }}.2.0/24' +vpc_cidr_a: '10.{{ 256 | random(seed=_resource_prefix) }}.156.0/23' +vpc_cidr_b: '10.{{ 256 | random(seed=_resource_prefix) }}.158.0/23' -subnet_cidr_a_1: '{{ cidr_prefix }}.1.0/26' -subnet_cidr_a_2: '{{ cidr_prefix }}.1.64/26' -subnet_cidr_a_3: '{{ cidr_prefix }}.1.128/26' -subnet_cidr_a_1a: '{{ cidr_prefix }}.1.192/26' -subnet_cidr_b_1: '{{ cidr_prefix }}.2.0/26' -subnet_cidr_b_2: '{{ cidr_prefix }}.2.64/26' +subnet_cidr_a_1: "{{ vpc_cidr_a | ansible.utils.ipsubnet(26, 0) }}" +subnet_cidr_a_2: "{{ vpc_cidr_a | ansible.utils.ipsubnet(26, 1) }}" +subnet_cidr_a_3: "{{ vpc_cidr_a | ansible.utils.ipsubnet(26, 2) }}" +subnet_cidr_a_1a: "{{ vpc_cidr_a | ansible.utils.ipsubnet(26, 3) }}" +subnet_cidr_b_1: "{{ vpc_cidr_b | ansible.utils.ipsubnet(26, 0) }}" +subnet_cidr_b_2: "{{ vpc_cidr_b | ansible.utils.ipsubnet(26, 1) }}" subnet_name_a_1: '{{ _resource_prefix }}-a-1' subnet_name_a_1a: '{{ _resource_prefix }}-a-1a' diff --git a/tests/integration/targets/opensearch/defaults/main.yml b/tests/integration/targets/opensearch/defaults/main.yml index da6aef4bb20..2ff719104cf 100644 --- a/tests/integration/targets/opensearch/defaults/main.yml +++ b/tests/integration/targets/opensearch/defaults/main.yml @@ -1,2 +1,5 @@ --- -# defaults file for opensearch tests +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.180.0/22 +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" diff --git a/tests/integration/targets/opensearch/tasks/test_delete_vpc_resources.yml b/tests/integration/targets/opensearch/tasks/test_delete_vpc_resources.yml index b0cfa64343d..26819cbd1e9 100644 --- a/tests/integration/targets/opensearch/tasks/test_delete_vpc_resources.yml +++ b/tests/integration/targets/opensearch/tasks/test_delete_vpc_resources.yml @@ -56,13 +56,13 @@ ec2_vpc_subnet: state: absent vpc_id: "{{ vpc_id }}" - cidr: 10.55.77.0/24 + cidr: "{{ subnet_a_cidr }}" - name: Delete subnet_2 ec2_vpc_subnet: state: absent vpc_id: "{{ vpc_id }}" - cidr: 10.55.78.0/24 + cidr: "{{ subnet_b_cidr }}" - name: Collect info about routing tables ec2_vpc_route_table_info: @@ -87,6 +87,6 @@ - name: Delete VPC for use in testing ec2_vpc_net: name: "{{ vpc_name }}" - cidr_block: 10.55.0.0/16 + cidr_block: "{{ vpc_cidr }}" purge_cidrs: true state: absent diff --git a/tests/integration/targets/opensearch/tasks/test_vpc_setup.yml b/tests/integration/targets/opensearch/tasks/test_vpc_setup.yml index 6e1fec1ab9f..0b691ad0a10 100644 --- a/tests/integration/targets/opensearch/tasks/test_vpc_setup.yml +++ b/tests/integration/targets/opensearch/tasks/test_vpc_setup.yml @@ -4,7 +4,7 @@ ec2_vpc_net: name: "{{ tiny_prefix }}-vpc" state: present - cidr_block: 10.55.0.0/16 + cidr_block: "{{ vpc_cidr }}" tenancy: default tags: AnsibleEIPTest: "{{ tiny_prefix }}-vpc" @@ -49,7 +49,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.55.77.0/24 + cidr: "{{ subnet_a_cidr }}" az: "{{ test_az_zone1 }}" resource_tags: Name: "{{ tiny_prefix }}-subnet_1" @@ -61,7 +61,7 @@ ec2_vpc_subnet: state: present vpc_id: "{{ testing_vpc.vpc.id }}" - cidr: 10.55.78.0/24 + cidr: "{{ subnet_b_cidr }}" az: "{{ test_az_zone2 }}" resource_tags: Name: "{{ tiny_prefix }}-subnet_2" diff --git a/tests/integration/targets/redshift_subnet_group/defaults/main.yml b/tests/integration/targets/redshift_subnet_group/defaults/main.yml index ea8921880a9..9f493572d1e 100644 --- a/tests/integration/targets/redshift_subnet_group/defaults/main.yml +++ b/tests/integration/targets/redshift_subnet_group/defaults/main.yml @@ -7,11 +7,11 @@ subnet_name_b: '{{ resource_prefix }}-b' subnet_name_c: '{{ resource_prefix }}-c' subnet_name_d: '{{ resource_prefix }}-d' -vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.0.0/16' -subnet_cidr_a: '10.{{ 256 | random(seed=resource_prefix) }}.1.0/24' -subnet_cidr_b: '10.{{ 256 | random(seed=resource_prefix) }}.2.0/24' -subnet_cidr_c: '10.{{ 256 | random(seed=resource_prefix) }}.3.0/24' -subnet_cidr_d: '10.{{ 256 | random(seed=resource_prefix) }}.4.0/24' +vpc_cidr: '10.{{ 256 | random(seed=resource_prefix) }}.176.0/22' +subnet_cidr_a: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_cidr_b: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" +subnet_cidr_c: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 2) }}" +subnet_cidr_d: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 3) }}" subnet_zone_a: '{{ ec2_availability_zone_names[0] }}' subnet_zone_b: '{{ ec2_availability_zone_names[1] }}' diff --git a/tests/integration/targets/route53_wait/defaults/main.yml b/tests/integration/targets/route53_wait/defaults/main.yml new file mode 100644 index 00000000000..f9f32c8dffa --- /dev/null +++ b/tests/integration/targets/route53_wait/defaults/main.yml @@ -0,0 +1,5 @@ +--- +# VPC CIDR allocation - randomised to avoid conflicts +# Note: route53_wait previously used 192.0.2.0/24 (TEST-NET-1) +# Changed to randomised 10.x allocation for consistency +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.172.0/24 diff --git a/tests/integration/targets/route53_wait/tasks/main.yml b/tests/integration/targets/route53_wait/tasks/main.yml index f6635e26847..3e5634a1a29 100644 --- a/tests/integration/targets/route53_wait/tasks/main.yml +++ b/tests/integration/targets/route53_wait/tasks/main.yml @@ -19,7 +19,7 @@ block: - name: create VPC ec2_vpc_net: - cidr_block: 192.0.2.0/24 + cidr_block: "{{ vpc_cidr }}" name: '{{ resource_prefix }}_vpc' state: present register: vpc @@ -237,7 +237,7 @@ - name: destroy VPC ec2_vpc_net: - cidr_block: 192.0.2.0/24 + cidr_block: "{{ vpc_cidr }}" name: '{{ resource_prefix }}_vpc' state: absent register: remove_vpc diff --git a/tests/integration/targets/setup_ec2_instance_env/aliases b/tests/integration/targets/setup_ec2_instance_env/aliases new file mode 100644 index 00000000000..136c05e0d02 --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/aliases @@ -0,0 +1 @@ +hidden diff --git a/tests/integration/targets/setup_ec2_instance_env/defaults/main.yml b/tests/integration/targets/setup_ec2_instance_env/defaults/main.yml new file mode 100644 index 00000000000..796cf15a66f --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/defaults/main.yml @@ -0,0 +1,24 @@ +--- +# defaults file for ec2_instance tests +ec2_instance_test_name: ec2_instance + +ec2_instance_owner: integration-run-{{ ec2_instance_test_name }} +ec2_instance_type: t3.micro +ec2_instance_tag_testid: "{{ resource_prefix }}-{{ ec2_instance_test_name }}" + +vpc_name: "{{ resource_prefix }}-{{ ec2_instance_test_name }}" +vpc_seed: "{{ resource_prefix }}-{{ ec2_instance_test_name }}" + +vpc_cidr: 10.{{ 256 | random(seed=vpc_seed) }}.168.0/22 + +subnet_a_az: "{{ ec2_availability_zone_names[0] }}" +subnet_a_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" +subnet_a_startswith: "{{ (subnet_a_cidr.split('.')[:3] + ['']) | join('.') }}" +subnet_a_name: "{{ resource_prefix }}-{{ ec2_instance_test_name }}-a" +subnet_b_az: "{{ ec2_availability_zone_names[1] }}" +subnet_b_cidr: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" +subnet_b_startswith: "{{ (subnet_b_cidr.split('.')[:3] + ['']) | join('.') }}" +subnet_b_name: "{{ resource_prefix }}-{{ ec2_instance_test_name }}-b" + +security_group_name_1: "{{ resource_prefix }}-{{ ec2_instance_test_name }}-1" +security_group_name_2: "{{ resource_prefix }}-{{ ec2_instance_test_name }}-2" diff --git a/tests/integration/targets/setup_ec2_instance_env/handlers/main.yml b/tests/integration/targets/setup_ec2_instance_env/handlers/main.yml new file mode 100644 index 00000000000..9b9fd494006 --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: Delete ec2_instance environment + ansible.builtin.include_tasks: cleanup.yml diff --git a/tests/integration/targets/setup_ec2_instance_env/meta/main.yml b/tests/integration/targets/setup_ec2_instance_env/meta/main.yml new file mode 100644 index 00000000000..23d65c7ef45 --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/meta/main.yml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml b/tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml new file mode 100644 index 00000000000..c2f6cb26a9d --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/tasks/cleanup.yml @@ -0,0 +1,119 @@ +--- +- name: Cleanup common VPC resources + module_defaults: + group/aws: + access_key: "{{ aws_access_key }}" + secret_key: "{{ aws_secret_key }}" + session_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: + - name: (Cleanup) Find all remaining Instances + amazon.aws.ec2_instance_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + instance-state-name: [pending, running, shutting-down, stopping, stopped] + register: instances + + - name: Set termination protection to false (so we can terminate instance) (cleanup) + amazon.aws.ec2_instance: + instance_ids: "{{ item.instance_id }}" + termination_protection: false + ignore_errors: true # noqa: ignore-errors + loop: "{{ instances.instances }}" + + - name: (Cleanup) Remove Instances (start) + amazon.aws.ec2_instance: + state: absent + instance_ids: "{{ item.instance_id }}" + wait: false + ignore_errors: true # noqa: ignore-errors + loop: "{{ instances.instances }}" + + - name: (Cleanup) Remove Instances (wait for completion) + amazon.aws.ec2_instance: + state: absent + instance_ids: "{{ item.instance_id }}" + filters: + instance-state-name: [pending, running, shutting-down, stopping, stopped] + vpc-id: "{{ testing_vpc.vpc.id }}" + wait: true + ignore_errors: true # noqa: ignore-errors + loop: "{{ instances.instances }}" + + - name: (Cleanup) Find all remaining ENIs + amazon.aws.ec2_eni_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + register: enis + + - name: (Cleanup) delete all ENIs + amazon.aws.ec2_eni: + state: absent + eni_id: "{{ item.id }}" + register: eni_removed + until: eni_removed is not failed + with_items: "{{ enis.network_interfaces }}" + ignore_errors: true # noqa: ignore-errors + retries: 10 + + - name: (Cleanup) Find all remaining Security Groups + amazon.aws.ec2_security_group_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + register: security_groups + + - name: (Cleanup) Remove the security group rules + amazon.aws.ec2_security_group: + state: present + name: "{{ item.group_name }}" + description: "{{ item.description }}" + vpc_id: "{{ testing_vpc.vpc.id }}" + rules: [] + egress_rules: [] + loop: "{{ security_groups.security_groups }}" + register: sg_removed + until: sg_removed is not failed + ignore_errors: true # noqa: ignore-errors + retries: 10 + + - name: (Cleanup) Remove the security groups + amazon.aws.ec2_security_group: + state: absent + group_id: "{{ item.group_id }}" + loop: "{{ security_groups.security_groups }}" + when: + - item.group_name != 'default' + register: sg_removed + until: sg_removed is not failed + ignore_errors: true # noqa: ignore-errors + retries: 10 + + - name: (Cleanup) Find all remaining Subnets + amazon.aws.ec2_vpc_subnet_info: + filters: + vpc-id: "{{ testing_vpc.vpc.id }}" + register: subnets + + - name: (Cleanup) Remove subnets + amazon.aws.ec2_vpc_subnet: + state: absent + vpc_id: "{{ testing_vpc.vpc.id }}" + cidr: "{{ item.cidr_block }}" + register: removed + loop: "{{ subnets.subnets }}" + until: removed is not failed + ignore_errors: true # noqa: ignore-errors + retries: 10 + + - name: (Cleanup) Remove the VPC + amazon.aws.ec2_vpc_net: + state: absent + name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr }}" + tags: + Name: Ansible Testing VPC + tenancy: default + register: removed + until: removed is not failed + ignore_errors: true # noqa: ignore-errors + retries: 10 diff --git a/tests/integration/targets/setup_ec2_instance_env/tasks/main.yml b/tests/integration/targets/setup_ec2_instance_env/tasks/main.yml new file mode 100644 index 00000000000..da6f2093256 --- /dev/null +++ b/tests/integration/targets/setup_ec2_instance_env/tasks/main.yml @@ -0,0 +1,96 @@ +--- +- name: Setup common VPC components + run_once: '{{ setup_run_once | default("no") | bool }}' + module_defaults: + group/aws: + access_key: "{{ aws_access_key }}" + secret_key: "{{ aws_secret_key }}" + session_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: + - name: Create VPC for use in testing + amazon.aws.ec2_vpc_net: + state: present + name: "{{ vpc_name }}" + cidr_block: "{{ vpc_cidr }}" + tags: + Name: "{{ vpc_name }}" + tenancy: default + ipv6_cidr: true + register: testing_vpc + notify: + - Delete ec2_instance environment + + - name: Create default subnet in zone A + amazon.aws.ec2_vpc_subnet: + state: present + vpc_id: "{{ testing_vpc.vpc.id }}" + cidr: "{{ subnet_a_cidr }}" + az: "{{ subnet_a_az }}" + resource_tags: + Name: "{{ subnet_a_name }}" + ipv6_cidr: "{{ testing_vpc.vpc.ipv6_cidr_block_association_set.0.ipv6_cidr_block | replace('/56', '/64') }}" + register: testing_subnet_a + + - name: Create secondary subnet in zone B + amazon.aws.ec2_vpc_subnet: + state: present + vpc_id: "{{ testing_vpc.vpc.id }}" + cidr: "{{ subnet_b_cidr }}" + az: "{{ subnet_b_az }}" + resource_tags: + Name: "{{ subnet_b_name }}" + register: testing_subnet_b + + - name: Wait for subnet propagation to settle + ansible.builtin.wait_for: + timeout: 10 + + - name: Create a security group with the vpc + amazon.aws.ec2_security_group: + state: present + name: "{{ security_group_name_1 }}" + description: a security group for ansible tests + vpc_id: "{{ testing_vpc.vpc.id }}" + rules: + - proto: tcp + from_port: 22 + to_port: 22 + cidr_ip: "0.0.0.0/0" + - proto: tcp + from_port: 80 + to_port: 80 + cidr_ip: "0.0.0.0/0" + register: sg + + - name: Create secondary security group with the vpc + amazon.aws.ec2_security_group: + name: "{{ security_group_name_2 }}" + description: a secondary security group for ansible tests + vpc_id: "{{ testing_vpc.vpc.id }}" + rules: + - proto: tcp + from_port: 22 + to_port: 22 + cidr_ip: "0.0.0.0/0" + - proto: tcp + from_port: 80 + to_port: 80 + cidr_ip: "0.0.0.0/0" + register: sg2 + + - name: Preserve defaults for other roles + ansible.builtin.set_fact: + # Ensure variables are available outside of this role + vpc_cidr: "{{ vpc_cidr }}" + vpc_name: "{{ vpc_name }}" + subnet_a_az: "{{ subnet_a_az }}" + subnet_a_cidr: "{{ subnet_a_cidr }}" + subnet_a_startswith: "{{ subnet_a_startswith }}" + subnet_a_name: "{{ subnet_a_name }}" + subnet_b_az: "{{ subnet_b_az }}" + subnet_b_cidr: "{{ subnet_b_cidr }}" + subnet_b_startswith: "{{ subnet_b_startswith }}" + subnet_b_name: "{{ subnet_b_name }}" + security_group_name_1: "{{ security_group_name_1 }}" + security_group_name_2: "{{ security_group_name_2 }}" diff --git a/tests/integration/targets/setup_ec2_vpc/aliases b/tests/integration/targets/setup_ec2_vpc/aliases new file mode 100644 index 00000000000..136c05e0d02 --- /dev/null +++ b/tests/integration/targets/setup_ec2_vpc/aliases @@ -0,0 +1 @@ +hidden diff --git a/tests/integration/targets/setup_ec2_vpc/defaults/main.yml b/tests/integration/targets/setup_ec2_vpc/defaults/main.yml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/integration/targets/setup_ec2_vpc/meta/main.yml b/tests/integration/targets/setup_ec2_vpc/meta/main.yml new file mode 100644 index 00000000000..23d65c7ef45 --- /dev/null +++ b/tests/integration/targets/setup_ec2_vpc/meta/main.yml @@ -0,0 +1,2 @@ +--- +dependencies: [] diff --git a/tests/integration/targets/setup_ec2_vpc/tasks/cleanup.yml b/tests/integration/targets/setup_ec2_vpc/tasks/cleanup.yml new file mode 100644 index 00000000000..3d2106fb1ac --- /dev/null +++ b/tests/integration/targets/setup_ec2_vpc/tasks/cleanup.yml @@ -0,0 +1,144 @@ +--- +# ============================================================ +- name: Cleanup after all tests + module_defaults: + group/aws: + access_key: "{{ aws_access_key }}" + secret_key: "{{ aws_secret_key }}" + session_token: "{{ security_token | default(omit) }}" + region: "{{ aws_region }}" + block: + # ============================================================ + # Describe state of remaining resources + + - name: (VPC Cleanup) Find all remaining ENIs + amazon.aws.ec2_eni_info: + filters: + vpc-id: "{{ setup_ec2_vpc_id }}" + register: remaining_enis + + - name: (VPC Cleanup) Retrieve security group info based on VPC ID + amazon.aws.ec2_security_group_info: + filters: + vpc-id: "{{ setup_ec2_vpc_id }}" + register: remaining_groups + + - name: (VPC Cleanup) Retrieve subnet info based on VPC ID + amazon.aws.ec2_vpc_subnet_info: + filters: + vpc-id: "{{ setup_ec2_vpc_id }}" + register: remaining_subnets + + - name: (VPC Cleanup) Retrieve route table info based on VPC ID + amazon.aws.ec2_vpc_route_table_info: + filters: + vpc-id: "{{ setup_ec2_vpc_id }}" + register: remaining_rtbs + + - name: (VPC Cleanup) Retrieve VPC info based on VPC ID + amazon.aws.ec2_vpc_net_info: + vpc_ids: + - "{{ setup_ec2_vpc_id }}" + register: remaining_vpc + + # ============================================================ + + - name: (Cleanup) Delete all ENIs + amazon.aws.ec2_eni: + state: absent + eni_id: "{{ item.id }}" + register: eni_removed + until: eni_removed is not failed + loop: "{{ remaining_enis.network_interfaces }}" + ignore_errors: true + retries: 10 + + # ============================================================ + # Delete all remaining SGs + + # Cross-dependencies between rules in the SGs can cause us problems if we don't clear the rules + # first + - name: (VPC Cleanup) Delete rules from remaining SGs + amazon.aws.ec2_security_group: + name: "{{ item.group_name }}" + group_id: "{{ item.group_id }}" + description: "{{ item.description }}" + rules: [] + rules_egress: [] + loop: "{{ remaining_groups.security_groups }}" + ignore_errors: true # noqa: ignore-errors + + - name: (VPC Cleanup) Delete remaining SGs + amazon.aws.ec2_security_group: + state: absent + group_id: "{{ item.group_id }}" + loop: "{{ remaining_groups.security_groups }}" + when: + - item.group_name != 'default' + ignore_errors: true # noqa: ignore-errors + + # ============================================================ + + - name: (VPC Cleanup) Delete remaining subnets + amazon.aws.ec2_vpc_subnet: + state: absent + vpc_id: "{{ setup_ec2_vpc_id }}" + cidr: "{{ item.cidr_block }}" + register: subnets_removed + loop: "{{ remaining_subnets.subnets }}" + until: subnets_removed is not failed + when: + - (item.name | default("")) != 'default' + ignore_errors: true # noqa: ignore-errors + retries: 10 + + # ============================================================ + + - name: (VPC Cleanup) Delete IGW + amazon.aws.ec2_vpc_igw: + state: absent + vpc_id: "{{ setup_ec2_vpc_id }}" + register: igw_deletion + retries: 10 + delay: 5 + until: igw_deletion is success + ignore_errors: true + + # ============================================================ + + - name: (VPC Cleanup) Delete route tables (excluding main table) + amazon.aws.ec2_vpc_route_table: + state: absent + vpc_id: "{{ setup_ec2_vpc_id }}" + route_table_id: "{{ item.id }}" + lookup: id + register: rtbs_removed + loop: "{{ remaining_rtbs.route_tables }}" + when: + - True not in main_associations + ignore_errors: true # noqa: ignore-errors + vars: + main_associations: "{{ item.associations | default([]) | map(attribute='main') | list }}" + + # ============================================================ + + - name: (VPC Cleanup) Remove the VPC + amazon.aws.ec2_vpc_net: + state: absent + vpc_id: "{{ setup_ec2_vpc_id }}" + register: vpc_removed + until: vpc_removed is not failed + ignore_errors: true # noqa: ignore-errors + retries: 10 + + # ============================================================ + + - name: (VPC Cleanup) (retry) Delete remaining route tables (including main table) + amazon.aws.ec2_vpc_route_table: + state: absent + vpc_id: "{{ setup_ec2_vpc_id }}" + route_table_id: "{{ item.id }}" + lookup: id + register: rtbs_removed + loop: "{{ remaining_rtbs.route_tables }}" + ignore_errors: true # noqa: ignore-errors diff --git a/tests/integration/targets/setup_ec2_vpc/tasks/main.yml b/tests/integration/targets/setup_ec2_vpc/tasks/main.yml new file mode 100644 index 00000000000..9f760b57c77 --- /dev/null +++ b/tests/integration/targets/setup_ec2_vpc/tasks/main.yml @@ -0,0 +1,4 @@ +--- +- name: Load VPC cleanup role + ansible.builtin.debug: + msg: VPC Cleanup module loaded diff --git a/tests/integration/targets/wafv2/defaults/main.yml b/tests/integration/targets/wafv2/defaults/main.yml index ac23638ca83..ed42acc9bf4 100644 --- a/tests/integration/targets/wafv2/defaults/main.yml +++ b/tests/integration/targets/wafv2/defaults/main.yml @@ -3,9 +3,13 @@ web_acl_name: '{{ tiny_prefix }}-web-acl' rule_group_name: '{{ tiny_prefix }}-rule-group' alb_name: "my-alb-{{ tiny_prefix }}" tg_name: "my-tg-{{ tiny_prefix }}" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.164.0/22 + cidr: - main: 10.228.228.0/22 - a: 10.228.228.0/24 - b: 10.228.229.0/24 - c: 10.228.230.0/24 - d: 10.228.231.0/24 + main: '{{ vpc_cidr }}' + a: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" + b: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" + c: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 2) }}" + d: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 3) }}" diff --git a/tests/integration/targets/wafv2/tasks/main.yml b/tests/integration/targets/wafv2/tasks/main.yml index a536cf4051f..cfe3a29b399 100644 --- a/tests/integration/targets/wafv2/tasks/main.yml +++ b/tests/integration/targets/wafv2/tasks/main.yml @@ -159,10 +159,10 @@ delay: 5 until: remove_subnet is success with_items: - - cidr: 10.228.228.0/24 - - cidr: 10.228.229.0/24 - - cidr: 10.228.230.0/24 - - cidr: 10.228.231.0/24 + - cidr: "{{ subnet_a_cidr }}" + - cidr: "{{ subnet_b_cidr }}" + - cidr: "{{ subnet_c_cidr }}" + - cidr: "{{ subnet_d_cidr }}" ignore_errors: true - name: destroy internet gateway @@ -179,7 +179,7 @@ - name: destroy VPC ec2_vpc_net: - cidr_block: 10.228.228.0/22 + cidr_block: "{{ vpc_cidr }}" name: '{{ resource_prefix }}_vpc' state: absent register: remove_vpc diff --git a/tests/integration/targets/wafv2_rule_group/defaults/main.yml b/tests/integration/targets/wafv2_rule_group/defaults/main.yml index ac23638ca83..32283608072 100644 --- a/tests/integration/targets/wafv2_rule_group/defaults/main.yml +++ b/tests/integration/targets/wafv2_rule_group/defaults/main.yml @@ -3,9 +3,13 @@ web_acl_name: '{{ tiny_prefix }}-web-acl' rule_group_name: '{{ tiny_prefix }}-rule-group' alb_name: "my-alb-{{ tiny_prefix }}" tg_name: "my-tg-{{ tiny_prefix }}" + +# VPC CIDR allocation - randomised to avoid conflicts +vpc_cidr: 10.{{ 256 | random(seed=resource_prefix) }}.160.0/22 + cidr: - main: 10.228.228.0/22 - a: 10.228.228.0/24 - b: 10.228.229.0/24 - c: 10.228.230.0/24 - d: 10.228.231.0/24 + main: '{{ vpc_cidr }}' + a: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 0) }}" + b: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 1) }}" + c: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 2) }}" + d: "{{ vpc_cidr | ansible.utils.ipsubnet(24, 3) }}"