turbot/steampipe-mod-terraform-gcp-compliance

Control: KMS Crypto keys should have prevent destroy enabled

Description

CryptoKeys cannot be deleted from Google Cloud Platform. Destroying a Terraform-managed CryptoKey will remove it from state and delete all CryptoKeyVersions, rendering the key unusable, but will not delete the resource from the project. When Terraform destroys these keys, any data previously encrypted with these keys will be irrecoverable. For this reason, it is strongly recommended that you add lifecycle hooks to the resource to prevent accidental destruction.

Usage

Run the control in your terminal:

powerpipe control run terraform_gcp_compliance.control.kms_key_prevent_destroy_enabled

Snapshot and share results via Turbot Pipes:

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

SQL

This control uses a named query:

select
address as resource,
case
when (lifecycle ->> 'prevent_destroy')::bool then 'ok'
else 'alarm'
end as status,
split_part(address, '.', 2) || case
when (lifecycle ->> 'prevent_destroy')::bool then ' prevent destroy enabled'
else ' prevent destroy disabled'
end || '.' reason
, path || ':' || start_line
from
terraform_resource
where
type = 'google_kms_crypto_key';

Tags