turbot/steampipe-mod-terraform-gcp-compliance

Control: GCP SQL instance should not be publicly accessible

Description

This control checks whether the GCP SQL instance is publicly accessible.

Usage

Run the control in your terminal:

powerpipe control run terraform_gcp_compliance.control.sql_instance_publicly_accessible

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run terraform_gcp_compliance.control.sql_instance_publicly_accessible --share

SQL

This control uses a named query:

select
address as resource,
case
when (attributes_std -> 'settings') is null then 'ok'
when (attributes_std -> 'settings' -> 'ip_configuration' -> 'dynamic' -> 'authorized_networks') is not null then 'alarm'
when (attributes_std -> 'settings' -> 'ip_configuration' -> 'dynamic' -> 'authorized_networks') is not null and (attributes_std -> 'settings' -> 'ip_configuration' -> 'authorized_networks' ->> 'value') is null then 'ok'
when (attributes_std -> 'settings' -> 'ip_configuration' -> 'authorized_networks' ->> 'value') like '%/0' then 'alarm'
else 'ok'
end as status,
split_part(address, '.', 2) || case
when (attributes_std -> 'settings') is null then ' no settings found'
when (attributes_std -> 'settings' -> 'ip_configuration' -> 'dynamic' -> 'authorized_networks') is null then ' authorized network set in dynamic mode'
when (attributes_std -> 'settings' -> 'ip_configuration' -> 'dynamic' -> 'authorized_networks') is not null and (attributes_std -> 'settings' -> 'ip_configuration' -> 'authorized_networks' ->> 'value') is null then ' authorized network not set'
when (attributes_std -> 'settings' -> 'ip_configuration' -> 'authorized_networks' ->> 'value') like '%/0' then ' publicly accessible'
else ' not publicly accessible'
end || '.' reason
, path || ':' || start_line
from
terraform_resource
where
type = 'google_sql_database_instance';

Tags