2424export TF_DATA_DIR = $(ENV_DIR ) /.terraform
2525TERRAFORM_WORKING_DIR = $(MKFILE_DIR ) /terraform/environment
2626
27+ # Since the variable directory and the terraform working directory are not the
28+ # same using a file custom.tf allows specifying additional terraform
29+ # instructions not (yet) covered by the terraform/environment functionality. A
30+ # symlink is created before terraform init/apply/etc if such a file exists,
31+ # otherwise it is removed (in case it was created during a previous Makefile
32+ # invocation with a different ENV_DIR
33+ .PHONY : custom-terraform
34+ custom-terraform :
35+ if [ -f $( ENV_DIR) /custom.tf ]; then ln -sf $( ENV_DIR) /custom.tf $( TERRAFORM_WORKING_DIR) /custom.tf; else rm -f $( TERRAFORM_WORKING_DIR) /custom.tf; fi
2736
2837# NOTE: leverage make's ability to noop if target already exists, but
2938# this also means that re-init must be triggered explicitly
@@ -32,11 +41,11 @@ $(TF_DATA_DIR):
3241 && terraform init -backend-config=$(ENV_DIR ) /backend.tfvars
3342
3443.PHONY : re-init
35- re-init : check-inputs-terraform
44+ re-init : check-inputs-terraform custom-terraform
3645 make --always-make $(TF_DATA_DIR )
3746
3847.PHONY : apply plan console destroy
39- apply plan console destroy : check-inputs-terraform $(TF_DATA_DIR )
48+ apply plan console destroy : check-inputs-terraform custom-terraform $(TF_DATA_DIR )
4049 cd $(TERRAFORM_WORKING_DIR ) \
4150 && source $(ENV_DIR ) /hcloud-token.dec \
4251 && terraform $(@ ) -var-file=$(ENV_DIR ) /terraform.tfvars
0 commit comments