From 136d050e37f89a86a87ab5218851997c889934d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20W=C3=BCrbach?= Date: Thu, 21 Dec 2023 14:57:56 +0100 Subject: [PATCH] chore: add docs and lint targets --- .github/workflows/ci.yaml | 7 +++++++ .gitignore | 14 ++++++++++++++ .tflint.hcl | 10 ++++++++++ Makefile | 14 ++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 .gitignore create mode 100644 .tflint.hcl diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7992f7e..5159c06 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -37,3 +37,10 @@ jobs: - name: Terraform Validate run: make validate + + - uses: terraform-linters/setup-tflint@v4 + with: + tflint_version: v0.49.0 + + - name: Lint + run: make lint diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..feec49b --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +.idea +.terraform +.terraform.lock.hcl +*.tfstate +*.tfstate.* +*.tfplan +*.terraformrc +*.tfvars +terraform.rc +*.json +.DS_Store +*.bkp +*.dtmp +.source diff --git a/.tflint.hcl b/.tflint.hcl new file mode 100644 index 0000000..bb66fff --- /dev/null +++ b/.tflint.hcl @@ -0,0 +1,10 @@ +plugin "terraform" { + enabled = true + preset = "recommended" +} + +plugin "google" { + enabled = true + version = "0.26.0" + source = "github.com/terraform-linters/tflint-ruleset-google" +} diff --git a/Makefile b/Makefile index 684cc71..e6b3043 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ TF_DIRS = $(patsubst %/main.tf, %, $(shell find . -type d -name .terraform -prune -o -name 'main.tf' -print)) VALIDATE_TF_DIRS = $(addprefix validate-,$(TF_DIRS)) +LINT_TF_DIRS = $(addprefix lint-,$(TF_DIRS)) DOCS_TF_DIRS = $(addprefix docs-,$(TF_DIRS)) # Generate docs for a terraform directories @@ -30,3 +31,16 @@ $(VALIDATE_TF_DIRS): validate-%: # Validate all terraform directories validate: $(VALIDATE_TF_DIRS) @echo "All validated" + +# Lint a terraform directories +$(LINT_TF_DIRS): lint-%: + @echo "Lint $*" + tflint --config "$(PWD)/.tflint.hcl" --chdir="$*" + +# Initialize tflint +lint-init: + tflint --init + +# Lint all terraform directories +lint: lint-init $(LINT_TF_DIRS) + @echo "All linted"