-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathinit.sh
36 lines (31 loc) · 1.36 KB
/
init.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
set -x
# Initialize terraform
if [[ -n "<< parameters.backend_config_file >>" ]]; then
for file in $(echo "<< parameters.backend_config_file >>" | tr ',' '\n'); do
if [[ -f "$file" ]]; then
# chdir needs files to be specified relative to the terraform
# config file, so change this to be a relative path
rel_path=$(realpath --relative-to ${module_path} ${file})
INIT_ARGS="$INIT_ARGS -backend-config=${rel_path}"
elif [[ -f "$module_path/$file" ]]; then
INIT_ARGS="$INIT_ARGS -backend-config=$file"
else
echo "Backend config '$file' wasn't found" >&2
exit 1
fi
done
fi
if [[ -n "<< parameters.backend_config >>" ]]; then
for config in $(echo "<< parameters.backend_config >>" | tr ',' '\n'); do
INIT_ARGS="$INIT_ARGS -backend-config=$config"
done
fi
export INIT_ARGS
# Set workspace from parameter, allowing it to be overridden by TF_WORKSPACE.
# If TF_WORKSPACE is set we don't want terraform init to use the value, in the case we are running new_workspace.sh this would cause an error
readonly workspace_parameter="<< parameters.workspace >>"
readonly workspace="${TF_WORKSPACE:-$workspace_parameter}"
export workspace
unset TF_WORKSPACE
rm -rf ${module_path}/.terraform
terraform -chdir=${module_path} init -input=false -no-color $INIT_ARGS