Skip to content

Conversation

@ausbru87
Copy link

@ausbru87 ausbru87 commented Nov 15, 2025

Add AWS CLI Module

New module for automatically installing and configuring AWS CLI v2 in Coder workspaces.

Features

  • AWS CLI v2 Installation: Linux and macOS support (x86_64 & ARM64)
  • Shell Autocomplete: Auto-configures command completion for bash, zsh, and fish
  • Version Pinning: Optional parameter to lock to specific AWS CLI versions
  • Airgapped Support: Custom download URL for environments without internet access
  • Smart Installation: Detects existing installations and skips reinstall

Usage

# STANDARD USAGE
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
}

# AIRGAPPED EXAMPLE
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"
}

Testing

  • Terraform tests included (aws-cli.tftest.hcl)
  • Validates required vars, version pinning, and custom download URL

- Installs AWS CLI v2 in Coder workspaces
- Supports x86_64 and ARM64 architectures with auto-detection
- Allows version pinning or installs latest version
- Optional GPG signature verification for security
- Idempotent installation (skips if already installed)
- Supports custom installation directories
- Includes comprehensive tests (Terraform + TypeScript)
- Full documentation with multiple usage examples
- Create ausbru87 namespace with avatar and README
- Move aws-cli module from registry/coder to registry/ausbru87
- Update all source paths to registry.coder.com/modules/ausbru87/aws-cli
- Follows contribution guidelines for community modules
- Format README.md tables with proper column alignment
- Add spaces around redirect operators in run.sh
- Remove trailing whitespace
- Update bun.lock with installed dependencies
Fix formatting issue on line 56 that was causing CI check to fail
@ausbru87 ausbru87 self-assigned this Nov 16, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new Terraform module to install AWS CLI v2 in Coder workspaces. The module supports Linux and macOS, provides version checking for idempotency, allows custom download URLs for airgapped environments, and automatically configures shell autocomplete for bash, zsh, and fish.

Key Changes:

  • Terraform module with configurable installation parameters
  • Shell script to download and install AWS CLI with architecture detection
  • Autocomplete configuration for multiple shell environments

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
main.tf Defines the Terraform module with variables for agent_id, install_version, download_url, and log_path
run.sh Installation script handling AWS CLI download, installation, and shell autocomplete configuration
README.md Documentation with usage examples for basic installation, version pinning, and airgapped environments
aws-cli.tftest.hcl Terraform tests for variable validation scenarios
README.md (namespace) Namespace profile for ausbru87 author
avatar.png Author avatar image
bun.lock Lock file configuration update

Comment on lines 15 to 20
if [ -n "$VERSION" ] && [ "$INSTALLED_VERSION" != "$VERSION" ]; then
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"
exit 0
fi
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a version mismatch is detected (line 15-16), the script prints a message but continues to installation without exiting. This means the installation will proceed even when the wrong version is installed, but the AWS CLI installer doesn't support installing specific versions. The script should either exit with an error, or proceed to reinstall with the latest version and document this behavior.

Copilot uses AI. Check for mistakes.
x86_64) ARCH="x86_64" ;;
aarch64 | arm64) ARCH="aarch64" ;;
*)
printf "Unsupported architecture: $ARCH\\n" > "${LOG_PATH}" 2>&1
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using > overwrites the log file instead of appending to it. This should use >> to append, consistent with other logging in the script. The same issue exists on line 65.

Copilot uses AI. Check for mistakes.
Comment on lines 44 to 47
curl -fsSL "$DOWNLOAD_URL" -o /tmp/awscliv2.zip >> "${LOG_PATH}" 2>&1

unzip -q /tmp/awscliv2.zip -d /tmp >> "${LOG_PATH}" 2>&1
sudo /tmp/aws/install >> "${LOG_PATH}" 2>&1
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing error checking after curl, unzip, and install commands. If any of these commands fail, the script continues to the next step, which could lead to confusing error messages. Add error checking (e.g., || exit 1) after each critical command or use set -e at the beginning of the script.

Copilot uses AI. Check for mistakes.
elif [ "$OS" = "darwin" ]; then
# Use custom download URL if provided, otherwise use default AWS URL
if [ -z "$DOWNLOAD_URL" ]; then
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

macOS installation doesn't use or validate the ARCH variable that was determined on lines 24-34. AWS CLI v2 for macOS has different packages for x86_64 and arm64 architectures, but this always downloads the universal package. While the universal package works, the script should be consistent with the architecture detection logic.

Suggested change
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
case "$ARCH" in
x86_64)
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2-x86_64.pkg"
;;
aarch64)
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2-arm64.pkg"
;;
*)
DOWNLOAD_URL="https://awscli.amazonaws.com/AWSCLIV2.pkg"
;;
esac

Copilot uses AI. Check for mistakes.
Comment on lines 72 to 113
else
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n"
exit 1
fi

# Configure autocomplete for common shells
if command -v aws_completer > /dev/null 2>&1; then
AWS_COMPLETER_PATH=$(which aws_completer)

# Bash autocomplete
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"
fi
fi

# Zsh autocomplete
if [ -f ~/.zshrc ] || [ -d ~/.oh-my-zsh ]; then
if ! grep -q "aws_completer.*aws" ~/.zshrc 2> /dev/null; then
cat >> ~/.zshrc << EOF

# AWS CLI autocomplete
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -C '$AWS_COMPLETER_PATH' aws
EOF
printf "✓ Configured AWS CLI autocomplete for zsh\\n"
fi
fi

# Fish autocomplete
if [ -d ~/.config/fish ] || command -v fish > /dev/null 2>&1; then
mkdir -p ~/.config/fish/completions
FISH_COMPLETION=~/.config/fish/completions/aws.fish
if [ ! -f "$FISH_COMPLETION" ]; then
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"
fi
fi
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The autocomplete configuration (lines 77-114) runs even if the installation verification at lines 69-75 might have failed. This code should be moved inside a conditional block that only runs after successful installation verification, or placed after the verification check succeeds.

Suggested change
else
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n"
exit 1
fi
# Configure autocomplete for common shells
if command -v aws_completer > /dev/null 2>&1; then
AWS_COMPLETER_PATH=$(which aws_completer)
# Bash autocomplete
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"
fi
fi
# Zsh autocomplete
if [ -f ~/.zshrc ] || [ -d ~/.oh-my-zsh ]; then
if ! grep -q "aws_completer.*aws" ~/.zshrc 2> /dev/null; then
cat >> ~/.zshrc << EOF
# AWS CLI autocomplete
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -C '$AWS_COMPLETER_PATH' aws
EOF
printf "✓ Configured AWS CLI autocomplete for zsh\\n"
fi
fi
# Fish autocomplete
if [ -d ~/.config/fish ] || command -v fish > /dev/null 2>&1; then
mkdir -p ~/.config/fish/completions
FISH_COMPLETION=~/.config/fish/completions/aws.fish
if [ ! -f "$FISH_COMPLETION" ]; then
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"
fi
fi
# Configure autocomplete for common shells
if command -v aws_completer > /dev/null 2>&1; then
AWS_COMPLETER_PATH=$(which aws_completer)
# Bash autocomplete
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"
fi
fi
# Zsh autocomplete
if [ -f ~/.zshrc ] || [ -d ~/.oh-my-zsh ]; then
if ! grep -q "aws_completer.*aws" ~/.zshrc 2> /dev/null; then
cat >> ~/.zshrc << EOF
# AWS CLI autocomplete
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -C '$AWS_COMPLETER_PATH' aws
EOF
printf "✓ Configured AWS CLI autocomplete for zsh\\n"
fi
fi
# Fish autocomplete
if [ -d ~/.config/fish ] || command -v fish > /dev/null 2>&1; then
mkdir -p ~/.config/fish/completions
FISH_COMPLETION=~/.config/fish/completions/aws.fish
if [ ! -f "$FISH_COMPLETION" ]; then
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"
fi
fi
fi
else
printf "❌ AWS CLI installation failed. Check logs at ${LOG_PATH}\\n"
exit 1

Copilot uses AI. Check for mistakes.
Comment on lines +3 to +5
LOG_PATH=${LOG_PATH}
VERSION=${VERSION}
DOWNLOAD_URL=${DOWNLOAD_URL}
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The template variables are assigned to shell variables with the same names. While this works, it's unclear whether these are template substitutions or shell variables. Consider using different casing or prefixes to make the distinction clearer (e.g., log_path=\"${LOG_PATH}\").

Copilot uses AI. Check for mistakes.
rm -f /tmp/AWSCLIV2.pkg

else
printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using > overwrites the log file instead of appending to it. This should use >> to append, consistent with other logging in the script.

Suggested change
printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1
printf "Unsupported OS: $OS\\n" >> "${LOG_PATH}" 2>&1

Copilot uses AI. Check for mistakes.
- Add set -e for strict error handling
- Exit on version mismatch with clear error message
- Use >> for log appending (was overwriting with >)
- Add error checking after curl, unzip, and install commands
- Add macOS architecture-specific download URLs
- Move autocomplete config after successful installation verification
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 3 comments.

ARCH=$(uname -m)

case "$ARCH" in
x86_64) ARCH="x86_64" ;;
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case statement for x86_64 is redundant as it assigns the same value. Consider removing this case branch or adding a comment explaining why it's needed for clarity.

Suggested change
x86_64) ARCH="x86_64" ;;

Copilot uses AI. Check for mistakes.
# AWS CLI autocomplete
autoload bashcompinit && bashcompinit
autoload -Uz compinit && compinit
complete -C '$AWS_COMPLETER_PATH' aws
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the zsh autocomplete heredoc, the variable $AWS_COMPLETER_PATH is not properly escaped. Since this is inside a heredoc with the delimiter ZSHEOF (not quoted), the variable will be expanded by the shell when writing to .zshrc. Use double backslash or a different heredoc approach to ensure the literal variable reference is written to the file.

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +29
Brief description of what this namespace provides. Include information about:

- What types of templates/modules you offer
- Your focus areas (e.g., specific cloud providers, technologies)
- Any special features or configurations

## Templates

List your available templates here:

- **template-name**: Brief description

## Modules

List your available modules here:

- **module-name**: Brief description

Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace README contains placeholder text that should be replaced with actual content describing the contributor's modules and focus areas. Update the description and module list to reflect the AWS CLI module being added.

Suggested change
Brief description of what this namespace provides. Include information about:
- What types of templates/modules you offer
- Your focus areas (e.g., specific cloud providers, technologies)
- Any special features or configurations
## Templates
List your available templates here:
- **template-name**: Brief description
## Modules
List your available modules here:
- **module-name**: Brief description
This namespace provides modules and templates focused on cloud automation, developer productivity, and infrastructure management. The main focus areas include AWS cloud services, CLI tooling, and solutions for streamlining development workflows. Special features include pre-configured modules for rapid deployment and integration with popular cloud providers.
## Templates
Currently, there are no templates available. Stay tuned for future additions!
## Modules
- **aws-cli**: Provides the AWS Command Line Interface (CLI) for managing AWS services directly from your workspace. Includes pre-installed AWS CLI v2, ready for use in automation scripts and cloud management tasks.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant