Skip to content

Commit

Permalink
Add Support for Terraform Lint Checking (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman authored Oct 13, 2017
1 parent 053558b commit dce4682
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ install:
script:
- "make bash:lint"
- "make make:lint"
- "make terraform:install"
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Available targets:
geodesic:deploy Run a Jenkins Job to Deploy $(APP) with $(CANONICAL_TAG)
git:aliases-update Update git aliases
git:submodules-update Update submodules
github:download-release Download release from github
github:download-private-release Download release from github
github:download-public-release Download release from github
go:build Build binary
go:build-all Build binary for all platforms
go:clean Clean compiled binary
Expand All @@ -62,7 +63,12 @@ Available targets:
help This help screen
jenkins:run-job-with-tag Run a Jenkins Job with $(TAG)
make:lint Lint all makefiles
travis:docker-tag-and-push Tag according travis envvars and push
terraform:get-modules Ensure all modules can be fetched
terraform:get-plugins Ensure all plugins can be fetched
terraform:lint Lint check Terraform
terraform:validate Basic terraform sanity check
travis:docker-login Login into docker hub
travis:docker-tag-and-push Tag & Push according Travis environment variables
```


Expand All @@ -71,7 +77,7 @@ Available targets:
- [`github-authorized-keys`](https://github.com/cloudposse/github-authorized-keys/) - A Golang project that leverages `docker:%`, `go:%`, `travis:%` targets
- [`charts`](https://github.com/cloudposse/charts/) - A collection of Helm Charts that leverages `docker:%` and `helm:%` targets
- [`bastion`](https://github.com/cloudposse/bastion/) - A docker image that leverages `docker:%` and `bash:lint` targets

- [`terraform-null-label`](https://github.com/cloudposse/terraform-null-label/) - A terraform module that leverages `terraform:%` targets

## Help

Expand Down
32 changes: 32 additions & 0 deletions modules/terraform/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
TMP ?= /tmp
TERRAFORM ?= $(BUILD_HARNESS_PATH)/terraform
TERRAFORM_VERSION ?= 0.10.7
TERRAFORM_URL ?= https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(OS)_amd64.zip

## Install terraform
terraform\:install:
@[ -x $(TERRAFORM) ] || ( \
echo "Installing Terraform $(TERRAFORM_VERSION) ($(OS)) from $(TERRAFORM_URL)" && \
curl '-#' -fL -o $(TMP)/terraform.zip $(TERRAFORM_URL) && \
unzip -q -d $(TMP)/ $(TMP)/terraform.zip && \
mv $(TMP)/terraform $(TERRAFORM) && \
rm -f $(TMP)/terraform.zip \
)
$(TERRAFORM) version

## Ensure all plugins can be fetched
terraform\:get-plugins:
@$(TERRAFORM) init -get-plugins -backend=false -input=false >/dev/null

## Ensure all modules can be fetched
terraform\:get-modules:
@$(TERRAFORM) init -get -backend=false -input=false >/dev/null

## Basic terraform sanity check
terraform\:validate:
@$(TERRAFORM) validate -check-variables=false

## Lint check Terraform
terraform\:lint:
@FAIL=`$(TERRAFORM) fmt -write=false | xargs --no-run-if-empty -n 1 printf '\t- %s\n'`; \
[ -z "$$FAIL" ] || (echo "Terraform configuration needs linting. Run '$(TERRAFORM) fmt'"; echo $$FAIL; exit 1)

0 comments on commit dce4682

Please sign in to comment.