Skip to content

Commit

Permalink
de-dupe module makefiles (#197)
Browse files Browse the repository at this point in the history
de-dupe module makefiles
  • Loading branch information
ryanking authored and czimergebot committed Jan 4, 2019
1 parent d1523e0 commit 87e9f6c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 47 deletions.
51 changes: 4 additions & 47 deletions templates/module/Makefile.tmpl
Original file line number Diff line number Diff line change
@@ -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
51 changes: 51 additions & 0 deletions templates/repo/scripts/module.mk
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 87e9f6c

Please sign in to comment.