turbot/steampipe-mod-terraform-aws-compliance

Control: VPC security groups should be associated with at least one ENI

Description

This rule ensures the security groups are attached to an Amazon Elastic Compute Cloud (Amazon EC2) instance or to an ENI. This rule helps monitor unused security groups in the inventory and the management of your environment.

Usage

Run the control in your terminal:

powerpipe control run terraform_aws_compliance.control.vpc_security_group_associated_to_eni

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run terraform_aws_compliance.control.vpc_security_group_associated_to_eni --share

SQL

This control uses a named query:

select
address as resource,
case
when name in (select split_part((jsonb_array_elements(attributes_std -> 'security_groups')::text), '.', 2) from terraform_resource where type = 'aws_network_interface') then 'ok'
else 'alarm'
end status,
split_part(address, '.', 2) || case
when name in (select split_part((jsonb_array_elements(attributes_std -> 'security_groups')::text), '.', 2) from terraform_resource where type = 'aws_network_interface') then ' has attached ENI(s)'
else ' has no attached ENI(s)'
end || '.' as reason
, path || ':' || start_line
from
terraform_resource
where
type = 'aws_security_group';

Tags