turbot/terraform_gcp_compliance

Query: compute_instance_with_no_default_service_account

Usage

powerpipe query terraform_gcp_compliance.query.compute_instance_with_no_default_service_account

Steampipe Tables

SQL

select
address as resource,
case
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is null then 'skip'
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is not null then 'skip'
when (attributes_std -> 'service_account') is not null and (attributes_std -> 'service_account' ->> 'email') is null then 'alarm'
when (attributes_std ->> 'name') like 'gke-%' and (attributes_std -> 'service_account' ->> 'email') like '%-compute@developer.gserviceaccount.com' then 'ok'
when (attributes_std -> 'service_account' ->> 'email') not like '%-compute@developer.gserviceaccount.com' then 'ok'
else 'alarm'
end status,
split_part(address, '.', 2) || case
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is null then ' no service account configured'
when (attributes_std -> 'service_account') is null and (attributes_std -> 'source_instance_template') is not null then ' has no service account in the instance template'
when (attributes_std -> 'service_account') is not null and (attributes_std -> 'service_account' ->> 'email') is null then ' does not have email configured in service account'
when (attributes_std ->> 'name') like 'gke-%' then ' configured to use default service account'
when (attributes_std -> 'service_account' ->> 'email') not like '%-compute@developer.gserviceaccount.com' then ' not use default service account'
else ' use default service account'
end || '.' reason
, path || ':' || start_line
from
terraform_resource
where
type in ('google_compute_instance', 'google_compute_instance_from_template', 'google_compute_instance_template');

Controls

The query is being used by the following controls: