From 9937ab0da17d31ae032559a1b3071460ffd60778 Mon Sep 17 00:00:00 2001 From: Clarissa Borges Date: Thu, 12 Dec 2024 10:02:58 -0300 Subject: [PATCH] Add missing workflows for Terraform and Open Source README --- .github/workflows/ci.yaml | 75 ++++++++++++++++++++ .github/workflows/dynamic-readme.yml | 17 +++++ .terraform-docs.yml | 11 +++ elasticache-redis/auth-token/makefile | 17 +++-- elasticache-redis/replication-group/makefile | 17 +++-- kafka/makefile | 19 +++-- makefile | 4 ++ makefiles/terraform.mk | 19 +++-- rds-postgres/admin-login/makefile | 17 +++-- rds-postgres/cloudwatch-alarms/makefile | 17 +++-- rds-postgres/parameter-group/makefile | 17 +++-- rds-postgres/primary-instance/makefile | 17 +++-- rds-postgres/rds-postgres-login/makefile | 17 +++-- rds-postgres/replica/makefile | 17 +++-- security-group-ingress/makefile | 67 +++++++++++++++++ security-group/makefile | 19 +++-- 16 files changed, 320 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/dynamic-readme.yml create mode 100644 .terraform-docs.yml create mode 100644 security-group-ingress/makefile diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..3e9125b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,75 @@ +name: Terraform +on: +- push + +jobs: + checkfmt: + name: Format + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Check format + run: make all/checkfmt + + validate: + name: Validate + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Validate + run: make all/validate + + docs: + name: Docs + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Platform Docs + uses: terraform-docs/gh-actions@v1.0.0 + with: + git-push: true + find-dir: platform + output-file: README.md + output-method: inject + working-dir: . + + - name: AWS Docs + uses: terraform-docs/gh-actions@v1.0.0 + with: + git-push: true + find-dir: aws + output-file: README.md + output-method: inject + working-dir: . + + lint: + name: Lint + runs-on: ubuntu-22.04 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + + - name: Setup TFLint + uses: terraform-linters/setup-tflint@v4 + with: + tflint_version: v0.44.1 + + - name: Lint + run: make all/lint + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/dynamic-readme.yml b/.github/workflows/dynamic-readme.yml new file mode 100644 index 0000000..41bb5db --- /dev/null +++ b/.github/workflows/dynamic-readme.yml @@ -0,0 +1,17 @@ +name: update-templates + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + update-templates: + permissions: + contents: write + pull-requests: write + pages: write + uses: thoughtbot/templates/.github/workflows/dynamic-readme.yaml@main + secrets: + token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.terraform-docs.yml b/.terraform-docs.yml new file mode 100644 index 0000000..b41d4bd --- /dev/null +++ b/.terraform-docs.yml @@ -0,0 +1,11 @@ +formatter: markdown + +output: + file: README.md + mode: inject + +settings: + hide-empty: true + + # Avoid reading locked version from running validate + lockfile: false diff --git a/elasticache-redis/auth-token/makefile b/elasticache-redis/auth-token/makefile index 2ba5cfc..55db0e4 100644 --- a/elasticache-redis/auth-token/makefile +++ b/elasticache-redis/auth-token/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/elasticache-redis/replication-group/makefile b/elasticache-redis/replication-group/makefile index 2ba5cfc..55db0e4 100644 --- a/elasticache-redis/replication-group/makefile +++ b/elasticache-redis/replication-group/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/kafka/makefile b/kafka/makefile index d0009b8..55db0e4 100644 --- a/kafka/makefile +++ b/kafka/makefile @@ -1,4 +1,5 @@ -TFLINTRC := ../.tflint.hcl +TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/makefile b/makefile index 3ea0f82..9e13b32 100644 --- a/makefile +++ b/makefile @@ -5,6 +5,7 @@ export TF_CLI_CONFIG_FILE := $(CURDIR)/.terraformrc MODULES := $(foreach main,$(wildcard */*/main.tf),$(subst /main.tf,,$(main))) MODULEMAKEFILES := $(foreach module,$(MODULES),$(module)/makefile) MAKEMODULES := $(foreach module,$(MODULES),$(module)/default) +SUBMODULESCOMMAND ?= default CLEANMODULES := $(foreach module,$(MODULES),$(module)/clean) .PHONY: default @@ -53,3 +54,6 @@ clean: $(CLEANMODULES) layers/%/package.zip: layers/%/* $(MAKE) -C layers/"$*" + +all/%: + $(MAKE) modules SUBMODULESCOMMAND=$(*) \ No newline at end of file diff --git a/makefiles/terraform.mk b/makefiles/terraform.mk index 2ba5cfc..95cdf1e 100644 --- a/makefiles/terraform.mk +++ b/makefiles/terraform.mk @@ -1,5 +1,6 @@ -TFLINTRC := ../../.tflint.hcl MODULEFILES := $(wildcard *.tf) +TFLINTRC ? =../../.tflint.hcl +TFDOCSRC ? =../../.terraform-docs.yml .PHONY: default default: checkfmt validate docs lint @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/rds-postgres/admin-login/makefile b/rds-postgres/admin-login/makefile index 2ba5cfc..55db0e4 100644 --- a/rds-postgres/admin-login/makefile +++ b/rds-postgres/admin-login/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/rds-postgres/cloudwatch-alarms/makefile b/rds-postgres/cloudwatch-alarms/makefile index 2ba5cfc..55db0e4 100644 --- a/rds-postgres/cloudwatch-alarms/makefile +++ b/rds-postgres/cloudwatch-alarms/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/rds-postgres/parameter-group/makefile b/rds-postgres/parameter-group/makefile index 2ba5cfc..55db0e4 100644 --- a/rds-postgres/parameter-group/makefile +++ b/rds-postgres/parameter-group/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/rds-postgres/primary-instance/makefile b/rds-postgres/primary-instance/makefile index 2ba5cfc..55db0e4 100644 --- a/rds-postgres/primary-instance/makefile +++ b/rds-postgres/primary-instance/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/rds-postgres/rds-postgres-login/makefile b/rds-postgres/rds-postgres-login/makefile index 2ba5cfc..55db0e4 100644 --- a/rds-postgres/rds-postgres-login/makefile +++ b/rds-postgres/rds-postgres-login/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/rds-postgres/replica/makefile b/rds-postgres/replica/makefile index 2ba5cfc..55db0e4 100644 --- a/rds-postgres/replica/makefile +++ b/rds-postgres/replica/makefile @@ -1,4 +1,5 @@ TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/security-group-ingress/makefile b/security-group-ingress/makefile new file mode 100644 index 0000000..55db0e4 --- /dev/null +++ b/security-group-ingress/makefile @@ -0,0 +1,67 @@ +TFLINTRC := ../../.tflint.hcl +TFDOCSRC ?= ../../.terraform-docs.yml +MODULEFILES := $(wildcard *.tf) + +.PHONY: default +default: checkfmt validate docs lint + +.PHONY: checkfmt +checkfmt: .fmt + +.PHONY: fmt +fmt: $(MODULEFILES) + terraform fmt + @touch .fmt + +.PHONY: validate +validate: .validate + +.PHONY: docs +docs: README.md + +.PHONY: lint +lint: .lint + +.lint: $(MODULEFILES) .lintinit + tflint --config=$(TFLINTRC) + @touch .lint + +.lintinit: $(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all + @touch .lintinit + +README.md: $(MODULEFILES) + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md + +.fmt: $(MODULEFILES) + terraform fmt -check + @touch .fmt + +.PHONY: init +init: .init + +.init: versions.tf .dependencies + terraform init -backend=false + @touch .init + +.validate: .init $(MODULEFILES) $(wildcard *.tf.example) + echo | cat - $(wildcard *.tf.example) > test.tf + if AWS_DEFAULT_REGION=us-east-1 terraform validate; then \ + rm test.tf; \ + touch .validate; \ + else \ + rm test.tf; \ + false; \ + fi + +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + +.PHONY: clean +clean: + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate diff --git a/security-group/makefile b/security-group/makefile index 2ba5cfc..3d530cd 100644 --- a/security-group/makefile +++ b/security-group/makefile @@ -1,4 +1,5 @@ -TFLINTRC := ../../.tflint.hcl +TFLINTRC : =../../.tflint.hcl +TFDOCSRC ? =../../.terraform-docs.yml MODULEFILES := $(wildcard *.tf) .PHONY: default @@ -26,11 +27,11 @@ lint: .lint @touch .lint .lintinit: $(TFLINTRC) - tflint --init --config=$(TFLINTRC) + tflint --init --config=$(TFLINTRC) --call-module-type=all @touch .lintinit README.md: $(MODULEFILES) - terraform-docs markdown table . --output-file README.md + terraform-docs --config "$(TFDOCSRC)" markdown table . --output-file README.md .fmt: $(MODULEFILES) terraform fmt -check @@ -39,7 +40,7 @@ README.md: $(MODULEFILES) .PHONY: init init: .init -.init: versions.tf +.init: versions.tf .dependencies terraform init -backend=false @touch .init @@ -53,6 +54,14 @@ init: .init false; \ fi +.dependencies: *.tf + @grep -ohE \ + "\b(backend|provider|resource|module) ['\"][[:alpha:]][[:alnum:]]*|\bsource *=.*" *.tf | \ + sed "s/['\"]//" | sort | uniq | \ + tee /tmp/initdeps | \ + diff -q .dependencies - >/dev/null 2>&1 || \ + mv /tmp/initdeps .dependencies + .PHONY: clean clean: - rm -rf .fmt .init .lint .lintinit .terraform .terraform.lock.hcl .validate + rm -rf .dependencies .fmt .init .lint .lintinit .terraform* .validate