2018-12-09 03:46:54 +00:00
|
|
|
# Set default target for make > 3.80
|
|
|
|
.DEFAULT_GOAL := default
|
|
|
|
|
|
|
|
# Default make to the deploy target
|
|
|
|
.PHONY: default
|
|
|
|
default: deploy
|
|
|
|
|
2021-12-07 03:25:05 +00:00
|
|
|
SELECTED_WORKSPACE := $(shell cat .terraform/environment 2>/dev/null || echo default)
|
2018-12-09 03:46:54 +00:00
|
|
|
ENV := $(if $(ENV),$(ENV),$(SELECTED_WORKSPACE))
|
|
|
|
|
|
|
|
.PHONY: setup
|
2021-12-07 03:25:05 +00:00
|
|
|
setup: init workspace
|
|
|
|
|
|
|
|
.PHONY: workspace
|
|
|
|
workspace:
|
2018-12-09 03:46:54 +00:00
|
|
|
ifneq ($(SELECTED_WORKSPACE),$(ENV))
|
|
|
|
@terraform workspace select $(ENV)
|
|
|
|
endif
|
|
|
|
|
|
|
|
.PHONY: init
|
|
|
|
init:
|
|
|
|
@terraform init
|
|
|
|
|
|
|
|
.PHONY: plan
|
|
|
|
plan: setup
|
|
|
|
@terraform plan \
|
|
|
|
$(if $(PLAN),--out $(PLAN)) \
|
|
|
|
$(if $(ENV),--var-file=$(ENV).tfvars) \
|
|
|
|
$(ARGS)
|
|
|
|
|
|
|
|
.PHONY: deploy
|
|
|
|
deploy: setup
|
|
|
|
@terraform apply \
|
|
|
|
$(if $(PLAN),$(PLAN)) \
|
|
|
|
$(ARGS)
|
|
|
|
|
|
|
|
.PHONY: destroy
|
|
|
|
destroy: setup
|
|
|
|
@terraform destroy \
|
|
|
|
$(if $(ENV),--var-file=$(ENV).tfvars) \
|
|
|
|
$(ARGS)
|
2021-12-07 03:25:05 +00:00
|
|
|
|
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
|
|
|
@rm -rf .terraform
|