2019-03-20 12:35:05 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
OS = $(strip $(shell uname -s))
|
|
|
|
ARCH = linux_amd64
|
|
|
|
PLATFORM = linux
|
|
|
|
ifeq ($(OS),Darwin)
|
|
|
|
ARCH = darwin_amd64
|
|
|
|
PLATFORM = darwin
|
|
|
|
endif
|
|
|
|
|
|
|
|
PLUGIN_DIR = ~/.terraform.d/plugins
|
|
|
|
|
|
|
|
PROVIDER_NAME = terraform-provider-ansible
|
2019-07-29 02:35:57 +00:00
|
|
|
PROVIDER_VERSION = v1.0.3
|
2019-03-20 12:35:05 +00:00
|
|
|
PROVIDER_ARCHIVE = $(PROVIDER_NAME)-$(ARCH).zip
|
|
|
|
PROVIDER_URL = https://github.com/nbering/terraform-provider-ansible/releases/download/$(PROVIDER_VERSION)/$(PROVIDER_ARCHIVE)
|
|
|
|
|
|
|
|
PROVISIONER_NAME = terraform-provisioner-ansible
|
2019-07-29 02:35:57 +00:00
|
|
|
PROVISIONER_VERSION = v2.3.0
|
2019-03-20 12:35:05 +00:00
|
|
|
PROVISIONER_ARCHIVE = $(PROVISIONER_NAME)-$(subst _,-,$(ARCH))_$(PROVISIONER_VERSION)
|
|
|
|
PROVISIONER_URL = https://github.com/radekg/terraform-provisioner-ansible/releases/download/$(PROVISIONER_VERSION)/$(PROVISIONER_ARCHIVE)
|
|
|
|
|
2019-07-29 02:35:57 +00:00
|
|
|
all: requirements install-provider install-provisioner secrets init-terraform
|
|
|
|
@echo "Success!"
|
2019-03-20 12:35:05 +00:00
|
|
|
|
|
|
|
plugins: install-provider install-provisioner
|
|
|
|
|
|
|
|
requirements:
|
|
|
|
ansible-galaxy install --ignore-errors --force -r ansible/requirements.yml
|
|
|
|
|
2019-07-29 02:35:57 +00:00
|
|
|
check-unzip:
|
|
|
|
ifeq (, $(shell which unzip))
|
|
|
|
$(error "No unzip in PATH, consider doing apt install unzip")
|
|
|
|
endif
|
2019-03-20 12:35:05 +00:00
|
|
|
|
2019-07-29 02:35:57 +00:00
|
|
|
install-provider: check-unzip
|
2019-03-20 12:35:05 +00:00
|
|
|
if [ ! -e $(PLUGIN_DIR)/$(ARCH)/$(PROVIDER_NAME)_$(PROVIDER_VERSION) ]; then \
|
|
|
|
mkdir -p $(PLUGIN_DIR); \
|
|
|
|
wget $(PROVIDER_URL) -P $(PLUGIN_DIR); \
|
|
|
|
unzip -o $(PLUGIN_DIR)/$(PROVIDER_ARCHIVE) -d $(PLUGIN_DIR); \
|
|
|
|
fi
|
|
|
|
|
|
|
|
install-provisioner:
|
|
|
|
if [ ! -e $(PLUGIN_DIR)/$(ARCH)/$(PROVISIONER_NAME)_$(PROVISIONER_VERSION) ]; then \
|
|
|
|
mkdir -p $(PLUGIN_DIR); \
|
|
|
|
wget $(PROVISIONER_URL) -O $(PLUGIN_DIR)/$(ARCH)/$(PROVISIONER_NAME)_$(PROVISIONER_VERSION); \
|
|
|
|
chmod +x $(PLUGIN_DIR)/$(ARCH)/$(PROVISIONER_NAME)_$(PROVISIONER_VERSION); \
|
|
|
|
fi
|
|
|
|
|
2019-07-29 02:35:57 +00:00
|
|
|
init-terraform:
|
|
|
|
terraform init -upgrade=true
|
|
|
|
|
2019-03-20 12:35:05 +00:00
|
|
|
secrets:
|
|
|
|
pass services/consul/ca-crt > ansible/files/consul-ca.crt
|
|
|
|
pass services/consul/ca-key > ansible/files/consul-ca.key
|
|
|
|
pass services/consul/client-crt > ansible/files/consul-client.crt
|
|
|
|
pass services/consul/client-key > ansible/files/consul-client.key
|
2019-07-29 02:35:57 +00:00
|
|
|
echo "Saving secrets to: terraform.tfvars"
|
2020-01-22 20:03:28 +00:00
|
|
|
@echo -e "\
|
2019-03-20 12:35:05 +00:00
|
|
|
# secrets extracted from password-store\n\
|
2020-01-27 14:09:21 +00:00
|
|
|
cloudflare_token = \"$(shell pass cloud/Cloudflare/token)\"\n\
|
|
|
|
cloudflare_email = \"$(shell pass cloud/Cloudflare/email)\"\n\
|
|
|
|
cloudflare_account = \"$(shell pass cloud/Cloudflare/account)\"\n\
|
|
|
|
aws_access_key = \"$(shell pass cloud/AWS/Nimbus/access-key)\"\n\
|
|
|
|
aws_secret_key = \"$(shell pass cloud/AWS/Nimbus/secret-key)\"\n\
|
2019-03-20 12:35:05 +00:00
|
|
|
" > terraform.tfvars
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
rm -r $(PLUGIN_DIR)/$(ARCHIVE)
|