Skip to content

Commit

Permalink
feat: validate submodules in pre-commit and ci (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-cart3r authored Sep 17, 2022
1 parent 14db4fd commit 0c76eff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/reusable-static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install -y make
# Configure git to use HTTPS instead of SSH
# ${HOME}/.gitconfig will be mounted to the terraform container
- name: Configure git config
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ repos:
pass_filenames: false
types: [terraform]

- id: terraform_validate_submodules
name: Terraform validate submodules
description: Validates all Terraform configuration files.
entry: make validate-submodules
language: system
pass_filenames: false
types: [terraform]

- id: terraform_docs
name: Generate Docs
description: Generate terraform docs for module
Expand Down
33 changes: 25 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
TERRAFORM_VERSION ?= 1.1.7
TERRAFORM_DOCS_VERSION ?= 0.16.0
TFSEC_VERSION ?= v1.13.2-amd64
CUR_DIR := $(shell pwd)# ${PWD} is incosistent in GitHub Actions
TERRAFORM_VERSION ?= 1.1.7
TERRAFORM_DOCS_VERSION ?= 0.16.0
TFSEC_VERSION ?= v1.13.2-amd64
CUR_DIR := $(shell pwd)# ${PWD} is incosistent in GitHub Actions
SUBMODULES_PREFIX := states

export

clean:
rm -rf .terraform
rm -rf **/.terraform

fmt:
docker run --platform=linux/amd64 \
docker run --rm --platform=linux/amd64 \
-v ${CUR_DIR}:/src \
-w /src \
hashicorp/terraform:${TERRAFORM_VERSION} fmt -recursive
Expand All @@ -28,7 +29,7 @@ docs:
/terraform-docs

init-no-backend:
docker run --platform=linux/amd64 \
docker run --rm --platform=linux/amd64 \
-v ${CUR_DIR}:/src \
-v ${HOME}/.ssh:/root/.ssh/ \
-v ${HOME}/.gitconfig:/root/.gitconfig \
Expand All @@ -37,7 +38,23 @@ init-no-backend:
-backend=false

validate: clean init-no-backend
docker run --platform=linux/amd64 \
docker run --rm --platform=linux/amd64 \
-v ${CUR_DIR}:/src \
-w /src \
hashicorp/terraform:${TERRAFORM_VERSION} validate

validate-submodules:
for submodule in ${SUBMODULES_PREFIX}/*; do\
echo "Validating $${submodule}..."; \
docker run --rm --platform=linux/amd64 \
-v ${CUR_DIR}:/src \
-v ${HOME}/.ssh:/root/.ssh/ \
-v ${HOME}/.gitconfig:/root/.gitconfig \
-w /src/$${submodule} \
hashicorp/terraform:${TERRAFORM_VERSION} init \
-backend=false; \
docker run --rm --platform=linux/amd64 \
-v ${CUR_DIR}:/src \
-w /src/$${submodule} \
hashicorp/terraform:${TERRAFORM_VERSION} validate; \
done
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# terraform-module-template
# terraform-module-state-machine
Current preferred layout and tooling for terraform modules

## Examples
Expand Down

0 comments on commit 0c76eff

Please sign in to comment.