| 1 |
- name: run ec2_lc tests |
| 2 |
module_defaults: |
| 3 |
group/aws: |
| 4 |
access_key: "{{ aws_access_key }}" |
| 5 |
secret_key: "{{ aws_secret_key }}" |
| 6 |
session_token: "{{ security_token | default(omit) }}" |
| 7 |
region: "{{ aws_region }}" |
| 8 |
collections: |
| 9 |
- amazon.aws |
| 10 |
|
| 11 |
block: |
| 12 |
|
| 13 |
- name: set up environment for testing. |
| 14 |
include_tasks: env_setup.yml |
| 15 |
|
| 16 |
- name: Create launch configuration 1 |
| 17 |
community.aws.autoscaling_launch_config: |
| 18 |
name: '{{ resource_prefix }}-lc1' |
| 19 |
image_id: '{{ ec2_ami_id }}' |
| 20 |
assign_public_ip: yes |
| 21 |
instance_type: '{{ ec2_instance_type }}' |
| 22 |
security_groups: '{{ sg.group_id }}' |
| 23 |
volumes: |
| 24 |
- device_name: /dev/xvda |
| 25 |
volume_size: 10 |
| 26 |
volume_type: gp2 |
| 27 |
delete_on_termination: true |
| 28 |
register: lc_1_create |
| 29 |
|
| 30 |
- name: Gather information about launch configuration 1 |
| 31 |
community.aws.autoscaling_launch_config_info: |
| 32 |
name: '{{ resource_prefix }}-lc1' |
| 33 |
register: lc_1_info_result |
| 34 |
|
| 35 |
- assert: |
| 36 |
that: |
| 37 |
- lc_1_create is changed |
| 38 |
- '"autoscaling:CreateLaunchConfiguration" in lc_1_create.resource_actions' |
| 39 |
- '"throughput" not in lc_1_info_result.launch_configurations[0].block_device_mappings[0].ebs' |
| 40 |
- lc_1_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_size == 10 |
| 41 |
- lc_1_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_type == 'gp2' |
| 42 |
- lc_1_info_result.launch_configurations[0].instance_type == 't2.micro' |
| 43 |
|
| 44 |
- name: Create launch configuration 1 - Idempotency |
| 45 |
community.aws.autoscaling_launch_config: |
| 46 |
name: '{{ resource_prefix }}-lc1' |
| 47 |
image_id: '{{ ec2_ami_id }}' |
| 48 |
assign_public_ip: yes |
| 49 |
instance_type: '{{ ec2_instance_type }}' |
| 50 |
security_groups: '{{ sg.group_id }}' |
| 51 |
volumes: |
| 52 |
- device_name: /dev/xvda |
| 53 |
volume_size: 10 |
| 54 |
volume_type: gp2 |
| 55 |
delete_on_termination: true |
| 56 |
register: lc_1_create_idem |
| 57 |
|
| 58 |
- assert: |
| 59 |
that: |
| 60 |
- lc_1_create_idem is not changed |
| 61 |
- '"autoscaling:CreateLaunchConfiguration" not in lc_1_create_idem.resource_actions' |
| 62 |
|
| 63 |
- name: Create launch configuration 2 |
| 64 |
community.aws.autoscaling_launch_config: |
| 65 |
name: '{{ resource_prefix }}-lc2' |
| 66 |
image_id: '{{ ec2_ami_id }}' |
| 67 |
assign_public_ip: yes |
| 68 |
instance_type: 't3.small' |
| 69 |
security_groups: '{{ sg.group_id }}' |
| 70 |
volumes: |
| 71 |
- device_name: /dev/xvda |
| 72 |
volume_size: 10 |
| 73 |
volume_type: gp2 |
| 74 |
delete_on_termination: true |
| 75 |
register: lc_2_create |
| 76 |
|
| 77 |
- name: Gather information about launch configuration 2 |
| 78 |
community.aws.autoscaling_launch_config_info: |
| 79 |
name: '{{ resource_prefix }}-lc2' |
| 80 |
register: lc_2_info_result |
| 81 |
|
| 82 |
- assert: |
| 83 |
that: |
| 84 |
- lc_2_create is changed |
| 85 |
- '"autoscaling:CreateLaunchConfiguration" in lc_2_create.resource_actions' |
| 86 |
- '"throughput" not in lc_2_info_result.launch_configurations[0].block_device_mappings[0].ebs' |
| 87 |
- lc_2_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_size == 10 |
| 88 |
- lc_2_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_type == 'gp2' |
| 89 |
- lc_2_info_result.launch_configurations[0].instance_type == 't3.small' |
| 90 |
- '"autoscaling:CreateLaunchConfiguration" in lc_2_create.resource_actions' |
| 91 |
|
| 92 |
- name: Create launch configuration 2 - Idempotency |
| 93 |
community.aws.autoscaling_launch_config: |
| 94 |
name: '{{ resource_prefix }}-lc2' |
| 95 |
image_id: '{{ ec2_ami_id }}' |
| 96 |
assign_public_ip: yes |
| 97 |
instance_type: '{{ ec2_instance_type }}' |
| 98 |
security_groups: '{{ sg.group_id }}' |
| 99 |
volumes: |
| 100 |
- device_name: /dev/xvda |
| 101 |
volume_size: 10 |
| 102 |
volume_type: gp2 |
| 103 |
delete_on_termination: true |
| 104 |
register: lc_2_create_idem |
| 105 |
|
| 106 |
- assert: |
| 107 |
that: |
| 108 |
- lc_2_create_idem is not changed |
| 109 |
- '"autoscaling:CreateLaunchConfiguration" not in lc_2_create_idem.resource_actions' |
| 110 |
|
| 111 |
- name: Create launch configuration 3 - test throughput parameter |
| 112 |
community.aws.autoscaling_launch_config: |
| 113 |
name: '{{ resource_prefix }}-lc3' |
| 114 |
image_id: '{{ ec2_ami_id }}' |
| 115 |
instance_type: '{{ ec2_instance_type }}' |
| 116 |
volumes: |
| 117 |
- device_name: /dev/sda1 |
| 118 |
volume_size: 10 |
| 119 |
volume_type: gp3 |
| 120 |
throughput: 250 |
| 121 |
delete_on_termination: true |
| 122 |
register: lc_3_create |
| 123 |
|
| 124 |
- name: Gather information about launch configuration 3 |
| 125 |
community.aws.autoscaling_launch_config_info: |
| 126 |
name: '{{ resource_prefix }}-lc3' |
| 127 |
register: lc_3_info_result |
| 128 |
|
| 129 |
- assert: |
| 130 |
that: |
| 131 |
- lc_3_create is changed |
| 132 |
- '"throughput" in lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs' |
| 133 |
- lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs.throughput == 250 |
| 134 |
- lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_size == 10 |
| 135 |
- lc_3_info_result.launch_configurations[0].block_device_mappings[0].ebs.volume_type == 'gp3' |
| 136 |
- lc_3_info_result.launch_configurations[0].instance_type == 't2.micro' |
| 137 |
- '"autoscaling:CreateLaunchConfiguration" in lc_3_create.resource_actions' |
| 138 |
|
| 139 |
- name: Create launch configuration 3 - Idempotency |
| 140 |
community.aws.autoscaling_launch_config: |
| 141 |
name: '{{ resource_prefix }}-lc3' |
| 142 |
image_id: '{{ ec2_ami_id }}' |
| 143 |
instance_type: '{{ ec2_instance_type }}' |
| 144 |
volumes: |
| 145 |
- device_name: /dev/sda1 |
| 146 |
volume_size: 10 |
| 147 |
volume_type: gp3 |
| 148 |
throughput: 250 |
| 149 |
delete_on_termination: true |
| 150 |
register: lc_3_create_idem |
| 151 |
|
| 152 |
- assert: |
| 153 |
that: |
| 154 |
- lc_3_create_idem is not changed |
| 155 |
- '"autoscaling:CreateLaunchConfiguration" not in lc_3_create_idem.resource_actions' |
| 156 |
|
| 157 |
- name: Search for the Launch Configurations that start with test resource_prefix |
| 158 |
community.aws.autoscaling_launch_config_find: |
| 159 |
name_regex: '{{ resource_prefix }}*' |
| 160 |
sort_order: descending |
| 161 |
register: lc_find_result |
| 162 |
|
| 163 |
- assert: |
| 164 |
that: |
| 165 |
- lc_find_result.results | length == 3 |
| 166 |
- '"autoscaling:DescribeLaunchConfigurations" in lc_find_result.resource_actions' |
| 167 |
|
| 168 |
- name: Delete launch configuration 1 |
| 169 |
community.aws.autoscaling_launch_config: |
| 170 |
name: '{{ resource_prefix }}-lc1' |
| 171 |
state: absent |
| 172 |
register: lc_1_delete |
| 173 |
|
| 174 |
- assert: |
| 175 |
that: |
| 176 |
- lc_1_delete is changed |
| 177 |
- '"autoscaling:DeleteLaunchConfiguration" in lc_1_delete.resource_actions' |
| 178 |
|
| 179 |
- name: Delete launch configuration 1 - Idempotency |
| 180 |
community.aws.autoscaling_launch_config: |
| 181 |
name: '{{ resource_prefix }}-lc1' |
| 182 |
state: absent |
| 183 |
register: lc_1_delete_idem |
| 184 |
|
| 185 |
- assert: |
| 186 |
that: |
| 187 |
- lc_1_delete_idem is not changed |
| 188 |
- '"autoscaling:DeleteLaunchConfiguration" not in lc_1_delete_idem.resource_actions' |
| 189 |
|
| 190 |
- name: Gather information about launch configuration 1 |
| 191 |
community.aws.autoscaling_launch_config_info: |
| 192 |
name: '{{ resource_prefix }}-lc1' |
| 193 |
register: lc_1_info_result |
| 194 |
|
| 195 |
- assert: |
| 196 |
that: |
| 197 |
- lc_1_info_result is not changed |
| 198 |
- lc_1_info_result.launch_configurations | length == 0 |
| 199 |
|
| 200 |
- name: Delete launch configuration 2 |
| 201 |
community.aws.autoscaling_launch_config: |
| 202 |
name: '{{ resource_prefix }}-lc2' |
| 203 |
state: absent |
| 204 |
register: lc_2_delete |
| 205 |
|
| 206 |
- assert: |
| 207 |
that: |
| 208 |
- lc_2_delete is changed |
| 209 |
- '"autoscaling:DeleteLaunchConfiguration" in lc_2_delete.resource_actions' |
| 210 |
|
| 211 |
- name: Delete launch configuration 2 - Idempotency |
| 212 |
community.aws.autoscaling_launch_config: |
| 213 |
name: '{{ resource_prefix }}-lc2' |
| 214 |
state: absent |
| 215 |
register: lc_2_delete_idem |
| 216 |
|
| 217 |
- assert: |
| 218 |
that: |
| 219 |
- lc_2_delete_idem is not changed |
| 220 |
- '"autoscaling:DeleteLaunchConfiguration" not in lc_2_delete_idem.resource_actions' |
| 221 |
|
| 222 |
- name: Gather information about launch configuration 2 |
| 223 |
community.aws.autoscaling_launch_config_info: |
| 224 |
name: '{{ resource_prefix }}-lc2' |
| 225 |
register: lc_2_info_result |
| 226 |
|
| 227 |
- assert: |
| 228 |
that: |
| 229 |
- lc_2_info_result is not changed |
| 230 |
- lc_2_info_result.launch_configurations | length == 0 |
| 231 |
|
| 232 |
- name: Delete launch configuration 3 |
| 233 |
community.aws.autoscaling_launch_config: |
| 234 |
name: '{{ resource_prefix }}-lc3' |
| 235 |
state: absent |
| 236 |
register: lc_3_delete |
| 237 |
|
| 238 |
- assert: |
| 239 |
that: |
| 240 |
- lc_3_delete is changed |
| 241 |
- '"autoscaling:DeleteLaunchConfiguration" in lc_3_delete.resource_actions' |
| 242 |
|
| 243 |
- name: Delete launch configuration 3 - Idempotency |
| 244 |
community.aws.autoscaling_launch_config: |
| 245 |
name: '{{ resource_prefix }}-lc3' |
| 246 |
state: absent |
| 247 |
register: lc_3_delete_idem |
| 248 |
|
| 249 |
- assert: |
| 250 |
that: |
| 251 |
- lc_3_delete_idem is not changed |
| 252 |
- '"autoscaling:DeleteLaunchConfiguration" not in lc_3_delete_idem.resource_actions' |
| 253 |
|
| 254 |
- name: Gather information about launch configuration 3 |
| 255 |
community.aws.autoscaling_launch_config_info: |
| 256 |
name: '{{ resource_prefix }}-lc2' |
| 257 |
register: lc_3_info_result |
| 258 |
|
| 259 |
- assert: |
| 260 |
that: |
| 261 |
- lc_3_info_result is not changed |
| 262 |
- lc_3_info_result.launch_configurations | length == 0 |
| 263 |
|
| 264 |
always: |
| 265 |
|
| 266 |
- include_tasks: env_cleanup.yml |