Skip to content

Commit d1a2d48

Browse files
committed
feat: update Terraform installation script and add apt update command
1 parent 73b2e46 commit d1a2d48

File tree

2 files changed

+6
-69
lines changed

2 files changed

+6
-69
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
FROM mcr.microsoft.com/devcontainers/base:jammy
1+
FROM mcr.microsoft.com/devcontainers/base:jammy
2+
3+
RUN apt update
Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,6 @@
11
#!/usr/bin/env bash
2+
curl "https://releases.hashicorp.com/terraform/1.10.5/terraform_1.10.5_linux_arm64.zip" -o "terraform.zip" \
23

3-
# Script to install Terraform on Linux
4-
# Date: 2025-02-27
4+
unzip terraform.zip
55

6-
set -e
7-
8-
# Print colored output
9-
print_message() {
10-
echo -e "\e[1;34m>> $1\e[0m"
11-
}
12-
13-
# Check if script is run as root
14-
if [ "$(id -u)" -ne 0 ]; then
15-
echo "This script must be run as root or with sudo privileges."
16-
exit 1
17-
fi
18-
19-
print_message "Installing dependencies..."
20-
apt-get update
21-
apt-get install -y curl unzip
22-
23-
# Get latest version
24-
print_message "Determining latest Terraform version..."
25-
LATEST_VERSION=$(curl -s https://releases.hashicorp.com/terraform/ | grep -Eo 'href="/terraform/[0-9]+\.[0-9]+\.[0-9]+"' | head -1 | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+')
26-
27-
if [ -z "$LATEST_VERSION" ]; then
28-
print_message "Failed to determine the latest Terraform version. Defaulting to 1.8.4"
29-
LATEST_VERSION="1.8.4"
30-
fi
31-
32-
print_message "Latest Terraform version: $LATEST_VERSION"
33-
34-
# Set architecture
35-
ARCH=$(uname -m)
36-
if [ "$ARCH" = "x86_64" ]; then
37-
ARCH_TYPE="amd64"
38-
elif [ "$ARCH" = "aarch64" ]; then
39-
ARCH_TYPE="arm64"
40-
elif [ "$ARCH" = "armv7l" ]; then
41-
ARCH_TYPE="arm"
42-
else
43-
# Default to amd64 for other architectures
44-
ARCH_TYPE="amd64"
45-
fi
46-
47-
print_message "Detected architecture: $ARCH ($ARCH_TYPE)"
48-
49-
# Download Terraform
50-
print_message "Downloading Terraform $LATEST_VERSION..."
51-
TF_URL="https://releases.hashicorp.com/terraform/${LATEST_VERSION}/terraform_${LATEST_VERSION}_linux_${ARCH_TYPE}.zip"
52-
TEMP_DIR=$(mktemp -d)
53-
curl -s -o "${TEMP_DIR}/terraform.zip" "$TF_URL"
54-
55-
# Install Terraform
56-
print_message "Installing Terraform..."
57-
unzip -o "${TEMP_DIR}/terraform.zip" -d "${TEMP_DIR}"
58-
mv "${TEMP_DIR}/terraform" /usr/local/bin/
59-
chmod +x /usr/local/bin/terraform
60-
61-
# Clean up
62-
rm -rf "${TEMP_DIR}"
63-
64-
# Verify installation
65-
if terraform --version > /dev/null 2>&1; then
66-
print_message "Terraform $(terraform --version | head -n 1) installed successfully!"
67-
print_message "You can now use Terraform by running: terraform"
68-
else
69-
print_message "Terraform installation failed."
70-
exit 1
71-
fi
6+
mv terraform /usr/local/bin

0 commit comments

Comments
 (0)