Skip to content

Commit 9688b89

Browse files
committed
feat: dockerize terraform makefile
1 parent ccb43aa commit 9688b89

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

Makefile.terraform

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
-include .config.mk
77

88
TERRAFORM_IMAGE ?= docker.io/hashicorp/terraform
9-
TERRAFORM_VERSION ?= 1.0 ## Terraform is very version specific, so know what you need
10-
TERRAFORM_STATE_S3 ?= no ## If using S3 for shared state, override this with a 'yes'
9+
TERRAFORM_VERSION ?= 1.0.7 ## Terraform is very version specific, so know what you need
10+
TERRAFORM_STATE_S3 ?= yes ## If using S3 for shared state, override this with a 'yes'
1111
CONTAINER_ENGINE ?= docker ## Commands will be executed via the container engine, expected to be docker cli compatible
12+
CONTAINER_WORK_DIR ?= /data
13+
CONTAINER_ENV ?= .env
1214

15+
BASE_ENV := -v ~/.aws:/root/.aws:Z --env-file=$(CONTAINER_ENV)
16+
BASE_WORKDIR := -w $(CONTAINER_WORK_DIR) -v "$(CURDIR)":$(CONTAINER_WORK_DIR):Z
1317
# Container based commands to for use handling target steps
14-
BASE_COMMAND := $(CONTAINER_ENGINE) run --rm -it --env-file $(BASE_ENV) -v "$(CURDIR)":$(WORKDIR):Z
18+
BASE_COMMAND := $(CONTAINER_ENGINE) run --rm -it $(BASE_ENV) $(BASE_WORKDIR)
1519
TERRAFORM_COMMAND := $(BASE_COMMAND) $(TERRAFORM_IMAGE):$(TERRAFORM_VERSION)
1620

1721
# Determine some runtime values
@@ -39,9 +43,12 @@ help: ## Show this help, includes list of all actions.
3943

4044
.PHONY: clean
4145
clean: ## Cleanup the local checkout
42-
-rm -f *.zip *.backup
46+
-rm -f *.zip *.backup .terraform
4347

44-
.terraform:
48+
$(CONTAINER_ENV):
49+
@env | awk '!/TOKEN/ && /^(AWS)/ { print }' | sort > $(@)
50+
51+
.terraform: $(BUILD_ENV)
4552
@if [ ! -d .terraform ]; then $(TERRAFORM_COMMAND) init; else $(TERRAFORM_COMMAND) get --update > /dev/null; fi
4653

4754
.PHONY: init

0 commit comments

Comments
 (0)