Debian Codegraph @

ansible_collections/amazon/aws/tests/integration/targets/autoscaling_instance/tasks/env_setup.yml

raw
1 ---
2 # Set up the testing dependencies: VPC, subnet, security group, and two launch configurations
3 - name: Create VPC for use in testing
4 amazon.aws.ec2_vpc_net:
5 name: "{{ default_resource_name }}"
6 cidr_block: "{{ vpc_cidr }}"
7 tenancy: default
8 register: testing_vpc
9
10 - ansible.builtin.set_fact:
11 vpc_id: "{{ testing_vpc.vpc.id }}"
12
13 - name: Create internet gateway for use in testing
14 amazon.aws.ec2_vpc_igw:
15 vpc_id: "{{ vpc_id }}"
16 state: present
17 tags:
18 Name: "{{ default_resource_name }}"
19 register: igw
20
21 - name: Create subnet for use in testing
22 amazon.aws.ec2_vpc_subnet:
23 state: present
24 vpc_id: "{{ vpc_id }}"
25 cidr: "{{ subnet_a_cidr }}"
26 az: "{{ subnet_a_az }}"
27 tags:
28 Name: "{{ default_resource_name }}"
29
30 register: testing_subnet
31 - name: Create routing rules
32 amazon.aws.ec2_vpc_route_table:
33 vpc_id: "{{ vpc_id }}"
34 tags:
35 Name: "{{ default_resource_name }}"
36 routes:
37 - dest: "0.0.0.0/0"
38 gateway_id: "{{ igw.gateway_id }}"
39 subnets:
40 - "{{ testing_subnet.subnet.id }}"
41
42 - name: Create a security group with the vpc created in the ec2_setup
43 amazon.aws.ec2_security_group:
44 name: "{{ default_resource_name }}"
45 description: a security group for ansible tests
46 vpc_id: "{{ vpc_id }}"
47 rules:
48 - proto: tcp
49 from_port: 22
50 to_port: 22
51 cidr_ip: "0.0.0.0/0"
52 - proto: tcp
53 from_port: 80
54 to_port: 80
55 cidr_ip: "0.0.0.0/0"
56 register: sg
57
58 # Note: main autoscaling tests use ASG "Launch Configs", these are being phased out in favour of EC2
59 # Launch Templates
60 - name: Ensure launch templates exist
61 amazon.aws.ec2_launch_template:
62 name: "{{ item }}"
63 network_interfaces:
64 - device_index: 0
65 # XXX confusing - ec2_instance (incorrectly) calls this assign_public_ip
66 associate_public_ip_address: true
67 delete_on_termination: true
68 # XXX confsuing - at the top level this would be security_groups, here it's groups
69 groups: "{{ sg.group_id }}"
70 image_id: "{{ ec2_ami_id }}"
71 user_data: "{{ lookup('ansible.builtin.file', 'user_data') | ansible.builtin.b64encode }}"
72 instance_type: t3.micro
73 loop:
74 - "{{ default_resource_name }}-1"
75 - "{{ default_resource_name }}-2"
76
77 - name: Create asg and wait for instances to be deemed healthy (no ELB)
78 amazon.aws.autoscaling_group:
79 name: "{{ default_resource_name }}"
80 launch_template:
81 launch_template_name: "{{ default_resource_name }}-1"
82 desired_capacity: 2
83 health_check_period: 10
84 default_cooldown: 10
85 min_size: 0
86 max_size: 4
87 vpc_zone_identifier: "{{ testing_subnet.subnet.id }}"
88 state: present
89 wait_for_instances: true
90 register: create_asg
91 - ansible.builtin.assert:
92 that:
93 - create_asg.viable_instances == 2
94 - create_asg.instances | length == 2
95
96 - ansible.builtin.assert:
97 that:
98 - create_asg.viable_instances == 2
99 - create_asg.instances | length == 2
100
101 - ansible.builtin.set_fact:
102 initial_instances: "{{ create_asg.instances }}"
103 all_instances: "{{ create_asg.instances }}"
104
105 - amazon.aws.autoscaling_group_info:
106 name: "{{ default_resource_name }}"