Skip to content

Instantly share code, notes, and snippets.

@rinx
Created August 24, 2024 11:01
Show Gist options
  • Save rinx/2782343134accb63204f62ea76262e53 to your computer and use it in GitHub Desktop.
Save rinx/2782343134accb63204f62ea76262e53 to your computer and use it in GitHub Desktop.
ast-grep rule for detecting terraform resources that does not have `project` attribute.
# yaml-language-server: $schema=https://raw.githubusercontent.com/ast-grep/ast-grep/main/schemas/rule.json
id: google-resource-no-project-attr
message: All google resource should have `project` attribute.
severity: warning
language: terraform
rule:
kind: block
all:
- has:
kind: identifier
pattern: resource
- has:
kind: string_lit
all:
- has:
kind: template_literal
regex: google_.*
- not:
has:
kind: template_literal
regex: google_service_account_iam_member
- has:
kind: body
not:
has:
kind: attribute
has:
kind: identifier
pattern: project
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment