Skip to content

Instantly share code, notes, and snippets.

@masutaka
Last active March 26, 2020 14:34
Show Gist options
  • Save masutaka/ab96bf8baed8670f438916bd4cf95f0d to your computer and use it in GitHub Desktop.
Save masutaka/ab96bf8baed8670f438916bd4cf95f0d to your computer and use it in GitHub Desktop.
Makefiles for terraform
.
├── Makefile # (1)
└── terraform
    ├── aws
    │   ├── Makefile # (2)
    │ └── main.tf
    └── heroku
    ├── Makefile # (3)
    └── main.tf
MAKE := make
TARGETS := aws heroku
define make-r
@for i in $(TARGETS); do \
$(MAKE) -w -C terraform/$$i $(1) || exit $$?; \
done
endef
# Recursive terraform init
.PHONY: init-r
init-r:
$(call make-r, init)
# Recursive terraform plan
.PHONY: plan-r
plan-r:
$(call make-r, plan)
# Recursive terraform apply
.PHONY: apply-r
apply-r:
$(call make-r, apply)
TERRAFORM := terraform
.PHONY: init
init:
$(TERRAFORM) init
.PHONY: plan
plan:
$(TERRAFORM) plan
.PHONY: apply
apply:
$(TERRAFORM) apply
TERRAFORM := terraform
.PHONY: init
init:
$(TERRAFORM) init
.PHONY: plan
plan:
$(TERRAFORM) plan
.PHONY: apply
apply:
$(TERRAFORM) apply
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment