Skip to content

Commit 890fa19

Browse files
committed
Add CircleCI config
1 parent 9e19a8d commit 890fa19

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

.circleci/config.yml

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
docker:
6+
- image: hashicorp/terraform:0.11.3
7+
entrypoint: /bin/sh
8+
steps:
9+
- checkout
10+
- run:
11+
name: "Validate tf files (terraform validate)"
12+
command: |
13+
find . -type f -name "*.tf" -exec dirname {} \;|sort -u | while read m; do (terraform validate -check-variables=false "$m" && echo "√ $m") || exit 1 ; done
14+
- run:
15+
name: "Check: Terraform formatting (terraform fmt)"
16+
command: |
17+
if [ `terraform fmt --list=true -diff=true -write=false | tee format-issues | wc -c` -ne 0 ]; then
18+
echo "Some terraform files need be formatted, run 'terraform fmt' to fix"
19+
echo "Formatting issues:"
20+
cat format-issues
21+
exit 1
22+
fi
23+
- run:
24+
name: "Install: tflint"
25+
command: |
26+
apk add wget
27+
wget https://github.com./wata727/tflint/releases/download/v0.5.4/tflint_linux_amd64.zip
28+
unzip tflint_linux_amd64.zip
29+
mkdir -p /usr/local/tflint/bin
30+
# TODO: CircleCI write to file for later run steps
31+
#export PATH=/usr/local/tflint/bin:$PATH
32+
echo "Installing tflint..."
33+
install tflint /usr/local/tflint/bin
34+
echo "Configuring tflint..."
35+
tf_ver=$(terraform version | awk 'FNR <= 1' | cut -dv -f2)
36+
echo -e "\tConfig for terraform version: ${tf_ver}"
37+
if [ -f '.tflint.hcl' ]; then
38+
sed -i "/terraform_version =/s/\".*\"/\"${tf_ver}\"/" .tflint.hcl
39+
else
40+
{
41+
echo -e "config {\nterraform_version = \"${tf_ver}\"\ndeep_check = true\nignore_module = {"
42+
for module in $(grep -h '[^a-zA-Z]source[ =]' *.tf | sed -r 's/.*=\s+//' | sort -u); do
43+
echo "${module} = true"
44+
done
45+
echo "}}"
46+
} > .tflint.hcl
47+
fi
48+
echo "tflint configuration:"
49+
cat .tflint.hcl
50+
- run:
51+
# Not supporting modules from registry ?? v0.5.4
52+
# For now, must ignore in config file
53+
name: "Check: tflint"
54+
command: |
55+
#echo "Initializing terraform..."
56+
#terraform init -input=false
57+
echo "Running tflint..."
58+
/usr/local/tflint/bin/tflint --version
59+
/usr/local/tflint/bin/tflint
60+
61+
workflows:
62+
version: 2
63+
build:
64+
jobs:
65+
- build

0 commit comments

Comments
 (0)