-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathsetup.sh
76 lines (61 loc) · 2.23 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
set -x
# 'path' is a required parameter, save it as module_path
readonly module_path="<< parameters.path >>"
export path=$module_path
if [[ ! -d "$module_path" ]]; then
echo "Path does not exist: \"$module_path\""
exit 1
fi
# Select the correct terraform version - this will persist for the rest of the job
if hash tfswitch 2>/dev/null; then
(cd "$module_path" && echo "" | tfswitch | grep -e Switched -e Reading | sed 's/^.*Switched/Switched/')
fi
# Check the terraform version is >= 0.14
tf_version=$(terraform version -json | jq -r .terraform_version)
if [ $(echo $tf_version | cut -d '.' -f 1) -lt 1 ] && [ $(echo $tf_version | cut -d '.' -f 2) -lt 14 ]; then
echo "Your version of terraform is too old. The terraform v2 orb only supports terraform >= 0.14"
exit 1
fi
set +x
if [ -n "$TF_REGISTRY_TOKEN" ]; then
echo "credentials \"$TF_REGISTRY_HOST\" { token = \"$TF_REGISTRY_TOKEN\" }" >>$HOME/.terraformrc
fi
set -x
# Set TF environment variables
# These are already set in the dockerfile, but set again just in case the orb is used with a different executor
export TF_INPUT=false
export TF_PLUGIN_CACHE_DIR=/usr/local/share/terraform/plugin-cache
export TF_IN_AUTOMATION=yep
# Configure cloud credentials
GCLOUD_SERVICE_KEY="${GCLOUD_SERVICE_KEY:-$GOOGLE_SERVICE_ACCOUNT}"
if [[ -n "$GCLOUD_SERVICE_KEY" ]]; then
if echo "$GCLOUD_SERVICE_KEY" | grep "{" >/dev/null; then
echo "$GCLOUD_SERVICE_KEY" >/tmp/google_creds
else
echo "$GCLOUD_SERVICE_KEY" \
| base64 --decode --ignore-garbage \
>/tmp/google_creds
fi
export GOOGLE_APPLICATION_CREDENTIALS=/tmp/google_creds
gcloud auth activate-service-account --key-file /tmp/google_creds
fi
if [[ -n "$GOOGLE_PROJECT_ID" ]]; then
gcloud --quiet config set project "$GOOGLE_PROJECT_ID"
fi
if [[ -n "$GOOGLE_COMPUTE_ZONE" ]]; then
gcloud --quiet config set compute/zone "$GOOGLE_COMPUTE_ZONE"
fi
# Put Aiven's provider in place if requested
if [[ -n "$AIVEN_PROVIDER" ]]; then
ln -fs /root/aiven/* /root/.terraform.d/plugins/
fi
# Detect tfmask
TFMASK=tfmask
if ! hash $TFMASK 2>/dev/null; then
TFMASK=cat
fi
# Detect compact_plan
COMPACT_PLAN=compact_plan
if ! hash $COMPACT_PLAN 2>/dev/null; then
COMPACT_PLAN=cat
fi