Skip to content

Commit 66c73df

Browse files
authored
[terraform] Add Custom Download Server Support for Terraform Dev Container Feature (#1364)
* Add custom download server option to download terraform * Bump Terraform version to 1.4.0 in devcontainer feature configuration * Update custom download server documentation and implementation to require full URL with protocol * Remove my changes from an auto-generated file * Remove my changes from an auto-generated file * Add security considerations for custom download servers in documentation * Update security considerations section in documentation with warning icon * Return leading empty lines back to NOTES.md * Fix formatting in custom download server scripts by ensuring consistent newline handling and invoking reportResults function.
1 parent 94ed0bb commit 66c73df

File tree

6 files changed

+95
-5
lines changed

6 files changed

+95
-5
lines changed

src/terraform/NOTES.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@
44

55
On August 10, 2023, HashiCorp announced a change of license for its products, including Terraform. After ~9 years of Terraform being open source under the MPL v2 license, it was to move under a non-open source BSL v1.1 license, starting from the next (1.6) version. See https://github.com/hashicorp/terraform/blob/main/LICENSE
66

7+
## Custom Download Server
8+
9+
The `customDownloadServer` option allows you to specify an alternative server for downloading Terraform and Sentinel packages. This is useful for organizations that maintain internal mirrors or have proxies for HashiCorp downloads.
10+
11+
When using this option:
12+
- Provide the complete URL including protocol (e.g., `https://my-mirror.example.com`)
13+
- The server should mirror the HashiCorp releases structure
14+
15+
Example:
16+
```json
17+
"features": {
18+
"ghcr.io/devcontainers/features/terraform:1": {
19+
"customDownloadServer": "https://my-mirror.example.com"
20+
}
21+
}
22+
```
23+
24+
### ⚠️ Security Considerations
25+
26+
When using a custom download server, be aware of the following security implications:
27+
28+
- **Server Verification**: Always verify that the custom server is trustworthy and maintained by your organization or a trusted entity. Using an untrusted or compromised server could lead to downloading malicious software.
29+
30+
- **Supply Chain Risks**: Malicious actors may attempt to distribute compromised versions of Terraform that contain backdoors, cryptominers, or other harmful code.
31+
32+
- **Integrity Checks**: The feature performs SHA256 checks when available, but these are only as trustworthy as the source of the checksums. If both the binaries and checksums come from a compromised server, the integrity check may pass despite the software being malicious.
33+
34+
- **Organizational Policy**: Ensure your custom download server adheres to your organization's security policies and implements proper access controls.
35+
36+
Always use the official HashiCorp download server (https://releases.hashicorp.com) unless you have a specific need for an alternative source.
37+
738
## OS Support
839

940
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.

src/terraform/devcontainer-feature.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "terraform",
3-
"version": "1.3.10",
3+
"version": "1.4.0",
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.",
@@ -54,6 +54,11 @@
5454
"type": "string",
5555
"default": "",
5656
"description": "Connect to a keyserver using a proxy by configuring this option"
57+
},
58+
"customDownloadServer": {
59+
"type": "string",
60+
"default": "",
61+
"description": "Custom server URL for downloading Terraform and Sentinel packages, including protocol (e.g., https://releases.hashicorp.com). If not provided, the default HashiCorp download server (https://releases.hashicorp.com) will be used."
5762
}
5863
},
5964
"customizations": {

src/terraform/install.sh

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ TERRAGRUNT_VERSION="${TERRAGRUNT:-"latest"}"
1818
INSTALL_SENTINEL=${INSTALLSENTINEL:-false}
1919
INSTALL_TFSEC=${INSTALLTFSEC:-false}
2020
INSTALL_TERRAFORM_DOCS=${INSTALLTERRAFORMDOCS:-false}
21+
CUSTOM_DOWNLOAD_SERVER="${CUSTOMDOWNLOADSERVER:-""}"
2122

2223
TERRAFORM_SHA256="${TERRAFORM_SHA256:-"automatic"}"
2324
TFLINT_SHA256="${TFLINT_SHA256:-"automatic"}"
@@ -26,6 +27,11 @@ SENTINEL_SHA256="${SENTINEL_SHA256:-"automatic"}"
2627
TFSEC_SHA256="${TFSEC_SHA256:-"automatic"}"
2728
TERRAFORM_DOCS_SHA256="${TERRAFORM_DOCS_SHA256:-"automatic"}"
2829

30+
HASHICORP_RELEASES_URL="https://releases.hashicorp.com"
31+
if [ -n "${CUSTOM_DOWNLOAD_SERVER}" ]; then
32+
HASHICORP_RELEASES_URL="${CUSTOM_DOWNLOAD_SERVER}"
33+
fi
34+
2935
TERRAFORM_GPG_KEY="72D7468F"
3036
TFLINT_GPG_KEY_URI="https://raw.githubusercontent.com/terraform-linters/tflint/v0.46.1/8CE69160EB3F2FE9.key"
3137
KEYSERVER_PROXY="${HTTPPROXY:-"${HTTP_PROXY:-""}"}"
@@ -357,7 +363,7 @@ find_version_from_git_tags TERRAGRUNT_VERSION "$terragrunt_url"
357363
install_terraform() {
358364
local TERRAFORM_VERSION=$1
359365
terraform_filename="terraform_${TERRAFORM_VERSION}_linux_${architecture}.zip"
360-
curl -sSL -o ${terraform_filename} "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/${terraform_filename}"
366+
curl -sSL -o ${terraform_filename} "${HASHICORP_RELEASES_URL}/terraform/${TERRAFORM_VERSION}/${terraform_filename}"
361367
}
362368

363369
mkdir -p /tmp/tf-downloads
@@ -373,8 +379,8 @@ fi
373379
if [ "${TERRAFORM_SHA256}" != "dev-mode" ]; then
374380
if [ "${TERRAFORM_SHA256}" = "automatic" ]; then
375381
receive_gpg_keys TERRAFORM_GPG_KEY
376-
curl -sSL -o terraform_SHA256SUMS https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS
377-
curl -sSL -o terraform_SHA256SUMS.sig https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.${TERRAFORM_GPG_KEY}.sig
382+
curl -sSL -o terraform_SHA256SUMS "${HASHICORP_RELEASES_URL}/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS"
383+
curl -sSL -o terraform_SHA256SUMS.sig "${HASHICORP_RELEASES_URL}/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_SHA256SUMS.${TERRAFORM_GPG_KEY}.sig"
378384
gpg --verify terraform_SHA256SUMS.sig terraform_SHA256SUMS
379385
else
380386
echo "${TERRAFORM_SHA256} *${terraform_filename}" > terraform_SHA256SUMS
@@ -464,7 +470,7 @@ fi
464470

465471
if [ "${INSTALL_SENTINEL}" = "true" ]; then
466472
SENTINEL_VERSION="latest"
467-
sentinel_releases_url='https://releases.hashicorp.com/sentinel'
473+
sentinel_releases_url="${HASHICORP_RELEASES_URL}/sentinel"
468474
find_sentinel_version_from_url SENTINEL_VERSION ${sentinel_releases_url}
469475
sentinel_filename="sentinel_${SENTINEL_VERSION}_linux_${architecture}.zip"
470476
echo "(*) Downloading Sentinel... ${sentinel_filename}"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library
6+
source dev-container-features-test-lib
7+
8+
# Check if terraform was installed correctly and it's the expected version
9+
check "terraform installed" terraform --version
10+
check "terraform version matches" terraform --version | grep "1.6.5"
11+
12+
# Report results
13+
reportResults
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Import test library
6+
source dev-container-features-test-lib
7+
8+
# Check if terraform was installed correctly and it's the expected version
9+
check "terraform installed" terraform --version
10+
check "terraform version matches" terraform --version | grep "1.6.5"
11+
12+
# Check if sentinel was installed correctly
13+
check "sentinel installed" sentinel --version
14+
15+
# Report results
16+
reportResults

test/terraform/scenarios.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,24 @@
7070
"tflint": "0.40.0"
7171
}
7272
}
73+
},
74+
"custom_download_server": {
75+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
76+
"features": {
77+
"terraform": {
78+
"version": "1.6.5",
79+
"customDownloadServer": "https://releases.hashicorp.com"
80+
}
81+
}
82+
},
83+
"custom_download_server_with_sentinel": {
84+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
85+
"features": {
86+
"terraform": {
87+
"version": "1.6.5",
88+
"installSentinel": true,
89+
"customDownloadServer": "https://releases.hashicorp.com"
90+
}
91+
}
7392
}
7493
}

0 commit comments

Comments
 (0)