turbot/steampipe-mod-terraform-azure-compliance

Control: Subnets should be associated with a Network Security Group

Description

This policy denies if a gateway subnet is configured with a network security group. Assigning a network security group to a gateway subnet will cause the gateway to stop functioning.

Usage

Run the control in your terminal:

powerpipe control run terraform_azure_compliance.control.network_security_group_subnet_associated

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run terraform_azure_compliance.control.network_security_group_subnet_associated --share

SQL

This control uses a named query:

with all_subnet as (
select
*
from
terraform_resource
where
type = 'azurerm_subnet'
), network_security_group_association as (
select
*
from
terraform_resource
where
type = 'azurerm_subnet_network_security_group_association'
)
select
a.address as resource,
case
when (s.attributes_std ->> 'subnet_id') is not null then 'ok'
else 'alarm'
end as status,
split_part(a.address, '.', 2) || case
when (s.attributes_std ->> 'subnet_id') is not null then ' associated with subnet'
else ' not associated with subnet'
end || '.' reason
, a.path || ':' || a.start_line
from
all_subnet as a
left join network_security_group_association as s on a.name = ( split_part((s.attributes_std ->> 'subnet_id'), '.', 2));

Tags