Skip to content

Commit 087d391

Browse files
committed
new pre-comit stuff
1 parent b4bf7bb commit 087d391

File tree

7 files changed

+170
-33
lines changed

7 files changed

+170
-33
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @rhythmictech/engineering

.github/workflows/check.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
name: pre-commit-check
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- develop
8+
pull_request:
9+
10+
jobs:
11+
build:
12+
runs-on: macOS-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
ref: ${{ github.head_ref }}
17+
- name: Install prerequisites
18+
run: ./bin/install-macos.sh
19+
- name: initialize Terraform
20+
run: terraform init --backend=false
21+
- uses: actions/cache@v1
22+
with:
23+
path: ~/.cache/pre-commit
24+
key: pre-commit|${{ hashFiles('.pre-commit-config.yaml') }}
25+
restore-keys: |
26+
pre-commit
27+
- name: pre-commit run all
28+
run: |
29+
pre-commit run -a
30+
env:
31+
AWS_DEFAULT_REGION: us-east-1
32+
SKIP: terraform_tflint_deep,no-commit-to-branch
33+
- uses: stefanzweifel/git-auto-commit-action@v4
34+
if: ${{ failure() }}
35+
with:
36+
commit_message: Apply automatic changes
37+
commit_options: "--no-verify"
38+
# Optional commit user and author settings
39+
commit_user_name: Linter Bot
40+
commit_user_email: noreply@rhythmictech.com
41+
commit_author: Linter Bot <actions@github.com>

.pre-commit-config.yaml

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
1-
---
21
repos:
3-
- repo: git://github.com/antonbabenko/pre-commit-terraform
4-
rev: v1.24.0
5-
hooks:
6-
- id: terraform_fmt
7-
- id: terraform_docs
8-
- repo: https://github.com/pre-commit/pre-commit-hooks
9-
rev: v2.4.0
10-
hooks:
11-
- id: end-of-file-fixer
12-
- id: trailing-whitespace
13-
- id: no-commit-to-branch
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.31.0
4+
hooks:
5+
- id: terraform_docs
6+
always_run: true
7+
args:
8+
- --args=--sort-by-required
9+
- id: terraform_fmt
10+
- id: terraform_tflint
11+
alias: terraform_tflint_deep
12+
name: terraform_tflint_deep
13+
args:
14+
- --args=--deep
15+
- id: terraform_tflint
16+
alias: terraform_tflint_nocreds
17+
name: terraform_tflint_nocreds
18+
- id: terraform_tfsec
19+
- repo: local
20+
hooks:
21+
- id: terraform_validate
22+
name: terraform_validate
23+
entry: |
24+
bash -c '
25+
AWS_DEFAULT_REGION=us-east-1
26+
declare -a DIRS
27+
for FILE in "$@"
28+
do
29+
DIRS+=($(dirname "$FILE"))
30+
done
31+
for DIR in $(printf "%s\n" "${DIRS[@]}" | sort -u)
32+
do
33+
cd $(dirname "$FILE")
34+
terraform init --backend=false
35+
terraform validate .
36+
done
37+
'
38+
language: system
39+
verbose: true
40+
files: \.tf(vars)?$
41+
exclude: examples
42+
- repo: https://github.com/pre-commit/pre-commit-hooks
43+
rev: v3.0.0
44+
hooks:
45+
- id: check-case-conflict
46+
- id: check-json
47+
- id: check-merge-conflict
48+
- id: check-symlinks
49+
- id: check-yaml
50+
args:
51+
- --unsafe
52+
- id: end-of-file-fixer
53+
- id: trailing-whitespace
54+
- id: mixed-line-ending
55+
args:
56+
- --fix=lf
57+
- id: no-commit-to-branch
58+
- id: pretty-format-json
59+
args:
60+
- --autofix
61+
- --top-keys=name,Name
62+
- id: trailing-whitespace
63+
args:
64+
- --markdown-linebreak-ext=md
65+
exclude: README.md

.tflint.hcl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
config {
2+
module = true
3+
deep_check = false
4+
}
5+
6+
rule "terraform_deprecated_interpolation" {
7+
enabled = true
8+
}
9+
10+
rule "terraform_unused_declarations" {
11+
enabled = true
12+
}
13+
14+
rule "terraform_comment_syntax" {
15+
enabled = true
16+
}
17+
18+
rule "terraform_documented_outputs" {
19+
enabled = true
20+
}
21+
22+
rule "terraform_documented_variables" {
23+
enabled = true
24+
}
25+
26+
rule "terraform_typed_variables" {
27+
enabled = true
28+
}
29+
30+
rule "terraform_module_pinned_source" {
31+
enabled = true
32+
}
33+
34+
rule "terraform_naming_convention" {
35+
enabled = true
36+
format = "snake_case"
37+
}
38+
39+
rule "terraform_required_version" {
40+
enabled = true
41+
}
42+
43+
rule "terraform_required_providers" {
44+
enabled = true
45+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# terraform-aws-backend
22

3-
[![](https://github.com/rhythmictech/terraform-aws-backend/workflows/check/badge.svg)](https://github.com/rhythmictech/terraform-aws-backend/actions)
3+
[![](https://github.com/rhythmictech/terraform-aws-backend/workflows/pre-commit-check/badge.svg)](https://github.com/rhythmictech/terraform-aws-backend/actions) <a href="https://twitter.com/intent/follow?screen_name=RhythmicTech"><img src="https://img.shields.io/twitter/follow/RhythmicTech?style=social&logo=RhythmicTech" alt="follow on Twitter"></a>
44

55
Creates a backend S3 bucket and DynamoDB table for managing Terraform state. Useful for bootstrapping a new
66
environment. This module supports cross-account state management, using a centralized account that holds the S3 bucket and KMS key.

bin/install-macos.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
echo 'installing brew packages'
4+
brew update
5+
brew tap liamg/tfsec
6+
brew install tfenv tflint terraform-docs pre-commit liamg/tfsec/tfsec coreutils
7+
brew upgrade tfenv tflint terraform-docs pre-commit liamg/tfsec/tfsec coreutils
8+
9+
echo 'installing pre-commit hooks'
10+
pre-commit install
11+
12+
echo 'setting pre-commit hooks to auto-install on clone in the future'
13+
git config --global init.templateDir ~/.git-template
14+
pre-commit init-templatedir ~/.git-template
15+
16+
echo 'installing terraform with tfenv'
17+
tfenv install min-required
18+
tfenv use min-required

0 commit comments

Comments
 (0)