2019-07-01 23:10:24 +03:00
|
|
|
ROOT=$(shell pwd)
|
|
|
|
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:
|
2019-07-02 21:59:42 +03:00
|
|
|
@echo "==> creating folders for code generation..."
|
|
|
|
@if [ ! -d "$(TFROOT)" ]; then \
|
2019-07-01 23:10:24 +03:00
|
|
|
mkdir -p "$(TFROOT)"; \
|
|
|
|
fi
|
|
|
|
|
2019-07-02 21:59:42 +03:00
|
|
|
@echo "==> cloning repository for terraform..."
|
|
|
|
@if [ ! -d "$(TFROOT)/$(TFREPO)" ]; then \
|
2019-07-01 23:10:24 +03:00
|
|
|
git clone $(TFGITURL) $(TFROOT)/$(TFREPO); \
|
|
|
|
fi
|
|
|
|
|
2019-07-02 21:59:42 +03:00
|
|
|
@echo "==> cloning repository for ansible..."
|
|
|
|
@if [ ! -d "$(GENROOT)/$(ASREPO)" ]; then \
|
2019-07-01 23:10:24 +03:00
|
|
|
git clone $(ASGITURL) $(GENROOT)/$(ASREPO); \
|
|
|
|
fi
|
|
|
|
|
2019-07-02 21:59:42 +03:00
|
|
|
@echo "==> initializing submodules..."
|
|
|
|
@git submodule update --init
|
|
|
|
|
|
|
|
@echo "==> installing gem packages..."
|
|
|
|
@cd $(MMROOT) && \
|
2019-07-01 23:10:24 +03:00
|
|
|
gem install bundler && \
|
|
|
|
bundle install --retry=3 --jobs=4
|
|
|
|
|
|
|
|
clean:
|
2019-07-02 21:59:42 +03:00
|
|
|
@echo "==> cleaning code generation folder..."
|
|
|
|
@rm -rf $(GENROOT)
|
2019-07-01 23:10:24 +03:00
|
|
|
|
|
|
|
build: build-terraform build-ansible
|
|
|
|
|
|
|
|
build-terraform:
|
2019-07-02 21:59:42 +03:00
|
|
|
@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 $(ROOT)/'{}' -e terraform -o $(TFROOT)/$(TFREPO)/; \
|
|
|
|
else \
|
|
|
|
echo "==> Generating source code for terraform from given name..."; \
|
|
|
|
cd $(MMROOT) && \
|
|
|
|
bundle exec compiler -d -p $(ROOT)/$(RESOURCE) -e terraform -o $(TFROOT)/$(TFREPO)/; \
|
|
|
|
fi
|
2019-07-01 23:10:24 +03:00
|
|
|
|
|
|
|
format-terraform:
|
2019-07-02 21:59:42 +03:00
|
|
|
@echo "==> Importing packages and formatting code for terraform..."
|
|
|
|
@cd $(TFROOT)/$(TFREPO) && \
|
2019-07-01 23:10:24 +03:00
|
|
|
goimports -w azurerm && \
|
|
|
|
make fmt
|
|
|
|
|
|
|
|
build-ansible:
|
2019-07-02 21:59:42 +03:00
|
|
|
@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 $(ROOT)/'{}' -e ansible -o $(GENROOT)/$(ASREPO)/; \
|
|
|
|
else \
|
|
|
|
echo "==> Generating source code for ansible from given name..."; \
|
|
|
|
cd $(MMROOT) && \
|
|
|
|
bundle exec compiler -d -p $(ROOT)/$(RESOURCE) -e ansible -o $(GENROOT)/$(ASREPO)/; \
|
|
|
|
fi
|
2019-07-01 23:10:24 +03:00
|
|
|
|
|
|
|
.PHONY: init clean build build-terraform format-terraform build-ansible
|