forked from Azure/magic-module-specs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
81 lines (67 loc) · 2.44 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
ROOT=$(shell pwd)
SPECROOT=$(ROOT)/specs
GENROOT=$(ROOT)/generated
GOSRC=$(GENROOT)/go/src
TFROOT=$(GOSRC)/github.com/terraform-providers
TFGITURL=https://github.com/VSChina/terraform-provider-azurerm.git
TFREPO=terraform-provider-azurerm
ASGITURL=https://github.com/VSChina/ansible.git
ASREPO=ansible
MMROOT=$(ROOT)/tools/magic-modules
# Environment variables.
export GOPATH=$(GENROOT)/go
export GO111MODULE=on
export GOFLAGS=-mod=vendor
default: init
all: clean init build format-terraform
init:
@echo "==> creating folders for code generation..."
@if [ ! -d "$(TFROOT)" ]; then \
mkdir -p "$(TFROOT)"; \
fi
@echo "==> cloning repository for terraform..."
@if [ ! -d "$(TFROOT)/$(TFREPO)" ]; then \
git clone $(TFGITURL) $(TFROOT)/$(TFREPO); \
fi
@echo "==> cloning repository for ansible..."
@if [ ! -d "$(GENROOT)/$(ASREPO)" ]; then \
git clone $(ASGITURL) $(GENROOT)/$(ASREPO); \
fi
@echo "==> initializing submodules..."
@git submodule update --init
@echo "==> installing gem packages..."
@cd $(MMROOT) && \
gem install bundler && \
bundle install --retry=3 --jobs=4
clean:
@echo "==> cleaning code generation folder..."
@rm -rf $(GENROOT)
build: build-terraform build-ansible
build-terraform:
@echo "==> Generating source code for terraform..."
@if [ -z "$(RESOURCE)" ]; then \
echo "==> Generating source code for terraform from resource list..."; \
cd $(MMROOT) && \
jq '.[]' $(ROOT)/resources.json | xargs -I '{}' bundle exec compiler -d -p $(SPECROOT)/'{}' -e terraform -o $(TFROOT)/$(TFREPO)/; \
else \
echo "==> Generating source code for terraform from given name..."; \
cd $(MMROOT) && \
bundle exec compiler -d -p $(SPECROOT)/$(RESOURCE) -e terraform -o $(TFROOT)/$(TFREPO)/; \
fi
format-terraform:
@echo "==> Importing packages and formatting code for terraform..."
@cd $(TFROOT)/$(TFREPO) && \
goimports -w azurerm && \
make fmt
build-ansible:
@echo "==> Generating source code for ansible..."
@if [ -z "$(RESOURCE)" ]; then \
echo "==> Generating source code for ansible from resource list..."; \
cd $(MMROOT) && \
jq '.[]' $(ROOT)/resources.json | xargs -I '{}' bundle exec compiler -d -p $(SPECROOT)/'{}' -e ansible -o $(GENROOT)/$(ASREPO)/; \
else \
echo "==> Generating source code for ansible from given name..."; \
cd $(MMROOT) && \
bundle exec compiler -d -p $(SPECROOT)/$(RESOURCE) -e ansible -o $(GENROOT)/$(ASREPO)/; \
fi
.PHONY: init clean build build-terraform format-terraform build-ansible