-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy patharchiveProvisionState.sh
More file actions
executable file
·52 lines (45 loc) · 1.48 KB
/
archiveProvisionState.sh
File metadata and controls
executable file
·52 lines (45 loc) · 1.48 KB
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
#!/bin/bash -e
export PROV_CONTEXT=$1
export PROV_ENV=$2
export TF_FOLDER="$PROV_CONTEXT-$PROV_ENV"
export RES_STATE=$PROV_CONTEXT"_"$PROV_ENV"_state"
export RES_REPO="inf_repo"
export RES_REPO_UP=$(echo $RES_REPO | awk '{print toupper($0)}')
export RES_REPO_STATE=$(eval echo "$"$RES_REPO_UP"_STATE") #loc of git repo clone
test_context() {
echo "PROV_CONTEXT=$PROV_CONTEXT"
echo "PROV_ENV=$PROV_ENV"
echo "RES_REPO=$RES_REPO"
echo "TF_FOLDER=$TF_FOLDER"
echo "RES_STATE=$RES_STATE"
echo "RES_REPO_UP=$RES_REPO_UP"
echo "RES_REPO_STATE=$RES_REPO_STATE"
}
arch_statefile() {
pushd "$RES_REPO_STATE/$TF_FOLDER"
if [ -f "terraform.tfstate" ]; then
echo "new state file exists, copying"
echo "-----------------------------------"
# cp -vr terraform.tfstate /build/state
shipctl copy_file_to_resource_state terraform.tfstate $RES_STATE
else
# this is a safety measure, if this existed, the above if itself would have
# yielded a state file
local prev_state_loc="$JOB_PREVIOUS_STATE/terraform.tfstate"
if [ -f "$prev_state_loc" ]; then
echo "previous state file exists, copying $prev_state_loc"
echo "-----------------------------------"
# cp -vr $prev_state_loc /build/state
shipctl copy_file_to_resource_state $prev_state_loc $RES_STATE
else
echo "No previous state file exists at $prev_state_loc, skip copying"
echo "-----------------------------------"
fi
fi
popd
}
main() {
test_context
arch_statefile
}
main