2023-03-13 14:42:11 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
|
|
username=`whoami`
|
2023-08-25 12:25:18 -04:00
|
|
|
org="gsa-tts-benefits-studio"
|
2023-03-13 14:42:11 -04:00
|
|
|
|
|
|
|
|
usage="
|
|
|
|
|
$0: Create development infrastructure
|
|
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
|
$0 -h
|
2023-04-17 15:17:43 -04:00
|
|
|
$0 [-u <USER NAME>] [-k] [-d]
|
2023-03-13 14:42:11 -04:00
|
|
|
|
|
|
|
|
Options:
|
|
|
|
|
-h: show help and exit
|
|
|
|
|
-u <USER NAME>: your username. Default: $username
|
|
|
|
|
-k: keep service user. Default is to remove them after run
|
|
|
|
|
-d: Destroy development resources. Default is to create them
|
|
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
|
* Requires cf-cli@8
|
|
|
|
|
* Requires terraform/development to be run on API app first, with the same [-u <USER NAME>]
|
|
|
|
|
"
|
|
|
|
|
|
|
|
|
|
action="apply"
|
|
|
|
|
creds="remove"
|
|
|
|
|
|
|
|
|
|
while getopts ":hkdu:" opt; do
|
|
|
|
|
case "$opt" in
|
|
|
|
|
u)
|
|
|
|
|
username=${OPTARG}
|
|
|
|
|
;;
|
|
|
|
|
k)
|
|
|
|
|
creds="keep"
|
|
|
|
|
;;
|
|
|
|
|
d)
|
|
|
|
|
action="destroy"
|
|
|
|
|
;;
|
|
|
|
|
h)
|
|
|
|
|
echo "$usage"
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
service_account="$username-terraform"
|
|
|
|
|
|
2023-03-15 16:38:16 -04:00
|
|
|
# ensure we're in the correct directory
|
|
|
|
|
cd $(dirname $0)
|
|
|
|
|
|
2023-03-14 16:00:40 -04:00
|
|
|
if [[ ! -s "secrets.auto.tfvars" ]]; then
|
2023-03-13 14:42:11 -04:00
|
|
|
# create user in notify-local-dev space to create s3 buckets
|
|
|
|
|
../create_service_account.sh -s notify-local-dev -u $service_account > secrets.auto.tfvars
|
|
|
|
|
fi
|
|
|
|
|
|
2023-03-14 16:00:40 -04:00
|
|
|
if [[ ! -f "../../.env" ]]; then
|
|
|
|
|
cp ../../sample.env ../../.env
|
|
|
|
|
fi
|
|
|
|
|
|
2023-03-13 14:42:11 -04:00
|
|
|
set +e
|
|
|
|
|
|
|
|
|
|
terraform init
|
|
|
|
|
terraform $action -var="username=$username"
|
|
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
|
|
if [[ $creds = "remove" ]]; then
|
|
|
|
|
../destroy_service_account.sh -s notify-local-dev -u $service_account
|
|
|
|
|
rm secrets.auto.tfvars
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
exit 0
|