added Makefile

main
Ricard Illa 2022-08-25 11:46:50 +02:00
parent 7edb988414
commit 06063c888f
No known key found for this signature in database
GPG Key ID: F69A672B72E54902
3 changed files with 44 additions and 0 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
.direnv .direnv
.terraform .terraform
.terraform.lock.hcl .terraform.lock.hcl
tfinit
tfplan

40
Makefile Normal file
View File

@ -0,0 +1,40 @@
SRC_DIR=tf
SRC=$(shell find $(SRC_DIR) -type f -name "*.tf")
TERRAFORM=terraform -chdir=$(SRC_DIR)
PG_USER=terraform
PG_HOST=pg.monotremata.xyz
PG_DB=terraform_backend
PG_PORT=5432
PG_PASSWD=$(shell pass "$(PG_HOST)/$(PG_USER)")
PG_CONN_STR=postgres://$(PG_USER):$(PG_PASSWD)@$(PG_HOST):$(PG_PORT)/$(PG_DB)
NAMECHEAP_API_KEY=$(shell pass namecheap.com/api_key)
LINODE_TOKEN=$(shell pass linode.com/token)
VULTR_API_KEY=$(shell pass vultr.com/api_key)
HTTP_PROXY=caladan:8888
HTTPS_PROXY=caladan:8888
export HTTP_PROXY
export HTTPS_PROXY
export NAMECHEAP_API_KEY
export LINODE_TOKEN
export VULTR_API_KEY
.PHONY: apply clean
apply: $(SRC_DIR)/tfplan $(SRC)
$(TERRAFORM) apply $(<F)
$(SRC_DIR)/tfplan: $(SRC_DIR)/tfinit $(SRC)
$(TERRAFORM) plan -out=$(@F)
$(SRC_DIR)/tfinit: $(SRC)
$(TERRAFORM) init -backend-config="conn_str=$(PG_CONN_STR)"
@touch $@
clean:
rm -f $(SRC_DIR)/tfplan $(SRC_DIR)/tfinit

View File

@ -39,6 +39,8 @@ to the partially-configured pg backend.
fetches the secrets (from `pass`) and exports the variables for api keys and fetches the secrets (from `pass`) and exports the variables for api keys and
tokens needed by the different providers. tokens needed by the different providers.
Additionally, I also wrote a simple `Makefile` to init/plan/apply quickly.
## Backend ## Backend
I use the pg backend on a PostgreSQL hosted on my NAS. I use the pg backend on a PostgreSQL hosted on my NAS.