Skip to content

Commit 787dd39

Browse files
authored
[terraform] - Fix terraform installation in debian trixie(13) (#1475)
* [terraform] - Fix terraform installation in debian trixie(13) * Version bump
1 parent 6a8863b commit 787dd39

File tree

5 files changed

+69
-12
lines changed

5 files changed

+69
-12
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.4.1",
3+
"version": "1.4.2",
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: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ INSTALL_SENTINEL=${INSTALLSENTINEL:-false}
1919
INSTALL_TFSEC=${INSTALLTFSEC:-false}
2020
INSTALL_TERRAFORM_DOCS=${INSTALLTERRAFORMDOCS:-false}
2121
CUSTOM_DOWNLOAD_SERVER="${CUSTOMDOWNLOADSERVER:-""}"
22+
# This is because ubuntu noble and debian trixie don't support the old format of GPG keys and validation
23+
NEW_GPG_CODENAMES="trixie noble"
2224

2325
TERRAFORM_SHA256="${TERRAFORM_SHA256:-"automatic"}"
2426
TFLINT_SHA256="${TFLINT_SHA256:-"automatic"}"
@@ -50,13 +52,11 @@ if [ "$(id -u)" -ne 0 ]; then
5052
exit 1
5153
fi
5254

53-
# Detect Ubuntu Noble and use new repo setup, else use legacy GPG logic
54-
IS_NOBLE=0
55-
if grep -qi 'ubuntu' /etc/os-release; then
56-
. /etc/os-release
57-
if [[ "$VERSION_CODENAME" == "noble" ]]; then
58-
IS_NOBLE=1
59-
fi
55+
# Detect Ubuntu Noble or Debian Trixie and use new repo setup, else use legacy GPG logic
56+
IS_GPG_NEW=0
57+
. /etc/os-release
58+
if [[ "${NEW_GPG_CODENAMES}" == *"${VERSION_CODENAME}"* ]]; then
59+
IS_GPG_NEW=1
6060
fi
6161

6262
# Get the list of GPG key servers that are reachable
@@ -112,7 +112,7 @@ receive_gpg_keys() {
112112
chmod 700 ${GNUPGHOME}
113113

114114
# Special handling for HashiCorp GPG key on Ubuntu Noble
115-
if [ "$IS_NOBLE" -eq 1 ] && [ "$keys" = "$TERRAFORM_GPG_KEY" ]; then
115+
if [ "$IS_GPG_NEW" -eq 1 ] && [ "$keys" = "$TERRAFORM_GPG_KEY" ]; then
116116
echo "(*) Ubuntu Noble detected, using Keybase for HashiCorp GPG key import...."
117117
curl -fsSL https://keybase.io/hashicorp/pgp_keys.asc | gpg --import
118118
if ! gpg --list-keys "${TERRAFORM_GPG_KEY}" > /dev/null 2>&1; then
@@ -400,7 +400,7 @@ verify_signature() {
400400

401401
receive_gpg_keys "$gpg_key"
402402
verify_result=$?
403-
if [ $verify_result -ne 0 ] && [ "$IS_NOBLE" -eq 1 ]; then
403+
if [ $verify_result -ne 0 ] && [ "$IS_GPG_NEW" -eq 1 ]; then
404404
echo "Skipping the gpg key validation for ubuntu noble as unable to import the key."
405405
return 1
406406
fi
@@ -429,7 +429,7 @@ fi
429429
if [ "${TERRAFORM_SHA256}" != "dev-mode" ]; then
430430
if [ "${TERRAFORM_SHA256}" = "automatic" ]; then
431431
# For Ubuntu Noble, try GPG verification but continue if it fails
432-
if [ "$IS_NOBLE" -eq 1 ]; then
432+
if [ "$IS_GPG_NEW" -eq 1 ]; then
433433
echo "(*) Ubuntu Noble detected - attempting GPG verification with fallback..."
434434
set +e
435435
sha256sums_url="${HASHICORP_RELEASES_URL}/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS"
@@ -543,7 +543,7 @@ if [ "${INSTALL_SENTINEL}" = "true" ]; then
543543
if [ "${SENTINEL_SHA256}" != "dev-mode" ]; then
544544
if [ "${SENTINEL_SHA256}" = "automatic" ]; then
545545
# For Ubuntu Noble, try GPG verification but continue if it fails
546-
if [ "$IS_NOBLE" -eq 1 ]; then
546+
if [ "$IS_GPG_NEW" -eq 1 ]; then
547547
echo "(*) Ubuntu Noble detected - attempting Sentinel GPG verification with fallback..."
548548
set +e
549549
sha256sums_url="${sentinel_releases_url}/${SENTINEL_VERSION}/sentinel_${SENTINEL_VERSION}_SHA256SUMS"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library
6+
source dev-container-features-test-lib
7+
8+
# Check to make sure the user is vscode
9+
check "user is vscode" whoami | grep vscode
10+
11+
# Check if terraform was installed correctly
12+
check "terraform installed" terraform --version
13+
14+
check "tflint" tflint --version
15+
16+
# Report results
17+
reportResults
18+
19+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library for `check` command
6+
source dev-container-features-test-lib
7+
8+
# Check to make sure the user is vscode
9+
check "user is vscode" whoami | grep vscode
10+
11+
# Check if terraform was installed correctly
12+
check "terraform installed" terraform --version
13+
14+
check "tflint" tflint --version
15+
16+
# Sentinel specific tests
17+
check "sentinel" sentinel --version
18+
19+
# Report result
20+
reportResults
21+
22+

test/terraform/scenarios.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
{
2+
"install_in_ubuntu_trixie": {
3+
"image": "mcr.microsoft.com/devcontainers/base:trixie",
4+
"features": {
5+
"terraform": {
6+
"version": "latest"
7+
}
8+
}
9+
},
10+
"install_in_ubuntu_trixie_sentinel": {
11+
"image": "mcr.microsoft.com/devcontainers/base:trixie",
12+
"features": {
13+
"terraform": {
14+
"installSentinel": true
15+
}
16+
}
17+
},
218
"install_in_ubuntu_noble": {
319
"image": "mcr.microsoft.com/devcontainers/base:noble",
420
"features": {

0 commit comments

Comments
 (0)