diff --git a/registry/ausbru87/modules/aws-cli/README.md b/registry/ausbru87/modules/aws-cli/README.md index 0ded3d20..6d0cbf5a 100644 --- a/registry/ausbru87/modules/aws-cli/README.md +++ b/registry/ausbru87/modules/aws-cli/README.md @@ -62,3 +62,17 @@ module "aws-cli" { log_path = "/var/log/aws-cli.log" } ``` + +### Airgapped Environment + +Use a custom download URL for environments without internet access to AWS: + +```tf +module "aws-cli" { + count = data.coder_workspace.me.start_count + source = "registry.coder.com/ausbru87/aws-cli/coder" + version = "1.0.0" + agent_id = coder_agent.example.id + download_url = "https://internal-mirror.company.com/awscli-exe-linux-x86_64.zip" +} +``` diff --git a/registry/ausbru87/modules/aws-cli/aws-cli.tftest.hcl b/registry/ausbru87/modules/aws-cli/aws-cli.tftest.hcl index 210fec2b..bd2c66a9 100644 --- a/registry/ausbru87/modules/aws-cli/aws-cli.tftest.hcl +++ b/registry/ausbru87/modules/aws-cli/aws-cli.tftest.hcl @@ -23,3 +23,12 @@ run "with_custom_log_path" { log_path = "/var/log/aws-cli.log" } } + +run "with_custom_download_url" { + command = plan + + variables { + agent_id = "test-agent-id" + download_url = "https://internal-mirror.company.com/awscli-exe-linux-x86_64.zip" + } +} diff --git a/registry/ausbru87/modules/aws-cli/main.tf b/registry/ausbru87/modules/aws-cli/main.tf index 825b7b8b..b3bea3eb 100644 --- a/registry/ausbru87/modules/aws-cli/main.tf +++ b/registry/ausbru87/modules/aws-cli/main.tf @@ -20,6 +20,12 @@ variable "install_version" { default = "" } +variable "download_url" { + type = string + description = "Custom download URL for AWS CLI. Useful for airgapped environments. If not set, uses the official AWS download URL." + default = "" +} + variable "log_path" { type = string description = "The path to the AWS CLI installation log file." @@ -33,6 +39,7 @@ resource "coder_script" "aws-cli" { script = templatefile("${path.module}/run.sh", { LOG_PATH : var.log_path, VERSION : var.install_version, + DOWNLOAD_URL : var.download_url, }) run_on_start = true run_on_stop = false diff --git a/registry/ausbru87/modules/aws-cli/run.sh b/registry/ausbru87/modules/aws-cli/run.sh index b2b25ccd..864871e1 100755 --- a/registry/ausbru87/modules/aws-cli/run.sh +++ b/registry/ausbru87/modules/aws-cli/run.sh @@ -2,19 +2,20 @@ LOG_PATH=${LOG_PATH} VERSION=${VERSION} +DOWNLOAD_URL=${DOWNLOAD_URL} -BOLD='\033[0;1m' -RESET='\033[0m' +BOLD='\\033[0;1m' +RESET='\\033[0m' -printf "${BOLD}Installing AWS CLI...\n${RESET}" +printf "${BOLD}Installing AWS CLI...\\n${RESET}" # Check if AWS CLI is already installed if command -v aws > /dev/null 2>&1; then INSTALLED_VERSION=$(aws --version 2>&1 | cut -d' ' -f1 | cut -d'/' -f2) if [ -n "$VERSION" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then - printf "AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\n" + printf "AWS CLI $INSTALLED_VERSION is installed, but version $VERSION was requested.\\n" else - printf "AWS CLI is already installed ($INSTALLED_VERSION). Skipping installation.\n" + printf "AWS CLI is already installed ($INSTALLED_VERSION). Skipping installation.\\n" exit 0 fi fi @@ -27,16 +28,19 @@ case "$ARCH" in x86_64) ARCH="x86_64" ;; aarch64 | arm64) ARCH="aarch64" ;; *) - printf "Unsupported architecture: $ARCH\n" > "${LOG_PATH}" 2>&1 + printf "Unsupported architecture: $ARCH\\n" > "${LOG_PATH}" 2>&1 exit 1 ;; esac # Install AWS CLI if [ "$OS" = "linux" ]; then - DOWNLOAD_URL="https://awscli.amazonaws.com/awscli-exe-linux-${ARCH}.zip" + # Use custom download URL if provided, otherwise use default AWS URL + if [ -z "$DOWNLOAD_URL" ]; then + DOWNLOAD_URL="https://awscli.amazonaws.com/awscli-exe-linux-${ARCH}.zip" + fi - printf "Downloading AWS CLI from $DOWNLOAD_URL...\n" + printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n" curl -fsSL "$DOWNLOAD_URL" -o /tmp/awscliv2.zip >> "${LOG_PATH}" 2>&1 unzip -q /tmp/awscliv2.zip -d /tmp >> "${LOG_PATH}" 2>&1 @@ -45,9 +49,12 @@ if [ "$OS" = "linux" ]; then rm -rf /tmp/awscliv2.zip /tmp/aws elif [ "$OS" = "darwin" ]; then - DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg" + # Use custom download URL if provided, otherwise use default AWS URL + if [ -z "$DOWNLOAD_URL" ]; then + DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg" + fi - printf "Downloading AWS CLI from $DOWNLOAD_URL...\n" + printf "Downloading AWS CLI from $DOWNLOAD_URL...\\n" curl -fsSL "$DOWNLOAD_URL" -o /tmp/AWSCLIV2.pkg >> "${LOG_PATH}" 2>&1 sudo installer -pkg /tmp/AWSCLIV2.pkg -target / >> "${LOG_PATH}" 2>&1 @@ -55,15 +62,15 @@ elif [ "$OS" = "darwin" ]; then rm -f /tmp/AWSCLIV2.pkg else - printf "Unsupported OS: $OS\n" > "${LOG_PATH}" 2>&1 + printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1 exit 1 fi if command -v aws > /dev/null 2>&1; then - printf "🥳 AWS CLI installed successfully!\n" + printf "🥳 AWS CLI installed successfully!\\n" aws --version else - printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\n" + printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n" exit 1 fi @@ -75,7 +82,7 @@ if command -v aws_completer > /dev/null 2>&1; then if [ -f ~/.bashrc ]; then if ! grep -q "aws_completer.*aws" ~/.bashrc; then echo "complete -C '$AWS_COMPLETER_PATH' aws" >> ~/.bashrc - printf "✓ Configured AWS CLI autocomplete for bash\n" + printf "✓ Configured AWS CLI autocomplete for bash\\n" fi fi @@ -89,7 +96,7 @@ autoload bashcompinit && bashcompinit autoload -Uz compinit && compinit complete -C '$AWS_COMPLETER_PATH' aws EOF - printf "✓ Configured AWS CLI autocomplete for zsh\n" + printf "✓ Configured AWS CLI autocomplete for zsh\\n" fi fi @@ -101,7 +108,7 @@ EOF cat > "$FISH_COMPLETION" << 'EOF' complete --command aws --no-files --arguments '(begin; set --local --export COMP_SHELL fish; set --local --export COMP_LINE (commandline); aws_completer | sed '"'"'s/ $//'"'"'; end)' EOF - printf "✓ Configured AWS CLI autocomplete for fish\n" + printf "✓ Configured AWS CLI autocomplete for fish\\n" fi fi fi