Skip to content

Commit bd740cc

Browse files
Upgrade to TF 0.13 + more pre-commit hooks & improvements (#4)
* Update pre-commit hooks, remove build-harness, rework docs, remove deps sources and switch to serverless for packaging
1 parent 2a6f538 commit bd740cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+12576
-8791
lines changed

.github/workflows/pre-commit.yml

+155
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
name: Pre-Commit
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
env:
10+
node-version: '14'
11+
python-version: '3.8'
12+
function-source-code-dir: ./source-code
13+
packaged-function-dir: ./packaged
14+
15+
jobs:
16+
packageLambda:
17+
name: Package lambda function
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Install Node.js & npm
23+
uses: actions/setup-node@v2
24+
with:
25+
node-version: ${{env.node-version}}
26+
check-latest: true
27+
- name: Install Python 3
28+
uses: actions/setup-python@v2
29+
with:
30+
python-version: ${{env.python-version}}
31+
- name: Install Serverless Framework
32+
run: npm install -g serverless
33+
- name: Install Node.js dependencies
34+
working-directory: ${{env.function-source-code-dir}}
35+
run: npm install
36+
- name: Create artifacts directory
37+
run: mkdir -p ${{env.packaged-function-dir}}
38+
- name: Package lambda function
39+
working-directory: ${{env.function-source-code-dir}}
40+
run: sls package --package ${{env.packaged-function-dir}}
41+
- name: Upload packaged lambda function to artifacts
42+
uses: actions/upload-artifact@v2
43+
with:
44+
name: lambda
45+
path: ${{env.packaged-function-dir}}/*.zip
46+
47+
# Min Terraform version(s)
48+
getDirectories:
49+
name: Get root directories
50+
runs-on: ubuntu-latest
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v2
54+
- name: Install Python
55+
uses: actions/setup-python@v2
56+
- name: Build matrix
57+
id: matrix
58+
run: |
59+
DIRS=$(python -c "import json; import glob; print(json.dumps([x.replace('/versions.tf', '') for x in glob.glob('./**/versions.tf', recursive=True)]))")
60+
echo "::set-output name=directories::$DIRS"
61+
outputs:
62+
directories: ${{ steps.matrix.outputs.directories }}
63+
64+
preCommitMinVersions:
65+
name: Min TF validate
66+
needs:
67+
- getDirectories
68+
- packageLambda
69+
runs-on: ubuntu-latest
70+
strategy:
71+
matrix:
72+
directory: ${{ fromJson(needs.getDirectories.outputs.directories) }}
73+
steps:
74+
- name: Checkout
75+
uses: actions/checkout@v2
76+
- name: Download artifcats (packaged lambda)
77+
uses: actions/download-artifact@v2
78+
with:
79+
name: lambda
80+
- name: Create artifacts directory
81+
run: mkdir -p ${{env.packaged-function-dir}} && cp ./*.zip ${{env.packaged-function-dir}}
82+
- name: Install Python
83+
uses: actions/setup-python@v2
84+
- name: Terraform min/max versions
85+
id: minMax
86+
uses: clowdhaus/[email protected]
87+
with:
88+
directory: ${{ matrix.directory }}
89+
- name: Install Terraform v${{ steps.minMax.outputs.minVersion }}
90+
uses: hashicorp/setup-terraform@v1
91+
with:
92+
terraform_version: ${{ steps.minMax.outputs.minVersion }}
93+
- name: Install pre-commit dependencies
94+
run: pip install pre-commit
95+
- name: Execute pre-commit
96+
# Run only validate pre-commit check on min version supported
97+
if: ${{ matrix.directory != '.' }}
98+
run:
99+
pre-commit run terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*
100+
- name: Execute pre-commit
101+
# Run only validate pre-commit check on min version supported
102+
if: ${{ matrix.directory == '.' }}
103+
run:
104+
pre-commit run terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)
105+
106+
# Max Terraform version
107+
getBaseVersion:
108+
name: Module max TF version
109+
runs-on: ubuntu-latest
110+
steps:
111+
- name: Checkout
112+
uses: actions/checkout@v2
113+
- name: Terraform min/max versions
114+
id: minMax
115+
uses: clowdhaus/[email protected]
116+
outputs:
117+
minVersion: ${{ steps.minMax.outputs.minVersion }}
118+
maxVersion: ${{ steps.minMax.outputs.maxVersion }}
119+
120+
preCommitMaxVersion:
121+
name: Max TF pre-commit
122+
runs-on: ubuntu-latest
123+
needs:
124+
- getBaseVersion
125+
- packageLambda
126+
strategy:
127+
fail-fast: false
128+
matrix:
129+
version:
130+
- ${{ needs.getBaseVersion.outputs.maxVersion }}
131+
steps:
132+
- name: Checkout
133+
uses: actions/checkout@v2
134+
- name: Download artifcats (packaged lambda)
135+
uses: actions/download-artifact@v2
136+
with:
137+
name: lambda
138+
- name: Create artifacts directory
139+
run: mkdir -p ${{env.packaged-function-dir}} && cp ./*.zip ${{env.packaged-function-dir}}
140+
- name: Install Python
141+
uses: actions/setup-python@v2
142+
- name: Install Terraform v${{ matrix.version }}
143+
uses: hashicorp/setup-terraform@v1
144+
with:
145+
terraform_version: ${{ matrix.version }}
146+
- name: Install pre-commit dependencies
147+
run: |
148+
pip install pre-commit
149+
curl -L "$(curl -s https://api.github.com/repos/terraform-docs/terraform-docs/releases/latest | grep -o -E "https://.+?-v0.12\..+?-linux-amd64" | head -n1)" > terraform-docs && chmod +x terraform-docs && sudo mv terraform-docs /usr/bin/
150+
curl -L "$(curl -s https://api.github.com/repos/terraform-linters/tflint/releases/latest | grep -o -E "https://.+?_linux_amd64.zip")" > tflint.zip && unzip tflint.zip && rm tflint.zip && sudo mv tflint /usr/bin/
151+
curl -L "$(curl -s https://api.github.com/repos/tfsec/tfsec/releases/latest | grep -o -E "https://.+?tfsec-linux-amd64")" > tfsec && chmod +x tfsec && sudo mv tfsec /usr/bin/
152+
- name: Execute pre-commit
153+
# Run all pre-commit checks on max version supported
154+
if: ${{ matrix.version == needs.getBaseVersion.outputs.maxVersion }}
155+
run: pre-commit run --color=always --show-diff-on-failure --all-files

.gitignore

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ override.tf.json
3030
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
3131
# example: *tfplan*
3232

33+
# IDE
3334
.idea/
34-
**/generated/
35-
!**/generated/.gitkeep
3635

37-
.build-harness
38-
build-harness
36+
# Serverless directories
37+
.serverless
38+
**/packaged/*
39+
!**/packaged/*.zip
40+
41+
# NodeJS
42+
node_modules/

.pre-commit-config.yaml

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.30.0
3+
rev: v1.48.0
44
hooks:
55
- id: terraform_fmt
6-
- id: terraform_docs_replace
7-
args: ['--with-aggregate-type-defaults', '--dest=docs/terraform.md']
8-
- repo: local
9-
hooks:
10-
- id: build-readme
11-
name: Build README.md
12-
language: system
13-
entry: make readme/sync
14-
types: [file]
15-
files: ^README\.yaml$
6+
- id: terraform_validate
7+
- id: terraform_docs
8+
- id: terraform_tflint
9+
args:
10+
- '--args=--config=__GIT_WORKING_DIR__/.tflint.hcl'
11+
- '--args=--format=compact'
12+
require_serial: true
13+
- id: terraform_tfsec
14+
args:
15+
- '--args=--exclude-downloaded-modules --concise-output'
16+
require_serial: true
17+
exclude: ^examples/
1618
- repo: git://github.com/pre-commit/pre-commit-hooks
17-
rev: v2.5.0
19+
rev: v3.4.0
1820
hooks:
1921
- id: check-merge-conflict
20-

.tflint.hcl

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
config {
2+
module = false
3+
force = false
4+
disabled_by_default = true
5+
}
6+
7+
plugin "aws" {
8+
enabled = false
9+
}
10+
11+
rule "terraform_deprecated_interpolation" {
12+
enabled = true
13+
}
14+
15+
rule "terraform_deprecated_index" {
16+
enabled = true
17+
}
18+
19+
rule "terraform_unused_declarations" {
20+
enabled = true
21+
}
22+
23+
rule "terraform_comment_syntax" {
24+
enabled = true
25+
}
26+
27+
rule "terraform_documented_outputs" {
28+
enabled = true
29+
}
30+
31+
rule "terraform_documented_variables" {
32+
enabled = true
33+
}
34+
35+
rule "terraform_typed_variables" {
36+
enabled = true
37+
}
38+
39+
rule "terraform_module_pinned_source" {
40+
enabled = true
41+
}
42+
43+
rule "terraform_naming_convention" {
44+
enabled = true
45+
}
46+
47+
rule "terraform_required_version" {
48+
enabled = true
49+
}
50+
51+
rule "terraform_required_providers" {
52+
enabled = true
53+
}
54+
55+
rule "terraform_standard_module_structure" {
56+
enabled = true
57+
}
58+
59+
rule "terraform_workspace_remote" {
60+
enabled = true
61+
}

.travis.yml

-16
This file was deleted.

3rd-party-licenses.md

-16
This file was deleted.

Makefile

-12
This file was deleted.

0 commit comments

Comments
 (0)