92 lines
2.3 KiB
Makefile
92 lines
2.3 KiB
Makefile
|
|
include ../config.mk
|
|
|
|
default: terraform
|
|
|
|
# I hate sed too and I am so sorry for what I'm about to do
|
|
terraform: terraform-check *.tf terraform-options
|
|
terraform init || terraform init -upgrade
|
|
terraform apply
|
|
terraform output | sed \
|
|
-e 's/\(.*\) = /\U\1 = /' \
|
|
-e 's/"//g' \
|
|
-e '' \
|
|
-e 'h;s/.* = //;s/\([.]\)/\\\1/g;x;s/ = .*//;G;s/\n/ = /' \
|
|
-e 's/ \+$$//' \
|
|
> terraform.mk
|
|
|
|
terraform-check: .toolcheck pubkey
|
|
$(eval AWS_INSTANCE_PUBLIC_KEY := $(shell sed -e 's/\//\\\//g' pubkey))
|
|
|
|
|
|
#CONFIGVARS = AWS_INSTANCE_PUBLIC_KEY AWS_SINGLE_INSTANCE_TYPE
|
|
SEDLINE =
|
|
|
|
config.tf: sedline config.tf.in ../config.mk
|
|
@sed $(SEDLINE) config.tf.in > config.tf
|
|
|
|
#configvars: ../config.mk
|
|
# $(eval CONFIGVARS := $(shell grep '^[0-9A-Z]' ../config.mk | awk '{print $1}'))
|
|
# echo $(CONFIGVARS)
|
|
|
|
#sedline: configvars $(addprefix __sed_,$(CONFIGVARS))
|
|
sedline: $(addprefix __sed_,$(shell grep '^[0-9A-Z_]' ../config.mk | awk '{print $$1}'))
|
|
|
|
__sed_%:
|
|
$(eval SEDLINE := $$(SEDLINE) -e 's/{{$*}}/$($*)/')
|
|
|
|
|
|
CHECK_TOOLS = terraform aws
|
|
|
|
# this relies on your credentials file, so that if you edit it, it will run again
|
|
.toolcheck: ~/.aws/credentials
|
|
@echo
|
|
@echo "Checking applications..."
|
|
@ FAIL=""; \
|
|
for TOOL in $(CHECK_TOOLS); do \
|
|
which $${TOOL} >/dev/null || FAIL="$${FAIL} $${TOOL}"; \
|
|
done; \
|
|
if test -n "$${FAIL}"; then \
|
|
echo "ERROR: You are missing the following:$${FAIL}"; \
|
|
echo "Please make sure all necessary tools are installed and available in your path"; \
|
|
echo; \
|
|
exit 1; \
|
|
fi
|
|
|
|
@echo
|
|
@echo "Checking AWS configuration..."
|
|
aws iam get-user
|
|
touch .toolcheck
|
|
|
|
# ...but if you don't have a credentials file, that's ok, it just runs the check every time
|
|
~/.aws/credentials:
|
|
true
|
|
|
|
pubkey:
|
|
if test -n "$(AWS_INSTANCE_PUBLIC_KEY)"; then \
|
|
echo "$(AWS_INSTANCE_PUBLIC_KEY)" > pubkey; \
|
|
else \
|
|
ssh-keygen -t rsa -N "" -f privkey && mv privkey.pub pubkey; \
|
|
fi
|
|
|
|
# optional components for terraform
|
|
terraform-options: config.tf tf-namecheap
|
|
|
|
tf-namecheap:
|
|
if test "$(DNS_NAMECHEAP)" -eq 1; then \
|
|
for FILE in namecheap/*; do \
|
|
sed $(SEDLINE) $${FILE} > $$(basename "$${FILE}"); \
|
|
done; \
|
|
else \
|
|
for FILE in namecheap/*; do \
|
|
echo rm -fv $$(basename "$${FILE}"); \
|
|
done; \
|
|
fi
|
|
|
|
|
|
|
|
# clean doesn't touch tfstate because we're not insane
|
|
clean:
|
|
rm -f privkey pubkey
|
|
rm -rf .terraform*
|
|
|