diff --git a/.travis.yml b/.travis.yml index 7e5cb299..7f21ed3f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,3 +16,4 @@ install: script: - "make bash:lint" - "make make:lint" + - "make terraform:install" diff --git a/README.md b/README.md index a416d9d7..f7332f1d 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` @@ -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 diff --git a/modules/terraform/Makefile b/modules/terraform/Makefile new file mode 100644 index 00000000..dcc19f28 --- /dev/null +++ b/modules/terraform/Makefile @@ -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)