From a2023f1c6c617e3b474162e281440001159d9cc5 Mon Sep 17 00:00:00 2001 From: exequielrafaela Date: Tue, 9 Jul 2019 19:46:34 -0300 Subject: [PATCH] Updating Makefile to support terratests cmds --- Makefile | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index b041821..a7729d2 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,7 @@ SHELL := /bin/bash LOCAL_OS_USER := $(shell whoami) LOCAL_OS_SSH_DIR := ~/.ssh LOCAL_OS_GIT_CONF_DIR := ~/.gitconfig +LOCAL_OS_AWS_CONF_DIR := ~/.aws TF_PWD_DIR := $(shell pwd) TF_VER := 0.11.14 @@ -10,6 +11,12 @@ TF_PWD_CONT_DIR := "/go/src/project/" TF_DOCKER_ENTRYPOINT := /usr/local/go/bin/terraform TF_DOCKER_IMAGE := binbash/terraform-resources +TERRATEST_DOCKER_ENTRYPOINT := dep +TERRATEST_DOCKER_WORKDIR := /go/src/project/tests + +# +# TERRAFORM +# define TF_CMD_PREFIX docker run --rm \ -v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \ @@ -17,6 +24,31 @@ docker run --rm \ -it ${TF_DOCKER_IMAGE}:${TF_VER} endef +# +# TERRATEST +# +define TERRATEST_GO_CMD_PREFIX +docker run --rm \ +-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \ +-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \ +-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \ +-v ${LOCAL_OS_AWS_CONF_DIR}:/root/.aws \ +-w ${TERRATEST_DOCKER_WORKDIR} \ +-it ${TF_DOCKER_IMAGE}:${TF_VER} +endef + +define TERRATEST_DEP_CMD_PREFIX +docker run --rm \ +-v ${TF_PWD_DIR}:${TF_PWD_CONT_DIR}:rw \ +-v ${LOCAL_OS_SSH_DIR}:/root/.ssh \ +-v ${LOCAL_OS_GIT_CONF_DIR}:/etc/gitconfig \ +--entrypoint=${TERRATEST_DOCKER_ENTRYPOINT} \ +-it ${TF_DOCKER_IMAGE}:${TF_VER} +endef + +# +# GIT-RELEASE +# # pre-req -> https://github.com/pnikosis/semtag define GIT_SEMTAG_CMD_PREFIX docker run --rm \ @@ -35,33 +67,58 @@ help: @echo 'Available Commands:' @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " - \033[36m%-18s\033[0m %s\n", $$1, $$2}' -version: ## version: show terraform version + +#==============================================================# +# TERRAFORM # +#==============================================================# +version: ## Show terraform version docker run --rm \ --entrypoint=${TF_DOCKER_ENTRYPOINT} \ -t ${TF_DOCKER_IMAGE}:${TF_VER} version -format: ## format: The terraform fmt is used to rewrite tf conf files to a canonical format and style. +format: ## The terraform fmt is used to rewrite tf conf files to a canonical format and style. ${TF_CMD_PREFIX} fmt ${TF_PWD_CONT_DIR} -doc: ## doc: A utility to generate documentation from Terraform modules in various output formats. +doc: ## A utility to generate documentation from Terraform modules in various output formats. docker run --rm -v ${TF_PWD_DIR}:/data -t binbash/terraform-docs markdown table /data -lint: ## lint: TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan. +lint: ## TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan. docker run --rm -v ${TF_PWD_DIR}:/data -t wata727/tflint --deep + +#==============================================================# +# TERRATEST # +#==============================================================# +terratest-dep-init: ## dep is a dependency management tool for Go. (https://github.com/golang/dep) + ${TERRATEST_DEP_CMD_PREFIX} init + ${TERRATEST_DEP_CMD_PREFIX} ensure + sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} . + cp -r ./vendor ./tests/ && rm -rf ./vendor + cp -r ./Gopkg* ./tests/ && rm -rf ./Gopkg* + +terratest-go-test: ## lint: TFLint is a Terraform linter for detecting errors that can not be detected by terraform plan. + ${TERRATEST_GO_CMD_PREFIX} test + sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} . + +#==============================================================# +# GIT RELEASE # +#==============================================================# release-patch: ## releasing patch (eg: 0.0.1 -> 0.0.2) based on semantic tagging script for Git # pre-req -> https://github.com/pnikosis/semtag ${GIT_SEMTAG_CMD_PREFIX} get + sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git ${GIT_SEMTAG_CMD_PREFIX} final -s patch release-minor: ## releasing minor (eg: 0.0.2 -> 0.1.0) based on semantic tagging script for Git # pre-req -> https://github.com/pnikosis/semtag ${GIT_SEMTAG_CMD_PREFIX} get + sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git ${GIT_SEMTAG_CMD_PREFIX} final -s minor release-major: ## releasing major (eg: 0.1.0 -> 1.0.0) based on semantic tagging script for Git # pre-req -> https://github.com/pnikosis/semtag ${GIT_SEMTAG_CMD_PREFIX} get + sudo chown -R ${LOCAL_OS_USER}:${LOCAL_OS_USER} ./.git ${GIT_SEMTAG_CMD_PREFIX} final -s major changelog-init: ## git-chglog (https://github.com/git-chglog/git-chglog) config initialization -> ./.chglog