-
Notifications
You must be signed in to change notification settings - Fork 78
Add AWS CLI module for installing AWS CLI v2 in workspaces #543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- 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
6ba3699 to
7a70127
Compare
There was a problem hiding this 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 |
| 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 |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| x86_64) ARCH="x86_64" ;; | ||
| aarch64 | arm64) ARCH="aarch64" ;; | ||
| *) | ||
| printf "Unsupported architecture: $ARCH\\n" > "${LOG_PATH}" 2>&1 |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| 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 |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| 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" |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| 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 |
| 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 |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| 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 |
| LOG_PATH=${LOG_PATH} | ||
| VERSION=${VERSION} | ||
| DOWNLOAD_URL=${DOWNLOAD_URL} |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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}\").
| rm -f /tmp/AWSCLIV2.pkg | ||
|
|
||
| else | ||
| printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1 |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| printf "Unsupported OS: $OS\\n" > "${LOG_PATH}" 2>&1 | |
| printf "Unsupported OS: $OS\\n" >> "${LOG_PATH}" 2>&1 |
- 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
305938b to
be4dc93
Compare
There was a problem hiding this 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" ;; |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| x86_64) ARCH="x86_64" ;; |
| # AWS CLI autocomplete | ||
| autoload bashcompinit && bashcompinit | ||
| autoload -Uz compinit && compinit | ||
| complete -C '$AWS_COMPLETER_PATH' aws |
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| 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 | ||
|
|
Copilot
AI
Nov 16, 2025
There was a problem hiding this comment.
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.
| 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. |
Add AWS CLI Module
New module for automatically installing and configuring AWS CLI v2 in Coder workspaces.
Features
Usage
Testing
aws-cli.tftest.hcl)