|
|
|
#!/usr/bin/env bash
|
|
|
|
# vim:ts=4:sts=4:sw=4:et
|
|
|
|
#
|
|
|
|
# Author: Hari Sekhon
|
|
|
|
# Date: Mon Feb 22 17:42:01 2021 +0000
|
|
|
|
#
|
|
|
|
# https://github.com/HariSekhon/DevOps-Bash-tools
|
|
|
|
#
|
|
|
|
# License: see accompanying Hari Sekhon LICENSE file
|
|
|
|
#
|
|
|
|
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
|
|
|
|
#
|
|
|
|
# https://www.linkedin.com/in/HariSekhon
|
|
|
|
#
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
[ -n "${DEBUG:-}" ] && set -x
|
|
|
|
srcdir="$(dirname "${BASH_SOURCE[0]}")"
|
|
|
|
|
|
|
|
export TERRAFORM_VERSION=1.1.9
|
|
|
|
|
|
|
|
tfenv_list_sed(){
|
|
|
|
sed 's/^\*[[:space:]]*//; s/(.*//; s/[[:space:]]//g'
|
|
|
|
}
|
|
|
|
|
|
|
|
if type -P tfenv &>/dev/null; then
|
|
|
|
if ! tfenv list | tfenv_list_sed | grep -Fxq "$TERRAFORM_VERSION"; then
|
|
|
|
echo "Terraform version '$TERRAFORM_VERSION' not installed in tfenv, installing now..."
|
|
|
|
tfenv install "$TERRAFORM_VERSION"
|
|
|
|
fi
|
|
|
|
current_version="$(tfenv list | grep '^\*' | tfenv_list_sed)"
|
|
|
|
if [ "$current_version" != "$TERRAFORM_VERSION" ]; then
|
|
|
|
# XXX: Careful, this will switch globally and could cause race conditions with other shells / scripts on the same machine
|
|
|
|
tfenv use "$TERRAFORM_VERSION"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# XXX: set these or other variables for Terraform code to find
|
|
|
|
export CLOUDFLARE_EMAIL=hari@...
|
|
|
|
export CLOUDFLARE_API_KEY=... # generate here: https://dash.cloudflare.com/profile/api-tokens
|
|
|
|
#export CLOUDFLARE_TOKEN=... # used by cloudflare_api.sh but not by terraform module
|
|
|
|
|
|
|
|
# export the variables for terraform
|
|
|
|
export TF_VAR_cloudflare_email="$CLOUDFLARE_EMAIL"
|
|
|
|
export TF_VAR_cloudflare_api_key="$CLOUDFLARE_API_KEY" # must be a key, not a token using the link above
|
|
|
|
|
|
|
|
# interfere with GitHub provider
|
|
|
|
for env_var in $(env | awk -F= '$1 ~ /GITHUB/ {print $1}'); do
|
|
|
|
unset "$env_var"
|
|
|
|
done
|