|
| 1 | +--- |
| 2 | +- name: Integration tests for ec2_networking_resources role |
| 3 | + module_defaults: |
| 4 | + group/aws: |
| 5 | + aws_access_key: "{{ aws_access_key }}" |
| 6 | + aws_secret_key: "{{ aws_secret_key }}" |
| 7 | + security_token: "{{ security_token | default(omit) }}" |
| 8 | + region: "{{ aws_region }}" |
| 9 | + |
| 10 | + block: |
| 11 | + - name: Create networking infrastructure |
| 12 | + ansible.builtin.include_role: |
| 13 | + name: cloud.aws_ops.ec2_networking_resources |
| 14 | + vars: |
| 15 | + ec2_networking_resources_vpc_name: "{{ vpc_name }}" |
| 16 | + ec2_networking_resources_vpc_cidr_block: "{{ vpc_cidr_block }}" |
| 17 | + ec2_networking_resources_subnet_cidr_block: "{{ subnet_cidr_block }}" |
| 18 | + ec2_networking_resources_sg_internal_name: "{{ sg_name }}" |
| 19 | + ec2_networking_resources_sg_internal_description: Test security group |
| 20 | + |
| 21 | + - name: Get the created VPC |
| 22 | + amazon.aws.ec2_vpc_net_info: |
| 23 | + filters: |
| 24 | + "tag:Name": "{{ vpc_name }}" |
| 25 | + cidr: "{{ vpc_cidr_block }}" |
| 26 | + register: _vpc |
| 27 | + |
| 28 | + - name: Assert the VPC exists |
| 29 | + ansible.builtin.assert: |
| 30 | + that: |
| 31 | + - _vpc.vpcs | length == 1 |
| 32 | + - _vpc.vpcs[0].cidr_block == vpc_cidr_block |
| 33 | + |
| 34 | + - name: Get the created subnet |
| 35 | + amazon.aws.ec2_vpc_subnet_info: |
| 36 | + filters: |
| 37 | + vpc-id: "{{ _vpc.vpcs[0].id }}" |
| 38 | + cidr-block: "{{ subnet_cidr_block }}" |
| 39 | + register: _subnet |
| 40 | + |
| 41 | + - name: Assert subnet has been created |
| 42 | + ansible.builtin.assert: |
| 43 | + that: |
| 44 | + - _subnet.subnets | length == 1 |
| 45 | + - _subnet.subnets[0].cidr_block == subnet_cidr_block |
| 46 | + |
| 47 | + - name: Get security group |
| 48 | + amazon.aws.ec2_security_group_info: |
| 49 | + filters: |
| 50 | + group-name: "{{ sg_name }}" |
| 51 | + register: _security_group |
| 52 | + |
| 53 | + - name: Assert default security group has been created |
| 54 | + ansible.builtin.assert: |
| 55 | + that: |
| 56 | + - _security_group.security_groups | length == 1 |
| 57 | + - _sg_rule.from_port == 22 |
| 58 | + - _sg_rule.to_port == 22 |
| 59 | + - _sg_rule.ip_protocol == "tcp" |
| 60 | + - _sg_rule.ip_ranges[0].cidr_ip == vpc_cidr_block |
| 61 | + vars: |
| 62 | + _sg_rule: "{{ _security_group.security_groups[0].ip_permissions[0] }}" |
| 63 | + |
| 64 | + always: |
| 65 | + - name: Delete the security group |
| 66 | + amazon.aws.ec2_security_group: |
| 67 | + state: absent |
| 68 | + name: "{{ sg_name }}" |
| 69 | + ignore_errors: true |
| 70 | + |
| 71 | + - name: Get the VPC |
| 72 | + amazon.aws.ec2_vpc_net_info: |
| 73 | + filters: |
| 74 | + "tag:Name": "{{ vpc_name }}" |
| 75 | + cidr: "{{ vpc_cidr_block }}" |
| 76 | + register: vpc |
| 77 | + ignore_errors: true |
| 78 | + |
| 79 | + - name: Delete the VPC subnet |
| 80 | + amazon.aws.ec2_vpc_subnet: |
| 81 | + state: absent |
| 82 | + vpc_id: "{{ vpc.vpcs[0].id }}" |
| 83 | + cidr: "{{ subnet_cidr_block }}" |
| 84 | + ignore_errors: true |
| 85 | + |
| 86 | + - name: Get the route tables |
| 87 | + amazon.aws.ec2_vpc_route_table_info: |
| 88 | + filters: |
| 89 | + vpc-id: "{{ vpc.vpcs[0].id }}" |
| 90 | + register: routes |
| 91 | + ignore_errors: true |
| 92 | + |
| 93 | + - name: Delete the route tables |
| 94 | + amazon.aws.ec2_vpc_route_table: |
| 95 | + state: absent |
| 96 | + route_table_id: "{{ item.route_table_id }}" |
| 97 | + lookup: id |
| 98 | + loop: "{{ routes.route_tables }}" |
| 99 | + ignore_errors: true |
| 100 | + |
| 101 | + - name: Delete the VPC |
| 102 | + amazon.aws.ec2_vpc_net: |
| 103 | + state: absent |
| 104 | + name: "{{ vpc_name }}" |
| 105 | + cidr_block: "{{ vpc_cidr_block }}" |
| 106 | + ignore_errors: true |
0 commit comments