-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
48 lines (38 loc) · 1.36 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
PROJDIR := $(realpath $(CURDIR))
TERRAFORM_DIR := terraform
ENVS_DIR := environments
ANSIBLE_CAOS := ansible/caos-ansible-roles
SAMPLES = $(shell basename -a $(wildcard $(addprefix $(PROJDIR)/, $(TERRAFORM_DIR))/*))
# TODO: Handle basename error if environments dir is empty
ENVS = $(shell basename -a $(wildcard $(addprefix $(PROJDIR)/, $(ENVS_DIR))/*) 2> /dev/null)
.DEFAULT_GOAL := default
default:
@echo No default target defined
format:
@terraform fmt \
-write=true \
-recursive
deps:
git submodule update --init
@for role in $(shell find ${ANSIBLE_CAOS} -maxdepth 1 -type d -not -path '*/.*' | tail -n +2 ); do cd $${role}; [ -f requirements.yml ] && ansible-galaxy install --roles-path ../../ -r requirements.yml; cd ../; done
define make-new-env
new-$1:
@cp -r $(TERRAFORM_DIR)/$1 $(ENVS_DIR)
@echo "New environment created $(ENVS_DIR)/$1"
endef
define make-init-env
init-$1:
@terraform -chdir=$(ENVS_DIR)/$1 init
endef
define make-apply-env
apply-$1:
@terraform -chdir=$(ENVS_DIR)/$1 apply
endef
define make-destroy-env
destroy-$1:
@terraform -chdir=$(ENVS_DIR)/$1 destroy
endef
$(foreach element,$(SAMPLES),$(eval $(call make-new-env,$(element))))
$(foreach element,$(ENVS),$(eval $(call make-init-env,$(element))))
$(foreach element,$(ENVS),$(eval $(call make-apply-env,$(element))))
$(foreach element,$(ENVS),$(eval $(call make-destroy-env,$(element))))