-
Notifications
You must be signed in to change notification settings - Fork 5
/
apply-all.sh
executable file
·76 lines (61 loc) · 2.57 KB
/
apply-all.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
#!/usr/bin/env bash
CI="$1"
if [[ -f "${PWD}/terragrunt.hcl" ]]; then
if [[ -n "${CI}" ]]; then
NON_INTERACTIVE="--terragrunt-non-interactive"
fi
terragrunt run-all apply --terragrunt-parallelism 1 ${NON_INTERACTIVE} --terragrunt-exclude-dir="${PWD}/.mocks/"*
else
PARALLELISM=6
find . -type d -maxdepth 1 | grep -vE "[.]/[.].*" | grep -vE "^[.]$" | grep -v workspace | sort | \
while read dir;
do
name=$(echo "$dir" | sed -E "s~[.]/(.*)~\1~g")
TYPE=$(grep "deployment-type/gitops" ./${name}/bom.yaml | sed -E "s~[^:]+: [\"'](.*)[\"']~\1~g")
if [[ "${TYPE}" == "true" ]]; then
PARALLELISM=3
echo "***** Setting parallelism for gitops type deployment for step ${name} to ${PARALLELISM} *****"
fi
OPTIONAL=$(grep "apply-all/optional" ./${name}/bom.yaml | sed -E "s~[^:]+: [\"'](.*)[\"']~\1~g")
if [[ "${OPTIONAL}" == "true" ]]; then
echo "***** Skipping optional step ${name} *****"
continue
fi
VPN_REQUIRED=$(grep "vpn/required" ./${name}/bom.yaml | sed -E "s~[^:]+: [\"'](.*)[\"']~\1~g")
if [[ "${VPN_REQUIRED}" == "true" ]]; then
RUNNING_PROCESSES=$(ps -ef)
VPN_RUNNING=$(echo "${RUNNING_PROCESSES}" | grep "openvpn --config")
if [[ -n "${VPN_RUNNING}" ]]; then
echo "VPN required but it is already running"
elif command -v openvpn 1> /dev/null 2> /dev/null; then
OVPN_FILE=$(find . -name "*.ovpn" | head -1)
if [[ -z "${OVPN_FILE}" ]]; then
echo "VPN profile not found. Skipping ${name}"
continue
fi
echo "Connecting to vpn with profile: ${OVPN_FILE}"
sudo openvpn --config "${OVPN_FILE}" &
elif [[ -n "${CI}" ]]; then
echo "VPN connection required but unable to create the connection. Skipping..."
continue
else
echo "Please connect to your vpn instance using the .ovpn profile within the 110-ibm-fs-edge-vpc directory and press ENTER to proceed."
read throwaway
fi
echo "Connecting to vpn with profile: ${OVPN_FILE}"
sudo openvpn --config "${OVPN_FILE}" &
elif [[ -n "${CI}" ]]; then
echo "VPN connection required but unable to create the connection. Skipping..."
continue
else
echo "Please connect to your vpn instance using the .ovpn profile within the 110-ibm-vpc-edge-* directory and press ENTER to proceed."
read throwaway
fi
echo "***** Applying ${name} *****"
cd "${name}" && \
terraform init && \
terraform apply -parallelism=$PARALLELISM -auto-approve && \
cd - 1> /dev/null || \
exit 1
done
fi