Skip to content

Commit b5ca4ce

Browse files
committed
add deploy script
1 parent d26d447 commit b5ca4ce

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

bin/deploy.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
gcloud --version > /dev/null 2>&1 || { echo >&2 'gcloud is missing. aborting...'; exit 1; }
4+
npm --version > /dev/null 2>&1 || { echo >&2 "npm is missing. aborting..."; exit 1; }
5+
export NODE_PATH="$(npm root -g)"
6+
7+
if [ -z "${BRANCH_FROM}" ]; then BRANCH_FROM = "dev"; fi
8+
if [ -z "${BRANCH_TO}" ]; then BRANCH_TO = "dev"; fi
9+
if [ "${BRANCH_TO}" != "dev" ]; then THUB_ENV="-e ${BRANCH_TO}"; fi
10+
if [ "${THUB_STATE}" == "approved" ]; then THUB_APPLY="-a"; fi
11+
12+
git --version > /dev/null 2>&1 || { echo >&2 "git is missing. aborting..."; exit 1; }
13+
git checkout $BRANCH_TO
14+
git checkout $BRANCH_FROM
15+
16+
jq --version > /dev/null 2>&1 || { echo >&2 'jq is missing. aborting...'; exit 1; }
17+
GOOGLE_CLOUD_PROJECT="$(gcloud config list --format=json | jq '.core.project')"
18+
BILLING_ID="$(gcloud beta billing accounts list --format=json | jq '.[0].name[16:]')"
19+
GOOGLE_APPLICATION_CREDENTIALS="${HOME}/.config/gcloud/${GOOGLE_CLOUD_PROJECT}.json"
20+
SERVICE_ACCOUNT="terraform@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com"
21+
gcloud iam service-accounts keys create ${GOOGLE_APPLICATION_CREDENTIALS} --iam-account=${SERVICE_ACCOUNT}
22+
23+
terrahub --version > /dev/null 2>&1 || { echo >&2 "terrahub is missing. aborting..."; exit 1; }
24+
terrahub configure -c template.locals.google_project_id="${GOOGLE_CLOUD_PROJECT}"
25+
terrahub configure -c template.locals.google_billing_account="${BILLING_ID}"
26+
27+
terrahub run -y -b ${THUB_APPLY} ${THUB_ENV}
28+
echo "Execution successful: from ${BRANCH_FROM} into ${BRANCH_TO}"

0 commit comments

Comments
 (0)