From 2a010e03aa21b3c7d0836955129cfd39c130bd3c Mon Sep 17 00:00:00 2001 From: Thomas Hintz Date: Tue, 19 Aug 2025 17:18:04 -0700 Subject: [PATCH] Also generated tfvars from apps.config. --- .gitignore | 4 +++- Makefile | 11 +++++++---- make-generated.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) create mode 100755 make-generated.sh diff --git a/.gitignore b/.gitignore index 1d65957..dca601d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,6 @@ app apps.config -all-apps/lb/Caddyfile \ No newline at end of file +# generated files +all-apps/lb/Caddyfile +generated.tfvars \ No newline at end of file diff --git a/Makefile b/Makefile index 9da0c82..2df9ee3 100644 --- a/Makefile +++ b/Makefile @@ -12,11 +12,14 @@ all-apps/lb/Caddyfile: apps.config make-caddyfile.sh ignition.json: cl.yaml app/.dirstamp all-apps/lb/Caddyfile cat cl.yaml | sudo docker run --rm --volume /home/tjhintz/.ssh/id_rsa.pub:/pwd/ssh-keys --volume ${PWD}:/pwd --workdir /pwd -i quay.io/coreos/butane:latest -d /pwd > ignition.json -plan: ignition.json - terraform plan -var-file $(TERRAFORM_ENV).tfvars +generated.tfvars: apps.config make-generated.sh + ./make-generated.sh > generated.tfvars -apply: ignition.json - terraform apply -var-file $(TERRAFORM_ENV).tfvars +plan: ignition.json $(TERRAFORM_ENV).tfvars generated.tfvars + bash -c "terraform plan -var-file=<(cat $(TERRAFORM_ENV).tfvars generated.tfvars)" + +apply: ignition.json $(TERRAFORM_ENV).tfvars generated.tfvars + bash -c "terraform apply -var-file=<(cat $(TERRAFORM_ENV).tfvars generated.tfvars)" ## to help me remember the command to run to test the config locally testlocalhost: diff --git a/make-generated.sh b/make-generated.sh new file mode 100755 index 0000000..3cadf26 --- /dev/null +++ b/make-generated.sh @@ -0,0 +1,40 @@ +#!/bin/bash + +# this script generates the shared values for the +# terraform config (domain & subdomain variables) + +# it depends on apps.config which should define: +# ROOT_DOMAIN - the root domain for all apps +# APP_CONFIGS - app-subdomain pairs, configured via a comma, like: +# app1,subdomain1 app2,subdomain2 app3,subdomain3 +# full example: +# ROOT_DOMAIN=nassella.cc +# APP_CONFIGS="app1,subdomain1 app2,subdomain2 app3,subdomain3" + +set -e + +. apps.config + +read -r -a APP_CONFIGS <<< "$APP_CONFIGS" +APP_CONFIGS+=('lb,root') + +echo "domain = \"$ROOT_DOMAIN\"" +echo -n "subdomains = [" + +separator='' + +for config_string in ${APP_CONFIGS[@]}; do + IFS=',' + read -r -a config <<< "$config_string" + + subdomain=${config[1]} + + echo -n "$separator" + echo -n "\"$subdomain\"" + + separator=', ' +done + +echo "]" + +