Skip to content

Commit 1ea1b02

Browse files
committed
Added retry logic for all off box calls
1 parent bba4542 commit 1ea1b02

File tree

1 file changed

+57
-36
lines changed
  • solution_template/vm-linux-terraform/scripts

1 file changed

+57
-36
lines changed

solution_template/vm-linux-terraform/scripts/infra.sh

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,67 @@ sudo apt-get install unzip
88

99
sudo apt-get update
1010

11-
retry=0
12-
while true;do
13-
TF_VERSION=$(curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M ".current_version") && break || ((retry++))
14-
((retry >= 10)) && break
15-
done
16-
17-
retry=0
18-
while true;do
19-
wget -O terraform.zip https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip && break || ((retry++))
20-
((retry >= 10)) && break
21-
done
22-
23-
retry=0
24-
while true;do
25-
wget -O terraform.sha256 https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS && break || ((retry++))
26-
((retry >= 10)) && break
27-
done
28-
29-
retry=0
30-
while true;do
31-
wget -O terraform.sha256.sig https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS.sig && break || ((retry++))
32-
((retry >= 10)) && break
33-
done
34-
35-
retry=0
36-
while true;do
37-
curl -s https://keybase.io/hashicorp/pgp_keys.asc | gpg --import && break || ((retry++))
38-
((retry >= 10)) && break
39-
done
40-
41-
retry=0
42-
while true;do
43-
gpg --verify terraform.sha256.sig terraform.sha256 && break || ((retry++))
44-
((retry >= 10)) && break
45-
done
11+
for i in {1..10}; do curl -f -o TFVersion.json "https://checkpoint-api.hashicorp.com/v1/check/terraform" && break || sleep 1; done
12+
13+
if [ ! -f TFVersion.json ]; then
14+
echo "TFVersion.json not found!"
15+
exit 1
16+
fi
17+
18+
TF_VERSION=$(jq -r -M ".current_version" TFVersion.json)
19+
echo $TF_VERSION
20+
21+
for i in {1..10}; do curl -f -o terraform.zip "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip" && break || sleep 1; done
22+
23+
if [ ! -f terraform.zip ]; then
24+
echo "terraform.zip not found!"
25+
exit 1
26+
fi
27+
28+
for i in {1..10}; do curl -f -o terraform.sha256 "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS" && break || sleep 1; done
29+
30+
if [ ! -f terraform.sha256 ]; then
31+
echo "terraform.sha256 not found!"
32+
exit 1
33+
fi
34+
35+
for i in {1..10}; do curl -f -o terraform.sha256.sig "https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_SHA256SUMS.sig" && break || sleep 1; done
36+
37+
if [ ! -f terraform.sha256.sig ]; then
38+
echo "terraform.sha256.sig not found!"
39+
exit 1
40+
fi
41+
42+
for i in {1..10}; do curl -s -f -o pgp_key.asc "https://keybase.io/hashicorp/pgp_keys.asc" && break || sleep 1; done
43+
44+
if [ ! -f pgp_key.asc ]; then
45+
echo "pgp_key.asc not found!"
46+
exit 1
47+
fi
48+
49+
gpg --import pgp_key.asc
50+
51+
if [ ! $? -eq 0 ]; then
52+
echo "Failed to import pgp key."
53+
exit 1
54+
fi
55+
56+
gpg --verify terraform.sha256.sig terraform.sha256
57+
58+
59+
if [ ! $? -eq 0 ]; then
60+
echo "Terraform signatures failed validation."
61+
exit 1
62+
fi
4663

4764
echo $(grep -Po "[[:xdigit:]]{64}(?=\s+terraform_${TF_VERSION}_linux_amd64.zip)" terraform.sha256) terraform.zip | sha256sum -c
65+
4866
unzip terraform.zip
67+
4968
mv terraform /usr/local/bin
50-
rm -f terraform terraform.zip terraform.sha256 terraform.sha256.sig
69+
70+
rm -f terraform terraform.zip terraform.sha256 terraform.sha256.sig pgp_key.asc TFVersion.json
71+
5172
unset TF_VERSION
5273

5374
echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" | sudo tee /etc/apt/sources.list.d/azure-cli.list

0 commit comments

Comments
 (0)