Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/wafv2/tasks/alb.yml

raw
1 ############################################
2 # create ALB and necessary dependencies
3 # to test wafv2_resources
4 ############################################
5 - name: create VPC
6 ec2_vpc_net:
7 cidr_block: "{{ cidr.main }}"
8 name: '{{ resource_prefix }}_vpc'
9 state: present
10 register: vpc
11
12 - name: create internet gateway
13 ec2_vpc_igw:
14 vpc_id: '{{ vpc.vpc.id }}'
15 state: present
16 tags:
17 Name: '{{ resource_prefix }}'
18 register: igw
19
20 - name: create public subnet
21 ec2_vpc_subnet:
22 cidr: '{{ item.cidr }}'
23 az: '{{ aws_region}}{{ item.az }}'
24 vpc_id: '{{ vpc.vpc.id }}'
25 state: present
26 tags:
27 Public: '{{ item.public|string }}'
28 Name: '{{ item.public|ternary(''public'', ''private'') }}-{{ item.az }}'
29 with_items:
30 - cidr: "{{ cidr.a }}"
31 az: a
32 public: 'True'
33 - cidr: "{{ cidr.b }}"
34 az: b
35 public: 'True'
36 - cidr: "{{ cidr.c }}"
37 az: a
38 public: 'False'
39 - cidr: "{{ cidr.d }}"
40 az: b
41 public: 'False'
42 register: subnets
43
44 - ec2_vpc_subnet_info:
45 filters:
46 vpc-id: '{{ vpc.vpc.id }}'
47 register: vpc_subnets
48
49 - name: create list of subnet ids
50 set_fact:
51 alb_subnets: "{{ (vpc_subnets.subnets| selectattr('tags.Public', 'equalto', 'True')| map(attribute='id')| list) }}"
52 private_subnets: "{{ (vpc_subnets.subnets| selectattr('tags.Public', 'equalto', 'False')| map(attribute='id')| list) }}"
53
54 - name: create a route table
55 ec2_vpc_route_table:
56 vpc_id: '{{ vpc.vpc.id }}'
57 tags:
58 Name: igw-route
59 Created: '{{ resource_prefix }}'
60 subnets: '{{ alb_subnets + private_subnets }}'
61 routes:
62 - dest: 0.0.0.0/0
63 gateway_id: '{{ igw.gateway_id }}'
64 register: route_table
65
66 - ec2_security_group:
67 name: '{{ resource_prefix }}'
68 description: security group for Ansible ALB integration tests
69 state: present
70 vpc_id: '{{ vpc.vpc.id }}'
71 rules:
72 - proto: tcp
73 from_port: 1
74 to_port: 65535
75 cidr_ip: 0.0.0.0/0
76 register: sec_group
77
78 - name: create a target group for testing
79 elb_target_group:
80 name: '{{ tg_name }}'
81 protocol: http
82 port: 80
83 vpc_id: '{{ vpc.vpc.id }}'
84 state: present
85 register: tg
86
87 - name: create ALB with a listener
88 elb_application_lb:
89 name: "{{ alb_name }}"
90 subnets: "{{ alb_subnets }}"
91 security_groups: "{{ sec_group.group_id }}"
92 state: present
93 wait: yes
94 listeners:
95 - Protocol: HTTP
96 Port: 80
97 DefaultActions:
98 - Type: forward
99 TargetGroupName: "{{ tg_name }}"
100 register: alb
101
102 - assert:
103 that:
104 - alb.listeners|length == 1
105 - alb.listeners[0].rules|length == 1