turbot/steampipe-mod-terraform-gcp-compliance

Control: Ensure that the 'log_min_duration_statement' database flag for Cloud SQL PostgreSQL instance is set to '-1' (disabled)

Description

The log_min_duration_statement flag defines the minimum amount of execution time of a statement in milliseconds where the total duration of the statement is logged. Ensure that log_min_duration_statement is disabled, i.e., a value of -1 is set.

Usage

Run the control in your terminal:

powerpipe control run terraform_gcp_compliance.control.sql_instance_postgresql_log_min_duration_statement_database_flag_disabled

Snapshot and share results via Turbot Pipes:

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

SQL

This control uses a named query:

select
address as resource,
case
when coalesce(trim((attributes_std ->> 'database_version')), '') = '' then 'alarm'
when (attributes_std ->> 'database_version') not like 'POSTGRES%' then 'skip'
when (attributes_std -> 'settings' -> 'database_flags' ->> 'name') = 'log_min_duration_statement' and
(attributes_std -> 'settings' -> 'database_flags' ->> 'value') = '-1'
then 'ok'
else 'alarm'
end as status,
split_part(address, '.', 2) || case
when coalesce(trim((attributes_std ->> 'database_version')), '') = ''
then ' ''database_version'' is not defined'
when (attributes_std ->> 'database_version') not like 'POSTGRES%'
then ' not a PostgreSQL database'
when (attributes_std -> 'settings') is null then ' ''settings'' is not defined'
when (attributes_std -> 'settings' -> 'database_flags') is null then ' ''settings.database_flags'' is not defined'
when coalesce(trim((attributes_std -> 'settings' -> 'database_flags' ->> 'name')), '') = ''
then ' ''settings.database_flags.name'' is not defined'
when coalesce(trim((attributes_std -> 'settings' -> 'database_flags' ->> 'value')), '') = ''
then ' ''settings.database_flags.value'' is not defined'
when (attributes_std -> 'settings' -> 'database_flags' ->> 'name') <> 'log_min_duration_statement'
then ' ''log_min_duration_statement'' database flag not set'
when (attributes_std -> 'settings' -> 'database_flags' ->> 'name') = 'log_min_duration_statement' and
(attributes_std -> 'settings' -> 'database_flags' ->> 'value') = '-1'
then ' ''log_min_duration_statement'' database flag set to disabled'
else ' ''log_min_duration_statement'' database flag set to enabled'
end || '.' reason
, path || ':' || start_line
from
terraform_resource
where
type = 'google_sql_database_instance';

Tags