Skip to content

Commit 7a70127

Browse files
committed
Add download_url parameter for airgapped environment support
1 parent 2039c39 commit 7a70127

File tree

4 files changed

+53
-16
lines changed

4 files changed

+53
-16
lines changed

registry/ausbru87/modules/aws-cli/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,17 @@ module "aws-cli" {
6262
log_path = "/var/log/aws-cli.log"
6363
}
6464
```
65+
66+
### Airgapped Environment
67+
68+
Use a custom download URL for environments without internet access to AWS:
69+
70+
```tf
71+
module "aws-cli" {
72+
count = data.coder_workspace.me.start_count
73+
source = "registry.coder.com/ausbru87/aws-cli/coder"
74+
version = "1.0.0"
75+
agent_id = coder_agent.example.id
76+
download_url = "https://internal-mirror.company.com/awscli-exe-linux-x86_64.zip"
77+
}
78+
```

registry/ausbru87/modules/aws-cli/aws-cli.tftest.hcl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,12 @@ run "with_custom_log_path" {
2323
log_path = "/var/log/aws-cli.log"
2424
}
2525
}
26+
27+
run "with_custom_download_url" {
28+
command = plan
29+
30+
variables {
31+
agent_id = "test-agent-id"
32+
download_url = "https://internal-mirror.company.com/awscli-exe-linux-x86_64.zip"
33+
}
34+
}

registry/ausbru87/modules/aws-cli/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ variable "install_version" {
2020
default = ""
2121
}
2222

23+
variable "download_url" {
24+
type = string
25+
description = "Custom download URL for AWS CLI. Useful for airgapped environments. If not set, uses the official AWS download URL."
26+
default = ""
27+
}
28+
2329
variable "log_path" {
2430
type = string
2531
description = "The path to the AWS CLI installation log file."
@@ -33,6 +39,7 @@ resource "coder_script" "aws-cli" {
3339
script = templatefile("${path.module}/run.sh", {
3440
LOG_PATH : var.log_path,
3541
VERSION : var.install_version,
42+
DOWNLOAD_URL : var.download_url,
3643
})
3744
run_on_start = true
3845
run_on_stop = false

registry/ausbru87/modules/aws-cli/run.sh

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
LOG_PATH=${LOG_PATH}
44
VERSION=${VERSION}
5+
DOWNLOAD_URL=${DOWNLOAD_URL}
56

6-
BOLD='\033[0;1m'
7-
RESET='\033[0m'
7+
BOLD='\\033[0;1m'
8+
RESET='\\033[0m'
89

9-
printf "${BOLD}Installing AWS CLI...\n${RESET}"
10+
printf "${BOLD}Installing AWS CLI...\\n${RESET}"
1011

1112
# Check if AWS CLI is already installed
1213
if command -v aws > /dev/null 2>&1; then
1314
INSTALLED_VERSION=$(aws --version 2>&1 | cut -d' ' -f1 | cut -d'/' -f2)
1415
if [ -n "$VERSION" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then
15-
printf "AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\n"
16+
printf "AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\\n"
1617
else
17-
printf "AWS CLI is already installed ($INSTALLED_VERSION). Skipping installation.\n"
18+
printf "AWS CLI is already installed ($INSTALLED_VERSION). Skipping installation.\\n"
1819
exit 0
1920
fi
2021
fi
@@ -27,16 +28,19 @@ case "$ARCH" in
2728
x86_64) ARCH="x86_64" ;;
2829
aarch64 | arm64) ARCH="aarch64" ;;
2930
*)
30-
printf "Unsupported architecture: $ARCH\n" > "${LOG_PATH}" 2>&1
31+
printf "Unsupported architecture: $ARCH\\n" > "${LOG_PATH}" 2>&1
3132
exit 1
3233
;;
3334
esac
3435

3536
# Install AWS CLI
3637
if [ "$OS" = "linux" ]; then
37-
DOWNLOAD_URL="https://awscli.amazonaws.com/awscli-exe-linux-${ARCH}.zip"
38+
# Use custom download URL if provided, otherwise use default AWS URL
39+
if [ -z "$DOWNLOAD_URL" ]; then
40+
DOWNLOAD_URL="https://awscli.amazonaws.com/awscli-exe-linux-${ARCH}.zip"
41+
fi
3842

39-
printf "Downloading AWS CLI from $DOWNLOAD_URL...\n"
43+
printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n"
4044
curl -fsSL "$DOWNLOAD_URL" -o /tmp/awscliv2.zip >> "${LOG_PATH}" 2>&1
4145

4246
unzip -q /tmp/awscliv2.zip -d /tmp >> "${LOG_PATH}" 2>&1
@@ -45,25 +49,28 @@ if [ "$OS" = "linux" ]; then
4549
rm -rf /tmp/awscliv2.zip /tmp/aws
4650

4751
elif [ "$OS" = "darwin" ]; then
48-
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
52+
# Use custom download URL if provided, otherwise use default AWS URL
53+
if [ -z "$DOWNLOAD_URL" ]; then
54+
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
55+
fi
4956

50-
printf "Downloading AWS CLI from $DOWNLOAD_URL...\n"
57+
printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n"
5158
curl -fsSL "$DOWNLOAD_URL" -o /tmp/AWSCLIV2.pkg >> "${LOG_PATH}" 2>&1
5259

5360
sudo installer -pkg /tmp/AWSCLIV2.pkg -target / >> "${LOG_PATH}" 2>&1
5461

5562
rm -f /tmp/AWSCLIV2.pkg
5663

5764
else
58-
printf "Unsupported OS: $OS\n" > "${LOG_PATH}" 2>&1
65+
printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1
5966
exit 1
6067
fi
6168

6269
if command -v aws > /dev/null 2>&1; then
63-
printf "🥳 AWS CLI installed successfully!\n"
70+
printf "🥳 AWS CLI installed successfully!\\n"
6471
aws --version
6572
else
66-
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\n"
73+
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n"
6774
exit 1
6875
fi
6976

@@ -75,7 +82,7 @@ if command -v aws_completer > /dev/null 2>&1; then
7582
if [ -f ~/.bashrc ]; then
7683
if ! grep -q "aws_completer.*aws" ~/.bashrc; then
7784
echo "complete -C '$AWS_COMPLETER_PATH' aws" >> ~/.bashrc
78-
printf "✓ Configured AWS CLI autocomplete for bash\n"
85+
printf "✓ Configured AWS CLI autocomplete for bash\\n"
7986
fi
8087
fi
8188

@@ -89,7 +96,7 @@ autoload bashcompinit && bashcompinit
8996
autoload -Uz compinit && compinit
9097
complete -C '$AWS_COMPLETER_PATH' aws
9198
EOF
92-
printf "✓ Configured AWS CLI autocomplete for zsh\n"
99+
printf "✓ Configured AWS CLI autocomplete for zsh\\n"
93100
fi
94101
fi
95102

@@ -101,7 +108,7 @@ EOF
101108
cat > "$FISH_COMPLETION" << 'EOF'
102109
complete --command aws --no-files --arguments '(begin; set --local --export COMP_SHELL fish; set --local --export COMP_LINE (commandline); aws_completer | sed '"'"'s/ $//'"'"'; end)'
103110
EOF
104-
printf "✓ Configured AWS CLI autocomplete for fish\n"
111+
printf "✓ Configured AWS CLI autocomplete for fish\\n"
105112
fi
106113
fi
107114
fi

0 commit comments

Comments
 (0)