stack/Makefile

82 lines
1.8 KiB
Makefile

include $(PWD)/src/toolchain/Makefile
BACKEND_TF := $(wildcard infra/backend/*.tf)
ENVIRONMENT := production
REGION := sfo3
ROOT_DIR := $(shell pwd)
TERRAFORM := $(ROOT_DIR)/out/terraform
.DEFAULT_GOAL :=
.PHONY: default
default: \
toolchain \
apply
.PHONY:
clean:
rm -rf $(CACHE_DIR)
.PHONY:
credentials: \
$(CACHE_DIR)/secrets/credentials.tfvars
infra/backend/.terraform: \
$(OUT_DIR)/terraform \
$(BACKEND_TF)
env -C infra/backend $(TERRAFORM) init
infra/main/.terraform: \
$(OUT_DIR)/terraform \
$(BACKEND_TF)
env -C infra/main $(TERRAFORM) init \
-backend-config="../../config/$(ENVIRONMENT).tfbackend"
infra/backend/$(ENVIRONMENT).tfstate: \
$(CACHE_DIR)/secrets/credentials.tfvars \
$(OUT_DIR)/terraform \
infra/backend/.terraform
env -C infra/backend $(TERRAFORM) apply \
-var environment=$(ENVIRONMENT) \
-var namespace=$(ENVIRONMENT) \
-var region=$(REGION) \
-state ../../$@ \
-var-file ../../$<
config/$(ENVIRONMENT).tfbackend: \
infra/backend/$(ENVIRONMENT).tfstate \
$(OUT_DIR)/terraform
env -C infra/backend $(TERRAFORM) \
output -state ../../$< \
> $@
.PHONY:
apply: \
$(CACHE_DIR)/secrets/credentials.tfvars \
$(OUT_DIR)/terraform \
infra/main/.terraform
env -C infra/main $(TERRAFORM) apply \
-var-file ../../$<
$(CACHE_DIR)/secrets:
mkdir -p $@
$(CACHE_DIR)/secrets/%.tfvars: secrets/%.tfvars.gpg $(CACHE_DIR)/secrets
gpg --decrypt $< > $@
$(FETCH_DIR)/terraform:
$(call git_clone,$@,$(TERRAFORM_REPO),$(TERRAFORM_REF))
$(OUT_DIR)/terraform: $(FETCH_DIR)/terraform
$(call toolchain," \
cd $(FETCH_DIR)/terraform && \
export SSL_CERT_DIR=/etc/ssl/certs && \
export CGO_ENABLED=0 && \
export GOCACHE=/home/build/$(CACHE_DIR) && \
export GOPATH=/home/build/$(CACHE_DIR) && \
go build \
-v \
-trimpath \
-ldflags='-w -extldflags=-static' \
-o /home/build/$@ \
")