2023-11-12 16:50:05 -08:00
|
|
|
|
|
|
|
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
|
2024-01-18 18:14:17 -08:00
|
|
|
terraform init || terraform init -upgrade
|
2023-11-12 16:50:05 -08:00
|
|
|
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
|
|
|
|
|
2024-01-18 18:14:17 -08:00
|
|
|
terraform-check: .toolcheck pubkey
|
2023-11-12 16:50:05 -08:00
|
|
|
$(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
|
|
|
|
|
2024-01-18 18:14:17 -08:00
|
|
|
# this relies on your credentials file, so that if you edit it, it will run again
|
|
|
|
.toolcheck: ~/.aws/credentials
|
2023-11-12 16:50:05 -08:00
|
|
|
@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
|
2024-01-18 18:14:17 -08:00
|
|
|
touch .toolcheck
|
|
|
|
|
|
|
|
# ...but if you don't have a credentials file, that's ok, it just runs the check every time
|
|
|
|
~/.aws/credentials:
|
|
|
|
true
|
2023-11-12 16:50:05 -08:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
# clean doesn't touch tfstate because we're not insane
|
|
|
|
clean:
|
|
|
|
rm -f privkey pubkey
|
|
|
|
rm -rf .terraform*
|
|
|
|
|