turbot/steampipe-mod-aws-compliance

Control: Attached EBS volumes should have delete on termination enabled

Description

This rule ensures that AWS Elastic Block Store volumes that are attached to AWS Elastic Compute Cloud (AWS EC2) instances are marked for deletion when an instance is terminated.

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.ebs_attached_volume_delete_on_termination_enabled

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run aws_compliance.control.ebs_attached_volume_delete_on_termination_enabled --share

SQL

This control uses a named query:

select
arn as resource,
case
when state != 'in-use' then 'skip'
when attachment ->> 'DeleteOnTermination' = 'true' then 'ok'
else 'alarm'
end as status,
case
when state != 'in-use' then title || ' not attached to EC2 instance.'
when attachment ->> 'DeleteOnTermination' = 'true' then title || ' attached to ' || (attachment ->> 'InstanceId') || ', delete on termination enabled.'
else title || ' attached to ' || (attachment ->> 'InstanceId') || ', delete on termination disabled.'
end as reason
, region, account_id
from
aws_ebs_volume
left join jsonb_array_elements(attachments) as attachment on true;

Tags