-
Notifications
You must be signed in to change notification settings - Fork 341
/
tests.yml
772 lines (682 loc) · 26.7 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
---
- module_defaults:
group/aws:
aws_access_key: '{{ aws_access_key | default(omit) }}'
aws_secret_key: '{{ aws_secret_key | default(omit) }}'
security_token: '{{ security_token | default(omit) }}'
region: '{{ aws_region | default(omit) }}'
collections:
- amazon.aws
- community.aws
block:
- name: list available AZs
aws_az_info:
register: region_azs
- name: pick an AZ for testing
set_fact:
availability_zone: "{{ region_azs.availability_zones[0].zone_name }}"
- name: Create a test VPC
ec2_vpc_net:
name: "{{ vpc_name }}"
cidr_block: "{{ vpc_cidr }}"
tags:
Name: ec2_vol testing
ResourcePrefix: "{{ resource_prefix }}"
register: testing_vpc
- name: Create a test subnet
ec2_vpc_subnet:
vpc_id: "{{ testing_vpc.vpc.id }}"
cidr: "{{ subnet_cidr }}"
tags:
Name: ec2_vol testing
ResourcePrefix: "{{ resource_prefix }}"
az: '{{ availability_zone }}'
register: testing_subnet
- name: Find AMI to use
ec2_ami_info:
owners: 'amazon'
filters:
name: '{{ ec2_ami_name }}'
register: ec2_amis
- name: Set fact with latest AMI
vars:
latest_ami: '{{ ec2_amis.images | sort(attribute="creation_date") | last }}'
set_fact:
ec2_ami_image: '{{ latest_ami.image_id }}'
# # ==== ec2_vol tests ===============================================
- name: create a volume (validate module defaults)
ec2_vol:
volume_size: 1
zone: "{{ availability_zone }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: volume1
- name: check task return attributes
assert:
that:
- volume1.changed
- "'volume' in volume1"
- "'volume_id' in volume1"
- "'volume_type' in volume1"
- "'device' in volume1"
- volume1.volume.status == 'available'
- volume1.volume_type == 'standard'
- "'attachment_set' in volume1.volume"
- volume1.volume.attachment_set | length == 0
- not ("Name" in volume1.volume.tags)
- not volume1.volume.encrypted
- volume1.volume.tags.ResourcePrefix == "{{ resource_prefix }}"
# no idempotency check needed here
- name: create another volume (override module defaults)
ec2_vol:
encrypted: yes
volume_size: 4
volume_type: io1
iops: 101
name: "{{ resource_prefix }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
zone: "{{ availability_zone }}"
register: volume2
- name: check task return attributes
assert:
that:
- volume2.changed
- "'volume' in volume2"
- "'volume_id' in volume2"
- "'volume_type' in volume2"
- "'device' in volume2"
- volume2.volume.status == 'available'
- volume2.volume_type == 'io1'
- volume2.volume.iops == 101
- volume2.volume.size == 4
- volume2.volume.tags.Name == "{{ resource_prefix }}"
- volume2.volume.encrypted
- volume2.volume.tags.ResourcePrefix == "{{ resource_prefix }}"
- name: create another volume (override module defaults) (idempotent)
ec2_vol:
encrypted: yes
volume_size: 4
volume_type: io1
iops: 101
name: "{{ resource_prefix }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
zone: "{{ availability_zone }}"
register: volume2_idem
- name: check task return attributes
assert:
that:
- not volume2_idem.changed
- name: create snapshot from volume
ec2_snapshot:
volume_id: "{{ volume1.volume_id }}"
description: "Resource Prefix - {{ resource_prefix }}"
snapshot_tags:
ResourcePrefix: "{{ resource_prefix }}"
register: vol1_snapshot
- name: check task return attributes
assert:
that:
- vol1_snapshot.changed
- name: create a volume from a snapshot
ec2_vol:
snapshot: "{{ vol1_snapshot.snapshot_id }}"
encrypted: yes
volume_type: gp2
volume_size: 1
zone: "{{ availability_zone }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: volume3
- name: check task return attributes
assert:
that:
- volume3.changed
- "volume3.volume.snapshot_id == vol1_snapshot.snapshot_id"
- name: create an ec2 instance
ec2_instance:
name: "{{ instance_name }}"
vpc_subnet_id: "{{ testing_subnet.subnet.id }}"
instance_type: t3.nano
image_id: "{{ ec2_ami_image }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: test_instance
- name: check task return attributes
assert:
that:
- test_instance.changed
- name: attach existing volume to an instance
ec2_vol:
id: "{{ volume1.volume_id }}"
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdg
delete_on_termination: no
register: vol_attach_result
- name: check task return attributes
assert:
that:
- vol_attach_result.changed
- "'device' in vol_attach_result and vol_attach_result.device == '/dev/sdg'"
- "'volume' in vol_attach_result"
- vol_attach_result.volume.attachment_set[0].status in ['attached', 'attaching']
- vol_attach_result.volume.attachment_set[0].instance_id == test_instance.instance_ids[0]
- vol_attach_result.volume.attachment_set[0].device == '/dev/sdg'
- not vol_attach_result.volume.attachment_set[0].delete_on_termination
- name: attach existing volume to an instance (idempotent)
ec2_vol:
id: "{{ volume1.volume_id }}"
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdg
delete_on_termination: no
register: vol_attach_result
- name: check task return attributes
assert:
that:
- "not vol_attach_result.changed"
- vol_attach_result.volume.attachment_set[0].status in ['attached', 'attaching']
- name: attach a new volume to an instance
ec2_vol:
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
name: '{{ resource_prefix }} - sdh'
tags:
"lowercase spaced": 'hello cruel world'
"Title Case": 'Hello Cruel World'
CamelCase: 'SimpleCamelCase'
snake_case: 'simple_snake_case'
ResourcePrefix: "{{ resource_prefix }}"
register: new_vol_attach_result
- name: check task return attributes
assert:
that:
- new_vol_attach_result.changed
- "'device' in new_vol_attach_result and new_vol_attach_result.device == '/dev/sdh'"
- "'volume' in new_vol_attach_result"
- new_vol_attach_result.volume.attachment_set[0].status in ['attached', 'attaching']
- new_vol_attach_result.volume.attachment_set[0].instance_id == test_instance.instance_ids[0]
- new_vol_attach_result.volume.attachment_set[0].device == '/dev/sdh'
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world'
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World'
- new_vol_attach_result.volume.tags["CamelCase"] == 'SimpleCamelCase'
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case'
- new_vol_attach_result.volume.tags["Name"] == '{{ resource_prefix }} - sdh'
- name: attach a new volume to an instance (idempotent)
ec2_vol:
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: new_vol_attach_result_idem
ignore_errors: true
- name: check task return attributes
assert:
that:
- "not new_vol_attach_result_idem.changed"
- "'Volume mapping for /dev/sdh already exists' in new_vol_attach_result_idem.msg"
- name: change some tag values
ec2_vol:
instance: "{{ test_instance.instance_ids[0] }}"
id: "{{ new_vol_attach_result.volume.id }}"
device_name: /dev/sdh
volume_size: 1
volume_type: gp2
tags:
"lowercase spaced": 'hello cruel world ❤️'
"Title Case": 'Hello Cruel World ❤️'
CamelCase: 'SimpleCamelCase ❤️'
snake_case: 'simple_snake_case ❤️'
register: new_vol_attach_result
- name: check task return attributes
assert:
that:
- new_vol_attach_result.changed
- "'volume_id' in new_vol_attach_result"
- new_vol_attach_result.volume_id == "{{ new_vol_attach_result.volume_id }}"
- "'attachment_set' in new_vol_attach_result.volume"
- "'create_time' in new_vol_attach_result.volume"
- "'id' in new_vol_attach_result.volume"
- "'size' in new_vol_attach_result.volume"
- new_vol_attach_result.volume.size == 1
- "'volume_type' in new_vol_attach_result"
- new_vol_attach_result.volume_type == 'gp2'
- "'tags' in new_vol_attach_result.volume"
- (new_vol_attach_result.volume.tags | length) == 6
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️'
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️'
- new_vol_attach_result.volume.tags["CamelCase"] == 'SimpleCamelCase ❤️'
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️'
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix
- new_vol_attach_result.volume.tags["Name"] == '{{ resource_prefix }} - sdh'
- name: create a volume from a snapshot and attach to the instance
ec2_vol:
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdi
snapshot: "{{ vol1_snapshot.snapshot_id }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: attach_new_vol_from_snapshot_result
- name: check task return attributes
assert:
that:
- attach_new_vol_from_snapshot_result.changed
- "'device' in attach_new_vol_from_snapshot_result and attach_new_vol_from_snapshot_result.device == '/dev/sdi'"
- "'volume' in attach_new_vol_from_snapshot_result"
- attach_new_vol_from_snapshot_result.volume.attachment_set[0].status in ['attached', 'attaching']
- attach_new_vol_from_snapshot_result.volume.attachment_set[0].instance_id == test_instance.instance_ids[0]
- name: list volumes attached to instance
ec2_vol:
instance: "{{ test_instance.instance_ids[0] }}"
state: list
register: inst_vols
- name: check task return attributes
assert:
that:
- not inst_vols.changed
- "'volumes' in inst_vols"
- inst_vols.volumes | length == 4
- name: get info on ebs volumes
ec2_vol_info:
register: ec2_vol_info
- name: check task return attributes
assert:
that:
- not ec2_vol_info.failed
- name: get info on ebs volumes
ec2_vol_info:
filters:
attachment.instance-id: "{{ test_instance.instance_ids[0] }}"
register: ec2_vol_info
- name: check task return attributes
assert:
that:
- ec2_vol_info.volumes | length == 4
- name: detach volume from the instance
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
instance: ""
register: new_vol_attach_result
- name: check task return attributes
assert:
that:
- new_vol_attach_result.changed
- new_vol_attach_result.volume.status == 'available'
- name: detach volume from the instance (idempotent)
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
instance: ""
register: new_vol_attach_result_idem
- name: check task return attributes
assert:
that:
- not new_vol_attach_result_idem.changed
- name: must not change because of missing parameter modify_volume
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
zone: "{{ availability_zone }}"
volume_type: gp3
register: changed_gp3_volume
- name: volume must not changed
assert:
that:
- not changed_gp3_volume.changed
- name: change existing volume to gp3
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
zone: "{{ availability_zone }}"
volume_type: gp3
modify_volume: yes
register: changed_gp3_volume
- name: check that volume_type has changed
assert:
that:
- changed_gp3_volume.changed
- "'volume_id' in changed_gp3_volume"
- changed_gp3_volume.volume_id == "{{ new_vol_attach_result.volume_id }}"
- "'attachment_set' in changed_gp3_volume.volume"
- "'create_time' in changed_gp3_volume.volume"
- "'id' in changed_gp3_volume.volume"
- "'size' in changed_gp3_volume.volume"
- "'volume_type' in changed_gp3_volume"
- changed_gp3_volume.volume_type == 'gp3'
- "'iops' in changed_gp3_volume.volume"
- changed_gp3_volume.volume.iops == 3000
# Ensure our tags are still here
- "'tags' in changed_gp3_volume.volume"
- (changed_gp3_volume.volume.tags | length) == 6
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️'
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️'
- new_vol_attach_result.volume.tags["CamelCase"] == 'SimpleCamelCase ❤️'
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️'
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix
- new_vol_attach_result.volume.tags["Name"] == '{{ resource_prefix }} - sdh'
- name: volume must be from type gp3 (idempotent)
ec2_vol:
id: "{{ new_vol_attach_result.volume_id }}"
zone: "{{ availability_zone }}"
volume_type: gp3
modify_volume: yes
register: changed_gp3_volume
retries: 3
delay: 3
until: not changed_gp3_volume.failed
# retry because ebs change is to slow
- name: must not changed (idempotent)
assert:
that:
- not changed_gp3_volume.changed
- "'volume_id' in changed_gp3_volume"
- changed_gp3_volume.volume_id == "{{ new_vol_attach_result.volume_id }}"
- "'attachment_set' in changed_gp3_volume.volume"
- "'create_time' in changed_gp3_volume.volume"
- "'id' in changed_gp3_volume.volume"
- "'size' in changed_gp3_volume.volume"
- "'volume_type' in changed_gp3_volume"
- changed_gp3_volume.volume_type == 'gp3'
- "'iops' in changed_gp3_volume.volume"
- changed_gp3_volume.volume.iops == 3000
- "'throughput' in changed_gp3_volume.volume"
- "'tags' in changed_gp3_volume.volume"
- (changed_gp3_volume.volume.tags | length) == 6
- new_vol_attach_result.volume.tags["lowercase spaced"] == 'hello cruel world ❤️'
- new_vol_attach_result.volume.tags["Title Case"] == 'Hello Cruel World ❤️'
- new_vol_attach_result.volume.tags["CamelCase"] == 'SimpleCamelCase ❤️'
- new_vol_attach_result.volume.tags["snake_case"] == 'simple_snake_case ❤️'
- new_vol_attach_result.volume.tags["ResourcePrefix"] == resource_prefix
- new_vol_attach_result.volume.tags["Name"] == '{{ resource_prefix }} - sdh'
- name: re-read volume information to validate new volume_type
ec2_vol_info:
filters:
volume-id: "{{ changed_gp3_volume.volume_id }}"
register: verify_gp3_change
- name: volume type must be gp3
assert:
that:
- v.type == 'gp3'
vars:
v: "{{ verify_gp3_change.volumes[0] }}"
- name: delete volume
ec2_vol:
id: "{{ volume2.volume_id }}"
state: absent
register: delete_volume_result
- name: check task return attributes
assert:
that:
- "delete_volume_result.changed"
- name: delete volume (idempotent)
ec2_vol:
id: "{{ volume2.volume_id }}"
state: absent
register: delete_volume_result_idem
- name: check task return attributes
assert:
that:
- not delete_volume_result_idem.changed
- '"Volume {{ volume2.volume_id }} does not exist" in delete_volume_result_idem.msg'
# Originally from ec2_vol_info
- name: Create test volume with Destroy on Terminate
ec2_vol:
instance: "{{ test_instance.instance_ids[0] }}"
volume_size: 4
name: "{{ resource_prefix }}_delete_on_terminate"
device_name: /dev/sdj
volume_type: io1
iops: 100
tags:
Tag Name with Space-and-dash: Tag Value with Space-and-dash
delete_on_termination: yes
register: dot_volume
- name: check task return attributes
assert:
that:
- dot_volume.changed
- "'attachment_set' in dot_volume.volume"
- "'delete_on_termination' in dot_volume.volume.attachment_set[0]"
- "'create_time' in dot_volume.volume"
- "'id' in dot_volume.volume"
- "'size' in dot_volume.volume"
- dot_volume.volume.size == 4
- "'volume_type' in dot_volume"
- dot_volume.volume_type == 'io1'
- "'iops' in dot_volume.volume"
- dot_volume.volume.iops == 100
- "'tags' in dot_volume.volume"
- (dot_volume.volume.tags | length ) == 2
- dot_volume.volume.tags["Name"] == "{{ resource_prefix }}_delete_on_terminate"
- dot_volume.volume.tags["Tag Name with Space-and-dash"] == 'Tag Value with Space-and-dash'
- name: Gather volume info without any filters
ec2_vol_info:
register: volume_info_wo_filters
check_mode: no
- name: Check if info are returned without filters
assert:
that:
- "volume_info_wo_filters.volumes is defined"
- name: Gather volume info
ec2_vol_info:
filters:
"tag:Name": "{{ resource_prefix }}_delete_on_terminate"
register: volume_info
check_mode: no
- name: Format check
assert:
that:
- "volume_info.volumes|length == 1"
- "v.attachment_set[0].attach_time is defined"
- "v.attachment_set[0].device is defined and v.attachment_set[0].device == dot_volume.device"
- "v.attachment_set[0].instance_id is defined and v.attachment_set[0].instance_id == test_instance.instance_ids[0]"
- "v.attachment_set[0].status is defined and v.attachment_set[0].status == 'attached'"
- "v.create_time is defined"
- "v.encrypted is defined and v.encrypted == false"
- "v.id is defined and v.id == dot_volume.volume_id"
- "v.iops is defined and v.iops == 100"
- "v.region is defined and v.region == aws_region"
- "v.size is defined and v.size == 4"
- "v.snapshot_id is defined and v.snapshot_id == ''"
- "v.status is defined and v.status == 'in-use'"
- "v.tags.Name is defined and v.tags.Name == resource_prefix + '_delete_on_terminate'"
- "v.tags['Tag Name with Space-and-dash'] == 'Tag Value with Space-and-dash'"
- "v.type is defined and v.type == 'io1'"
- "v.zone is defined and v.zone == test_instance.instances[0].placement.availability_zone"
vars:
v: "{{ volume_info.volumes[0] }}"
- name: New format check
assert:
that:
- "v.attachment_set[0].delete_on_termination is defined"
vars:
v: "{{ volume_info.volumes[0] }}"
when: ansible_version.full is version('2.7', '>=')
- name: test create a new gp3 volume
ec2_vol:
volume_size: 70
zone: "{{ availability_zone }}"
volume_type: gp3
throughput: 130
iops: 3001
name: "GP3-TEST-{{ resource_prefix }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: gp3_volume
- name: check that volume_type is gp3
assert:
that:
- gp3_volume.changed
- "'attachment_set' in gp3_volume.volume"
- "'create_time' in gp3_volume.volume"
- "'id' in gp3_volume.volume"
- "'size' in gp3_volume.volume"
- gp3_volume.volume.size == 70
- "'volume_type' in gp3_volume"
- gp3_volume.volume_type == 'gp3'
- "'iops' in gp3_volume.volume"
- gp3_volume.volume.iops == 3001
- "'throughput' in gp3_volume.volume"
- gp3_volume.volume.throughput == 130
- "'tags' in gp3_volume.volume"
- (gp3_volume.volume.tags | length ) == 2
- gp3_volume.volume.tags["ResourcePrefix"] == "{{ resource_prefix }}"
- name: Read volume information to validate throughput
ec2_vol_info:
filters:
volume-id: "{{ gp3_volume.volume_id }}"
register: verify_throughput
- name: throughput must be equal to 130
assert:
that:
- v.throughput == 130
vars:
v: "{{ verify_throughput.volumes[0] }}"
- name: print out facts
debug:
var: vol_facts
- name: Read volume information to validate throughput
ec2_vol_info:
filters:
volume-id: "{{ gp3_volume.volume_id }}"
register: verify_throughput
- name: throughput must be equal to 130
assert:
that:
- v.throughput == 130
vars:
v: "{{ verify_throughput.volumes[0] }}"
- name: print out facts
debug:
var: vol_facts
- name: increase throughput
ec2_vol:
volume_size: 70
zone: "{{ availability_zone }}"
volume_type: gp3
throughput: 131
modify_volume: yes
name: "GP3-TEST-{{ resource_prefix }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: gp3_volume
- name: check that throughput has changed
assert:
that:
- gp3_volume.changed
- "'create_time' in gp3_volume.volume"
- "'id' in gp3_volume.volume"
- "'size' in gp3_volume.volume"
- gp3_volume.volume.size == 70
- "'volume_type' in gp3_volume"
- gp3_volume.volume_type == 'gp3'
- "'iops' in gp3_volume.volume"
- gp3_volume.volume.iops == 3001
- "'throughput' in gp3_volume.volume"
- gp3_volume.volume.throughput == 131
# Multi-Attach disk
- name: create disk with multi-attach enabled
ec2_vol:
volume_size: 4
volume_type: io1
iops: 102
zone: "{{ availability_zone }}"
multi_attach: yes
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: multi_attach_disk
- name: check volume creation
assert:
that:
- multi_attach_disk.changed
- "'volume' in multi_attach_disk"
- multi_attach_disk.volume.multi_attach_enabled
- name: attach existing volume to an instance
ec2_vol:
id: "{{ multi_attach_disk.volume_id }}"
instance: "{{ test_instance.instance_ids[0] }}"
device_name: /dev/sdk
delete_on_termination: no
register: vol_attach_result
- name: create another ec2 instance
ec2_instance:
name: "{{ instance_name }}-2"
vpc_subnet_id: "{{ testing_subnet.subnet.id }}"
instance_type: t3.nano
image_id: "{{ ec2_ami_image }}"
tags:
ResourcePrefix: "{{ resource_prefix }}"
register: test_instance_2
- name: check task return attributes
assert:
that:
- test_instance_2.changed
- name: attach existing volume to second instance
ec2_vol:
id: "{{ multi_attach_disk.volume_id }}"
instance: "{{ test_instance_2.instance_ids[0] }}"
device_name: /dev/sdg
delete_on_termination: no
register: vol_attach_result
- name: check task return attributes
assert:
that:
- vol_attach_result.changed
- "'volume' in vol_attach_result"
- vol_attach_result.volume.attachment_set | length == 2
- 'test_instance.instance_ids[0] in vol_attach_result.volume.attachment_set | map(attribute="instance_id") | list'
- 'test_instance_2.instance_ids[0] in vol_attach_result.volume.attachment_set | map(attribute="instance_id") | list'
# ==== Cleanup ============================================================
always:
- name: Describe the instance before we delete it
ec2_instance_info:
instance_ids:
- "{{ item }}"
ignore_errors: yes
with_items:
- "{{ test_instance.instance_ids[0] }}"
- "{{ test_instance_2.instance_ids[0] }}"
register: pre_delete
- debug:
var: pre_delete
- name: delete test instance
ec2_instance:
instance_ids:
- "{{ item }}"
state: terminated
with_items:
- "{{ test_instance.instance_ids[0] }}"
- "{{ test_instance_2.instance_ids[0] }}"
ignore_errors: yes
- name: delete volumes
ec2_vol:
id: "{{ item.volume_id }}"
state: absent
ignore_errors: yes
with_items:
- "{{ volume1 }}"
- "{{ volume2 }}"
- "{{ volume3 }}"
- "{{ new_vol_attach_result }}"
- "{{ attach_new_vol_from_snapshot_result }}"
- "{{ dot_volume }}"
- "{{ gp3_volume }}"
- "{{ multi_attach_disk }}"
- name: delete snapshot
ec2_snapshot:
snapshot_id: "{{ vol1_snapshot.snapshot_id }}"
state: absent
ignore_errors: yes
- name: delete test subnet
ec2_vpc_subnet:
vpc_id: "{{ testing_vpc.vpc.id }}"
cidr: "{{ subnet_cidr }}"
state: absent
ignore_errors: yes
- name: delete test VPC
ec2_vpc_net:
name: "{{ vpc_name }}"
cidr_block: "{{ vpc_cidr }}"
state: absent
ignore_errors: yes