diff --git a/templates/module/Makefile.tmpl b/templates/module/Makefile.tmpl index 916258d43..932ca4ed0 100644 --- a/templates/module/Makefile.tmpl +++ b/templates/module/Makefile.tmpl @@ -1,51 +1,8 @@ # Auto-generated by fogg. Do not edit # Make improvements in fogg, so that everyone can benefit. -TF_VARS := $(patsubst %,-e%,$(filter TF_VAR_%,$(.VARIABLES))) -REPO_ROOT := $(shell git rev-parse --show-toplevel) -REPO_RELATIVE_PATH := $(shell git rev-parse --show-prefix) -# We need to do this because `terraform fmt` recurses into .terraform/modules -# and wont' accept more than one file at a time. -TF=$(wildcard *.tf) -IMAGE_VERSION={{ .DockerImageVersion }}_TF{{ .TerraformVersion }} +export DOCKER_IMAGE_VERSION :={{ .DockerImageVersion }} +export TERRAFORM_VERSION := {{ .TerraformVersion }} +export TF_PLUGIN_CACHE_DIR := {{ .PathToRepoRoot }}/.terraform.d/plugin-cache -docker_base = \ - docker run --rm -e HOME=/home -v $$HOME/.aws:/home/.aws -v $(REPO_ROOT):/repo \ - -v $(REPO_ROOT)/.bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \ - -e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ - -e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \ - -e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \ - -w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh) -docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION) -docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION) - -all: fmt lint doc - -fmt: - @$(docker_sh) -c 'for f in $(TF); do printf .; terraform fmt $$f; done'; \ - echo - - -check: lint check-docs - -lint: lint-tf - -lint-tf: - @$(docker_sh) -c 'for f in $(TF); do printf .; terraform fmt --check=true --diff=true $$f || exit $$? ; done' - -readme: - bash ../../../scripts/update-readme.sh update - -docs: readme - -check-docs: - @bash .update-readme.sh check; \ - if [ ! $$? -eq 0 ]; then \ - echo "Docs are out of date, run \`make docs\`"; \ - fi - -clean: - -test: - -.PHONY: all check-doc clean docs fmt lint lint-tf readme test +include {{ .PathToRepoRoot }}/scripts/module.mk diff --git a/templates/repo/scripts/module.mk b/templates/repo/scripts/module.mk new file mode 100644 index 000000000..c826dbfcc --- /dev/null +++ b/templates/repo/scripts/module.mk @@ -0,0 +1,51 @@ +# Auto-generated by fogg. Do not edit +# Make improvements in fogg, so that everyone can benefit. + +TF_VARS := $(patsubst %,-e%,$(filter TF_VAR_%,$(.VARIABLES))) +REPO_ROOT := $(shell git rev-parse --show-toplevel) +REPO_RELATIVE_PATH := $(shell git rev-parse --show-prefix) +# We need to do this because `terraform fmt` recurses into .terraform/modules +# and wont' accept more than one file at a time. +TF=$(wildcard *.tf) +IMAGE_VERSION=$(DOCKER_IMAGE_VERSION)_TF$(TERRAFORM_VERSION) + +docker_base = \ + docker run --rm -e HOME=/home -v $$HOME/.aws:/home/.aws -v $(REPO_ROOT):/repo \ + -v $(REPO_ROOT)/.bin:/usr/local/bin -v $(REPO_ROOT)/terraform.d:/repo/$(REPO_RELATIVE_PATH)/terraform.d \ + -e GIT_SSH_COMMAND='ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no' \ + -e RUN_USER_ID=$(shell id -u) -e RUN_GROUP_ID=$(shell id -g) \ + -e TF_PLUGIN_CACHE_DIR="/repo/.terraform.d/plugin-cache" -e TF="$(TF)" \ + -w /repo/$(REPO_RELATIVE_PATH) $(TF_VARS) $$(sh $(REPO_ROOT)/scripts/docker-ssh-mount.sh) +docker_terraform = $(docker_base) chanzuckerberg/terraform:$(IMAGE_VERSION) +docker_sh = $(docker_base) --entrypoint='/bin/sh' chanzuckerberg/terraform:$(IMAGE_VERSION) + +all: fmt lint doc + +fmt: + @$(docker_sh) -c 'for f in $(TF); do printf .; terraform fmt $$f; done'; \ + echo + + +check: lint check-docs + +lint: lint-tf + +lint-tf: + @$(docker_sh) -c 'for f in $(TF); do printf .; terraform fmt --check=true --diff=true $$f || exit $$? ; done' + +readme: + bash $(REPO_ROOT)/scripts/update-readme.sh update + +docs: readme + +check-docs: + @bash $(REPO_ROOT)/scripts/update-readme.sh check; \ + if [ ! $$? -eq 0 ]; then \ + echo "Docs are out of date, run \`make docs\`"; \ + fi + +clean: + +test: + +.PHONY: all check-doc clean docs fmt lint lint-tf readme test