Skip to content

Commit 974a62e

Browse files
committed
chore: ensure PHONY and SILENT
1 parent af3fe64 commit 974a62e

File tree

1 file changed

+33
-14
lines changed

1 file changed

+33
-14
lines changed

Makefile.terraform

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ifeq ("$(AWS_CONFIG)", "$(wildcard $(AWS_CONFIG))")
1919
BASE_ENV := -v $(AWS_CONFIG):/root/.aws:Z --env-file=$(CONTAINER_ENV)
2020
endif
2121
BASE_ENV := $(BASE_ENV) --env-file=$(CONTAINER_ENV)
22+
BASE_USER := -u $(shell id -u ${USER}):$(shell id -g ${USER})
2223
BASE_WORKDIR := -w $(CONTAINER_WORK_DIR) -v "$(CURDIR)":$(CONTAINER_WORK_DIR):Z
2324

2425
# Container based commands to for use handling target steps
@@ -34,10 +35,20 @@ endif
3435

3536
all: help
3637

37-
.PHONY:.check-env
38+
# Exports the variables for shell use
39+
export
40+
41+
# This helper function makes debuging much easier.
42+
.PHONY: debug-%
43+
.SILENT: debug-%
44+
debug-%: ## Debug a variable by calling `make debug-VARIABLE`
45+
echo $(*) = $($(*))
46+
47+
.PHONY: .check-env
48+
.SILENT: .check-env
3849
.check-env:
3950
ifeq ($(origin TERRAFORM_STATE_S3), "yes")
40-
@if [ "${AWS_PROFILE}" == "" ]; then \
51+
if [ "${AWS_PROFILE}" == "" ]; then \
4152
if [ "${AWS_SECRET_ACCESS_KEY}" == "" ] || [ "${AWS_ACCESS_KEY_ID}" == "" ]; then \
4253
echo "ERROR: AWS_PROFILE _or_ AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must be profiled"; \
4354
exit 1; \
@@ -46,18 +57,22 @@ ifeq ($(origin TERRAFORM_STATE_S3), "yes")
4657
endif
4758

4859
.PHONY: help
60+
.SILENT: help
4961
help: ## Show this help, includes list of all actions.
50-
@awk 'BEGIN {FS = ":.*?## "}; /^.+: .*?## / && !/awk/ {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' ${MAKEFILE_LIST}
62+
awk 'BEGIN {FS = ":.*?## "}; /^.+: .*?## / && !/awk/ {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' ${MAKEFILE_LIST}
5163

5264
.PHONY: clean
5365
clean: ## Cleanup the local checkout
54-
-rm -f *.zip *.backup $(TERRAFORM_DIR)
66+
-rm -f *.zip *.backup
67+
-rf -rf $(TERRAFORM_DIR)
5568

69+
.SILENT: $(CONTAINER_ENV)
5670
$(CONTAINER_ENV):
57-
@env | awk '!/TOKEN/ && /^(AWS)/ { print }' | sort > $(@)
71+
env | awk '!/TOKEN/ && /^(AWS)/ { print }' | sort > $(@)
5872

59-
$(TERRAFORM_DIR): $(BUILD_ENV)
60-
@if [ ! -d $(TERRAFORM_DIR) ]; then $(TERRAFORM_COMMAND) init; else $(TERRAFORM_COMMAND) get --update > /dev/null; fi
73+
.SILENT: $(TERRAFORM_DIR)
74+
$(TERRAFORM_DIR): $(CONTAINER_ENV)
75+
if [ ! -d $(TERRAFORM_DIR) ]; then $(TERRAFORM_COMMAND) init; else $(TERRAFORM_COMMAND) get --update > /dev/null; fi
6176

6277
.PHONY: init
6378
init: $(TERRAFORM_DIR) ## Initalize shared storage bucket for state and ensure modules are loaded
@@ -74,25 +89,29 @@ new-workspace-%: init ## Creates and selects a new workspace
7489
select-%: init ## Change to the provided workspace
7590
$(TERRAFORM_COMMAND) workspace select $*
7691

92+
.PHONY: plan-%
7793
plan-%: select-% plan ## Run terraform plan against the defined workspace
7894
: # This is because make doesnt like wildcard targets to not have any actions
7995

96+
.PHONY: plan
8097
plan: init ## Run terraform plan against the current workspace
8198
$(TERRAFORM_COMMAND) plan $(TERRAFORM_VAR_FILE)
8299

100+
.PHONY: test
83101
test: plan ## Standard entry point for running tests. Calls plan
84102

103+
.PHONY: apply-%
85104
apply-%: select-% apply ## Run terraform apply against the defined workspace
86105
: # This is because make doesnt like this target to not have any actions
87106

107+
.PHONY: apply
88108
apply: init ## Run terraform apply against the current workspace
89109
$(TERRAFORM_COMMAND) apply $(TERRAFORM_VAR_FILE)
90110

91-
show: init ## Run terraform show against the current workspace
92-
$(TERRAFORM_COMMAND) show
93-
94-
show-node: init ## Run terraform show against the current workspace. NODE_REGEX search pattern
95-
$(TERRAFORM_COMMAND) show | grep -P '^module| id| ip' | grep -C1 -P "${NODE_REGEX}"
111+
.PHONY: show
112+
show: init ## Run terraform show against the current workspace. ex: make show RESOURCE=something.or.other
113+
$(TERRAFORM_COMMAND) show $(RESOURCE)
96114

97-
taint-node: init ## Run terraform taint against the current workspace. NODE_REGEX search pattern
98-
./scripts/taint.sh $(TERRAFORM_COMMAND) ${NODE_REGEX}
115+
.PHONY: taint
116+
taint: init ## Run terraform taint in current workspace against a resource. ex: make taint RESOURCE=something.or.other
117+
$(TERRAFORM_COMMAND) taint $(RESOURCE)

0 commit comments

Comments
 (0)