-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9b6053
commit 54e0c43
Showing
4 changed files
with
143 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
ACTION=$1 | ||
ENV=$2 | ||
shift 2 | ||
other="$@" | ||
# must be subscription in lower case | ||
subscription="" | ||
BACKEND_CONFIG_PATH="./env/${ENV}/backend.tfvars" | ||
|
||
if [ -z "$ACTION" ]; then | ||
echo "[ERROR] Missed ACTION: init, apply, plan" | ||
exit 0 | ||
fi | ||
|
||
if [ -z "$ENV" ]; then | ||
echo "[ERROR] ENV should be: dev, uat or prod." | ||
exit 0 | ||
fi | ||
|
||
# | ||
# 🏁 Source & init shell | ||
# | ||
|
||
# shellcheck source=/dev/null | ||
source "./env/$ENV/backend.ini" | ||
|
||
# Subscription set | ||
az account set -s "${subscription}" | ||
|
||
# if using cygwin, we have to transcode the WORKDIR | ||
if [[ $WORKDIR == /cygdrive/* ]]; then | ||
WORKDIR=$(cygpath -w $WORKDIR) | ||
fi | ||
|
||
# Helm | ||
export HELM_DEBUG=1 | ||
export TF_VAR_github_token="${GITHUB_TOKEN}" | ||
# TODO set your PAT TOKEN as env var | ||
if [ -z "$GITHUB_TOKEN" ]; then | ||
echo "Error: Set an environment variable named GITHUB_TOKEN with your GitHub PAT Token" | ||
exit 1 | ||
fi | ||
|
||
# | ||
# 🌎 Terraform | ||
# | ||
if echo "init plan apply refresh import output state taint destroy" | grep -w "$ACTION" > /dev/null; then | ||
if [ "$ACTION" = "init" ]; then | ||
echo "[INFO] init tf on ENV: ${ENV}" | ||
terraform "$ACTION" -backend-config="${BACKEND_CONFIG_PATH}" $other | ||
elif [ "$ACTION" = "output" ] || [ "$ACTION" = "state" ] || [ "$ACTION" = "taint" ]; then | ||
# init terraform backend | ||
terraform init -reconfigure -backend-config="${BACKEND_CONFIG_PATH}" | ||
terraform "$ACTION" $other | ||
else | ||
# init terraform backend | ||
echo "[INFO] init tf on ENV: ${ENV}" | ||
terraform init -reconfigure -backend-config="${BACKEND_CONFIG_PATH}" | ||
|
||
echo "[INFO] run tf with: ${ACTION} on ENV: ${ENV} and other: >${other}<" | ||
terraform "${ACTION}" -var-file="./env/${ENV}/terraform.tfvars" -compact-warnings $other | ||
fi | ||
else | ||
echo "[ERROR] ACTION not allowed." | ||
exit 1 | ||
fi |