Skip to content

Commit 90a9b1d

Browse files
[terraform] Update retry logic to handle DNS-related errors more gracefully (#713)
* [terraform] Update retry logic - Add `dnsutils` package to dependencies - Update retry logic to handle DNS-related errors more gracefully * Update install.sh * Bump version
1 parent c3f9105 commit 90a9b1d

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/terraform/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "terraform",
3-
"version": "1.3.4",
3+
"version": "1.3.5",
44
"name": "Terraform, tflint, and TFGrunt",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/terraform",
66
"description": "Installs the Terraform CLI and optionally TFLint and Terragrunt. Auto-detects latest version and installs needed dependencies.",

src/terraform/install.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ receive_gpg_keys() {
7777
sleep 10s
7878
fi
7979
done
80+
81+
# If all attempts fail, try getting the keyserver IP address and explicitly passing it to gpg
82+
if [ "${gpg_ok}" = "false" ]; then
83+
retry_count=0;
84+
echo "(*) Resolving GPG keyserver IP address..."
85+
local keyserver_ip_address=$( dig +short keyserver.ubuntu.com | head -n1 )
86+
echo "(*) GPG keyserver IP address $keyserver_ip_address"
87+
88+
until [ "${gpg_ok}" = "true" ] || [ "${retry_count}" -eq "3" ];
89+
do
90+
echo "(*) Downloading GPG key..."
91+
( echo "${keys}" | xargs -n 1 gpg -q ${keyring_args} --recv-keys --keyserver ${keyserver_ip_address}) 2>&1 && gpg_ok="true"
92+
if [ "${gpg_ok}" != "true" ]; then
93+
echo "(*) Failed getting key, retring in 10s..."
94+
(( retry_count++ ))
95+
sleep 10s
96+
fi
97+
done
98+
fi
8099
set -e
81100
if [ "${gpg_ok}" = "false" ]; then
82101
echo "(!) Failed to get gpg key."
@@ -183,7 +202,7 @@ ensure_cosign() {
183202
export DEBIAN_FRONTEND=noninteractive
184203

185204
# Install dependencies if missing
186-
check_packages curl ca-certificates gnupg2 dirmngr coreutils unzip
205+
check_packages curl ca-certificates gnupg2 dirmngr coreutils unzip dnsutils
187206
if ! type git > /dev/null 2>&1; then
188207
check_packages git
189208
fi

0 commit comments

Comments
 (0)