Skip to content

Commit dce4682

Browse files
authored
Add Support for Terraform Lint Checking (#34)
1 parent 053558b commit dce4682

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ install:
1616
script:
1717
- "make bash:lint"
1818
- "make make:lint"
19+
- "make terraform:install"

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Available targets:
3737
geodesic:deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
3838
git:aliases-update Update git aliases
3939
git:submodules-update Update submodules
40-
github:download-release Download release from github
40+
github:download-private-release Download release from github
41+
github:download-public-release Download release from github
4142
go:build Build binary
4243
go:build-all Build binary for all platforms
4344
go:clean Clean compiled binary
@@ -62,7 +63,12 @@ Available targets:
6263
help This help screen
6364
jenkins:run-job-with-tag Run a Jenkins Job with $(TAG)
6465
make:lint Lint all makefiles
65-
travis:docker-tag-and-push Tag according travis envvars and push
66+
terraform:get-modules Ensure all modules can be fetched
67+
terraform:get-plugins Ensure all plugins can be fetched
68+
terraform:lint Lint check Terraform
69+
terraform:validate Basic terraform sanity check
70+
travis:docker-login Login into docker hub
71+
travis:docker-tag-and-push Tag & Push according Travis environment variables
6672
```
6773

6874

@@ -71,7 +77,7 @@ Available targets:
7177
- [`github-authorized-keys`](https://github.com/cloudposse/github-authorized-keys/) - A Golang project that leverages `docker:%`, `go:%`, `travis:%` targets
7278
- [`charts`](https://github.com/cloudposse/charts/) - A collection of Helm Charts that leverages `docker:%` and `helm:%` targets
7379
- [`bastion`](https://github.com/cloudposse/bastion/) - A docker image that leverages `docker:%` and `bash:lint` targets
74-
80+
- [`terraform-null-label`](https://github.com/cloudposse/terraform-null-label/) - A terraform module that leverages `terraform:%` targets
7581

7682
## Help
7783

modules/terraform/Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
TMP ?= /tmp
2+
TERRAFORM ?= $(BUILD_HARNESS_PATH)/terraform
3+
TERRAFORM_VERSION ?= 0.10.7
4+
TERRAFORM_URL ?= https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(OS)_amd64.zip
5+
6+
## Install terraform
7+
terraform\:install:
8+
@[ -x $(TERRAFORM) ] || ( \
9+
echo "Installing Terraform $(TERRAFORM_VERSION) ($(OS)) from $(TERRAFORM_URL)" && \
10+
curl '-#' -fL -o $(TMP)/terraform.zip $(TERRAFORM_URL) && \
11+
unzip -q -d $(TMP)/ $(TMP)/terraform.zip && \
12+
mv $(TMP)/terraform $(TERRAFORM) && \
13+
rm -f $(TMP)/terraform.zip \
14+
)
15+
$(TERRAFORM) version
16+
17+
## Ensure all plugins can be fetched
18+
terraform\:get-plugins:
19+
@$(TERRAFORM) init -get-plugins -backend=false -input=false >/dev/null
20+
21+
## Ensure all modules can be fetched
22+
terraform\:get-modules:
23+
@$(TERRAFORM) init -get -backend=false -input=false >/dev/null
24+
25+
## Basic terraform sanity check
26+
terraform\:validate:
27+
@$(TERRAFORM) validate -check-variables=false
28+
29+
## Lint check Terraform
30+
terraform\:lint:
31+
@FAIL=`$(TERRAFORM) fmt -write=false | xargs --no-run-if-empty -n 1 printf '\t- %s\n'`; \
32+
[ -z "$$FAIL" ] || (echo "Terraform configuration needs linting. Run '$(TERRAFORM) fmt'"; echo $$FAIL; exit 1)

0 commit comments

Comments
 (0)