Control: Ensure that the 'log_temp_files' database flag for Cloud SQL PostgreSQL instance is set to '0'
Description
PostgreSQL can create a temporary file for actions such as sorting, hashing and temporary query results when these operations exceed work_mem. The log_temp_files flag controls logging names and the file size when it is deleted. Configuring log_temp_files to 0 causes all temporary file information to be logged, while positive values log only files whose size is greater than or equal to the specified number of kilobytes. A value of -1 disables temporary file information logging.
Usage
Run the control in your terminal:
powerpipe control run terraform_gcp_compliance.control.sql_instance_postgresql_log_temp_files_database_flag_0Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run terraform_gcp_compliance.control.sql_instance_postgresql_log_temp_files_database_flag_0 --shareSQL
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_temp_files' and      (attributes_std -> 'settings' -> 'database_flags' ->> 'value') = '0'    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_temp_files'    then ' ''log_temp_files'' database flag not set'    when (attributes_std -> 'settings' -> 'database_flags' ->> 'name') = 'log_temp_files' and      (attributes_std -> 'settings' -> 'database_flags' ->> 'value') = '0'    then ' ''log_temp_files'' database flag set to ''0'''    else ' ''log_temp_files'' database flag not set to ''0'''  end || '.' reason  , path || ':' || start_linefrom  terraform_resourcewhere  type = 'google_sql_database_instance';