Add delete_on_termination to all EC2 root volumes (#44818)

Not terminating volumes on instance deletion causes
unwanted costs
This commit is contained in:
Will Thames 2018-08-31 00:31:05 +10:00 committed by Ryan Brown
parent 3c6c7bae9d
commit 0c22c0cefb
7 changed files with 33 additions and 2 deletions

View file

@ -12,6 +12,9 @@
image_id: "{{ ec2_ami_image[aws_region] }}"
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
- device_name: /dev/sdb
ebs:
volume_size: 20

View file

@ -18,6 +18,10 @@
cpu_options:
core_count: 1
threads_per_core: 1
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
<<: *aws_connection_info
register: instance_creation
@ -38,6 +42,10 @@
TestId: "{{ resource_prefix }}"
vpc_subnet_id: "{{ testing_subnet_a.subnet.id }}"
instance_type: c4.large
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
cpu_options:
core_count: 1
threads_per_core: 2

View file

@ -14,6 +14,10 @@
TestId: "{{ resource_prefix }}"
security_groups: "{{ sg.group_id }}"
instance_type: t2.micro
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
<<: *aws_connection_info
register: in_default_vpc
- name: Terminate instance

View file

@ -37,6 +37,10 @@
availability_zone: '{{ aws_region }}b'
tags:
TestId: "{{ resource_prefix }}"
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
instance_type: t2.micro
<<: *aws_connection_info
register: in_test_vpc

View file

@ -32,11 +32,15 @@
- name: Make instance with an instance_role
ec2_instance:
name: "{{ resource_prefix }}-test-default-vpc"
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image[aws_region] }}"
security_groups: "{{ sg.group_id }}"
instance_type: t2.micro
instance_role: "{{ resource_prefix }}-test-policy"
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
<<: *aws_connection_info
register: instance_with_role
@ -46,7 +50,7 @@
- name: Update instance with new instance_role
ec2_instance:
name: "{{ resource_prefix }}-test-default-vpc"
name: "{{ resource_prefix }}-test-instance-role"
image_id: "{{ ec2_ami_image[aws_region] }}"
security_groups: "{{ sg.group_id }}"
instance_type: t2.micro

View file

@ -22,6 +22,10 @@
source_dest_check: false
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
instance_type: t2.micro
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
<<: *aws_connection_info
register: in_test_vpc

View file

@ -16,6 +16,10 @@
vpc_subnet_id: "{{ testing_subnet_b.subnet.id }}"
termination_protection: true
instance_type: t2.micro
volumes:
- device_name: /dev/sda1
ebs:
delete_on_termination: true
<<: *aws_connection_info
register: in_test_vpc
- name: Try to terminate the instance