Skip to content

Support Atmos Toolchain for 3rd Party Tools - #1466

Closed
Sam Tholiya (samtholiya) wants to merge 136 commits into
mainfrom
tools-experiment
Closed

Sam Tholiya (samtholiya) wants to merge 136 commits into
mainfrom
tools-experiment

Conversation

@samtholiya

@samtholiya Sam Tholiya (samtholiya) commented Sep 7, 2025 •

Copy link
Copy Markdown
Contributor

Describe the Feature

Atmos should automatically add the packages base-path as a priority search PATH when executing any commands.

Expected Behavior

Packages are automatically installed and available to atmos components, custom commands, and workflows.

When running atmos terraform plan and it depends on [email protected], if not installed it should automatically install it (if it's configured).

When running a custom command, that needs tflint, it should be able to automatically install it.

When running a workflow that needs tfsec, it should automatically install it.

Available Commands:
  add         Add or update a tool and version in .tool-versions
  aliases     List configured tool aliases
  clean       Remove all installed tools by deleting the .tools directory
  exec        Exec a specific version of a tool (replaces current process)
  get         Show all versions configured for a tool, sorted in semver order
  help        Help about any command
  info        Display tool configuration from registry
  install     Install a CLI binary from the registry
  list        List configured tools and their installation status
  path        Emit the complete PATH environment variable for configured tool versions
  remove      Remove a tool or a specific version from .tool-versions
  set         Set a specific version for a tool in .tool-versions
  uninstall   Uninstall a CLI binary from the registry
  which       Display the path to an executable

Flags:
  -h, --help                   help for toolchain
      --log-level string       Set log level (debug, info, warn, error)
      --tool-versions string   Path to tool-versions file (default ".tool-versions")
      --tools-config string    Path to tools configuration file (default "tools.yaml")
      --tools-dir string       Directory to store installed tools (default ".tools")

Use Case

  • Install versions of opentofu or terraform
  • Install helmfile
  • Install terraform-docs, tflint, etc.
  • Support multiple concurrent versions
  • Install any other binaries needed by workflows, custom commands, etc
  • Atmos should act as a wrapper for atmos, to install and exec any version of atmos using the use keyword

Describe Ideal Solution

Atmos Commands

# Install all packages
atmos toolchain install
# Update packages 
atmos toolchain update

Atmos Configuration

# atmos.yaml

# Automatically install (if not installed) and use this version of atmos, and exec (replacing PID).
# See `exec` example in `toolchain-experiment`
# THis replaces the current process, it's NOT A SUBSHELL.
# This ensures everyone uses the right version based on the configuration.
use 1.183.1


# Define packages required for a specific type of component
# In this example, we're refering to the "opentofu" alias and 
# specifying the version of 1.10.3
components:
  terraform:
    command: [email protected]
  helmfile:
    command: [email protected]

The use keyword will install atmos at version 1.183.1, then call syscall.Exec to replace the current process with the atmos at the correct version, if the current version is not already 1.183.1.

Aliases

Aliases map a short name like opentofu to a registry configuration of opentofu/opentofu or terraform to something like hashicorp/terraform

# toolchain subcommand configuration
toolchain:

  
  # Tool name aliases for .tool-versions compatibility
  # Maps common tool names to their registry owner/repo paths
  aliases:
    terraform: hashicorp/terraform
    opentofu: opentofu/opentofu
    helm: helm/helm
    kubectl: kubernetes-sigs/kubectl
    kustomize: kubernetes-sigs/kustomize
    kind: kubernetes-sigs/kind
    krew: kubernetes-sigs/krew
    github-comment: suzuki-shunsuke/github-comment
    tflint: terraform-linters/tflint
    tfsec: aquasecurity/tfsec
    checkov: bridgecrewio/checkov
    terragrunt: gruntwork-io/terragrunt
    packer: hashicorp/packer
    vault: hashicorp/vault
    consul: hashicorp/consul
    nomad: hashicorp/nomad
    waypoint: hashicorp/waypoint
    boundary: hashicorp/boundary
    helmfile: helmfile/helmfile
    atmos: cloudposse/atmos

Tool Versions

We should use the simple .tool-versions convention popularized by asdf

tool1 1.2.3 4.5.7
tool2 2.3.4
tool3 5.6.7

The first semver is the default version, when nothing is specified

This file is consulted when calling install/uninstall/add/remove.

We should use aliases in this file to refer to toolchain tools. This is so we can change the mapping in the future.

Aqua Registry Configuration

We're going to add partial Aqua support for registries and expand the implementation over time. To start, we want to support the essential packages we depend on.

Local Configuration

We also want a local toolchain configuration, when not depending on the Aqua registry.

# toolchain subcommand configuration
toolchain:

  # this is relative to the repo root
  install-dir: .tools/bin

  # Local tools configuration
  # This file is consulted first before the Aqua registry
  # Allows local overrides and custom tool definitions
  

  tools:
    # Atmos configuration supporting both raw and gzipped binaries
    cloudposse/atmos:
      type: github_release
      repo_owner: cloudposse
      repo_name: atmos
      binary_name: atmos
      version_constraints:
        - constraint: ">= 1.0.0"
          asset: atmos_{{trimV .Version}}_{{.OS}}_{{.Arch}}
          format: raw
        - constraint: ">= 1.0.0"
          asset: atmos_{{trimV .Version}}_{{.OS}}_{{.Arch}}.gz
          format: gzip
  
    # Override a registry tool with local settings
    hashicorp/terraform:
      type: http
      url: https://releases.hashicorp.com/terraform/{{trimV .Version}}/terraform_{{trimV .Version}}_{{.OS}}_{{.Arch}}.zip
      format: zip
      binary_name: terraform
  
    # TFLint configuration
    terraform-linters/tflint:
      type: github_release
      repo_owner: terraform-linters
      repo_name: tflint
      binary_name: tflint
  
    # Custom tool not in registry
    my-custom-tool:
      type: github_release
      repo_owner: myorg
      repo_name: my-custom-tool
      asset: my-custom-tool_{{trimV .Version}}_{{.OS}}_{{.Arch}}.tar.gz
      format: tar.gz
      binary_name: my-custom-tool
  
    # Override OpenTofu to use a specific version constraint
    opentofu/opentofu:
      type: github_release
      repo_owner: opentofu
      repo_name: opentofu
      binary_name: tofu
      version_constraints:
        - constraint: ">= 1.10.0"
          asset: tofu_{{trimV .Version}}_{{.OS}}_{{.Arch}}.tar.gz
          format: tar.gz
        - constraint: "< 1.10.0"
          asset: tofu_{{trimV .Version}}_{{.OS}}_{{.Arch}}.zip
          format: zip
  
    helm/helm:
      type: http
      repo_owner: helm
      repo_name: helm
      url: https://get.helm.sh/helm-v{{.Version}}-{{.OS}}-{{.Arch}}.tar.gz
      format: tar.gz
      binary_name: helm

Stack Configuration

# stacks/_defaults.yaml
components:
  terraform:
    vpc:
      command: hashicorp/[email protected]

When the command is evaluated, it's first checked against the toolchain, and if it's not installed, it will be automatically installed.

The PATH for exec will be updated to use the directory containing terraform for version 1.11.4

Workflows

workflows:
  tflint:
    description: "Run tflint on a component"
    needs:
    - [email protected]
    - [email protected]
    steps:
      - name: tflint
        type: shell
        command: |
          cd terraform/components
          tflint --recursive

Custom Commands

# Custom CLI commands
commands:
  - name: tfsec
    description: Run tfsec against a specified Terraform component
    arguments:
      - name: component
        description: Name of the component to scan
    needs:
    - [email protected]
    steps:
      # Navigate to the Terraform component directory
      - cd components/terraform/{{ .Arguments.component }}
      # Run tfsec scan
      - tfsec .

Alternatives Considered

Using aqua directly. However, the aims of the Aqua Project are different than our aims and Aqua does not expose an SDK or stable interfaces for other CLIs to use Aqua.

https://github.com/suzuki-shunsuke

Summary by CodeRabbit

  • New Features

    • Added toolchain CLI for managing and installing CLI tools from the Aqua registry.
    • Tool installation, uninstallation, and version management with support for multiple concurrent versions.
    • Interactive version selection for tools with GitHub releases integration.
    • Local tool aliases and configuration support via tools.yaml.
    • Tool information display and PATH environment variable management.
    • GitHub token authentication for registry access.
  • Documentation

    • Added comprehensive toolchain documentation and CLI help pages.

@github-actions github-actions Bot added the size/xl Extra large size PR label Sep 7, 2025
@mergify

mergify Bot commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

Warning

This PR exceeds the recommended limit of 1,000 lines.

Large PRs are difficult to review and may be rejected due to their size.

Please verify that this PR does not address multiple issues.
Consider refactoring it into smaller, more focused PRs to facilitate a smoother review process.

@mergify

mergify Bot commented Sep 7, 2025

Copy link
Copy Markdown
Contributor

Important

Cloud Posse Engineering Team Review Required

This pull request modifies files that require Cloud Posse's review. Please be patient, and a core maintainer will review your changes.

To expedite this process, reach out to us on Slack in the #pr-reviews channel.

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

golangci-lint found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@coderabbitai

coderabbitai Bot commented Sep 7, 2025 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR introduces a complete toolchain subsystem for Atmos that installs and manages CLI binaries from the Aqua registry. It adds schema definitions, CLI command structure, registry clients, installer logic with asset downloading and extraction, local configuration management, and extensive test coverage across all components.

Changes

Cohort / File(s) Summary
Schema & Config Setup
pkg/schema/schema.go, toolchain/setup.go, toolchain/errors.go
Adds Toolchain type to AtmosConfiguration schema with fields (InstallPath, FilePath, ToolsDir, ToolsConfigFile); introduces package-level config management with SetAtmosConfig and path getters; defines standardized error variables for toolchain operations.
CLI Integration & Root
cmd/root.go, cmd/toolchain/toolchain.go
Wires toolchain command into root CLI via SetAtmosConfig propagation after InitCliConfig; defines ToolchainCommandProvider for command registry integration with persistent flags (github-token, tool-versions, tools-dir, tools-config).
Core Installer & Registry
toolchain/installer.go, toolchain/aqua_registry.go, toolchain/local_config.go, toolchain/github.go, toolchain/http_client.go
Implements pluggable ToolResolver abstraction, Installer with Install/Uninstall/FindBinaryPath/CreateLatestFile methods; AquaRegistry for fetching/caching registry metadata; LocalConfigManager for tools.yaml parsing and version constraint resolution; GitHubAPI client for releases; HTTPClient with GitHub token authentication.
Tool Version Management
toolchain/tool_versions.go, toolchain/types.go
Adds ToolVersions data model for asdf-compatible .tool-versions file; ParseToolVersionArg for CLI parsing; Tool, File, Override, AquaPackage types for registry schemas; helpers for YAML marshaling and template evaluation.
Command Implementations
toolchain/add.go, toolchain/remove.go, toolchain/install.go, toolchain/uninstall.go, toolchain/list.go, toolchain/get.go, toolchain/set.go, toolchain/exec.go, toolchain/which.go, toolchain/path.go, toolchain/info.go, toolchain/aliases.go, toolchain/clean.go
Implements 13 toolchain commands: add/remove versions, install/uninstall with progress UI, list installed tools in table format, get/set versions interactively, exec/which for tool invocation, path emission, info display, alias listing, clean cache/tools.
Utility Modules
toolchain/progress.go
Provides TTY-aware terminal status line and progress bar utilities for real-time CLI feedback.
Core Tests
toolchain/*_test.go (40+ test files)
Comprehensive test coverage for all commands, helpers, and utilities including mock resolvers, temp directories, and table-driven scenarios for edge cases and error paths.
Command Snapshots & Markdown Docs
tests/snapshots/TestCLICommands_*, cmd/markdown/atmos_toolchain_*.md
Snapshot golden files for CLI help output; markdown documentation for each toolchain command with usage examples and flags.
Website Documentation & Assets
website/docs/cli/commands/toolchain/*.mdx, website/src/components/Screengrabs/atmos-toolchain-*.html
Comprehensive MDX documentation pages and static HTML help screengrabs for all 14 toolchain subcommands; main usage guide describing architecture and features.
Toolchain Build & Config
toolchain/Makefile, toolchain/README.md, .gitignore
Adds minimal Go build Makefile; extensive README documenting architecture, features, registry integration, aliases, authentication, troubleshooting; gitignore entries for node_modules and toolchain artifacts.
Dependencies
go.mod
Adds direct requires for github.com/Masterminds/semver/v3 v3.4.0 and github.com/gabriel-vasile/mimetype v1.4.10, moving them from indirect to direct.
Test Helpers & Misc
toolchain/main_test.go, tests/preconditions_test.go, internal/exec/atlantis_utils_test.go
Adds Viper/environment binding for GitHub token in test setup; updates preconditions test to use t.Setenv; adds atlantis utility tests for project name building.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CLI as atmos toolchain
    participant Installer
    participant Resolver
    participant Registry as Aqua Registry
    participant GitHub
    participant FS as Filesystem

    User->>CLI: atmos toolchain install [email protected]
    CLI->>Installer: NewInstaller()
    Installer->>Resolver: Resolve("terraform")
    Resolver-->>Installer: ("hashicorp", "terraform")
    Installer->>Registry: GetToolWithVersion("hashicorp", "terraform", "1.11.4")
    Registry->>GitHub: FetchReleases("hashicorp", "terraform")
    GitHub-->>Registry: ["1.11.4", "1.9.8", ...]
    Registry-->>Installer: Tool{Asset:"...", Format:"zip", ...}
    Installer->>Installer: BuildAssetURL(tool, "1.11.4")
    Installer->>FS: Download asset
    Installer->>FS: Extract archive
    Installer->>FS: Install to .tools/bin/hashicorp/terraform/1.11.4/
    Installer->>FS: CreateLatestFile(latest=1.11.4)
    Installer->>FS: Update .tool-versions
    CLI-->>User: ✓ terraform 1.11.4 installed
Loading
sequenceDiagram
    participant RootCmd as cmd/root.go
    participant InitCliConfig as InitCliConfig()
    participant ToolchainCmd as toolchain package
    participant SubCmds as Subcommands

    RootCmd->>InitCliConfig: Execute
    InitCliConfig-->>RootCmd: atmosConfig
    RootCmd->>ToolchainCmd: SetAtmosConfig(&atmosConfig)
    ToolchainCmd->>ToolchainCmd: Store config globally
    activate ToolchainCmd
    SubCmds->>ToolchainCmd: GetToolsDirPath(), GetToolVersionsFilePath()
    ToolchainCmd-->>SubCmds: Configured paths
    deactivate ToolchainCmd
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Rationale: This PR introduces a substantial new subsystem with significant logic density across multiple domains (HTTP clients, registry parsing, file extraction, version resolution, CLI command wiring). While the changes are well-structured and homogeneous within each module, the breadth—spanning installer logic, registry clients, config management, 13+ command implementations, and 40+ test files—demands careful review. The logic for URL templating, version constraint resolution, asset extraction, and error handling requires attention. However, the extensive test coverage and clear architectural separation mitigate complexity somewhat.

Possibly related PRs

Suggested reviewers

  • aknysh

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Support Atmos Toolchain for 3rd Party Tools" directly and accurately reflects the core objective of this changeset. The raw summary and PR objectives confirm that the primary change is the introduction of a new toolchain subsystem with CLI commands and registry support for managing third-party tools—exactly what the title describes. The title is concise, clear, and specific enough that a teammate reviewing commit history would immediately understand the feature being added without ambiguity.

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3c2d371 and d2676a6.

📒 Files selected for processing (28)
  • cmd/root.go (3 hunks)
  • cmd/toolchain/toolchain.go (1 hunks)
  • go.mod (2 hunks)
  • tests/preconditions_test.go (1 hunks)
  • toolchain/aqua_registry.go (1 hunks)
  • toolchain/clean.go (1 hunks)
  • toolchain/errors.go (1 hunks)
  • toolchain/exec.go (1 hunks)
  • toolchain/exec_test.go (1 hunks)
  • toolchain/get.go (1 hunks)
  • toolchain/get_test.go (1 hunks)
  • toolchain/github.go (1 hunks)
  • toolchain/github_token_test.go (1 hunks)
  • toolchain/http_client_test.go (1 hunks)
  • toolchain/install.go (1 hunks)
  • toolchain/install_test.go (1 hunks)
  • toolchain/installer.go (1 hunks)
  • toolchain/installer_test.go (1 hunks)
  • toolchain/local_config.go (1 hunks)
  • toolchain/main_test.go (1 hunks)
  • toolchain/path.go (1 hunks)
  • toolchain/path_test.go (1 hunks)
  • toolchain/remove.go (1 hunks)
  • toolchain/set.go (1 hunks)
  • toolchain/tool_versions.go (1 hunks)
  • toolchain/uninstall.go (1 hunks)
  • toolchain/uninstall_test.go (1 hunks)
  • toolchain/which.go (1 hunks)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Sep 7, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.04044% with 1239 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.81%. Comparing base (8012b2a) to head (d2676a6).

Files with missing lines Patch % Lines
toolchain/installer.go 54.47% 277 Missing and 74 partials ⚠️
toolchain/uninstall.go 47.24% 141 Missing and 22 partials ⚠️
toolchain/aqua_registry.go 53.64% 145 Missing and 14 partials ⚠️
toolchain/set.go 58.47% 140 Missing and 2 partials ⚠️
toolchain/install.go 54.14% 80 Missing and 14 partials ⚠️
toolchain/list.go 77.34% 59 Missing and 16 partials ⚠️
toolchain/tool_versions.go 67.06% 46 Missing and 9 partials ⚠️
toolchain/info.go 45.71% 36 Missing and 2 partials ⚠️
toolchain/get.go 74.01% 27 Missing and 6 partials ⚠️
toolchain/path.go 62.50% 23 Missing and 10 partials ⚠️
... and 8 more
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1466      +/-   ##
==========================================
- Coverage   66.04%   65.81%   -0.24%     
==========================================
  Files         350      373      +23     
  Lines       39912    43176    +3264     
==========================================
+ Hits        26361    28416    +2055     
- Misses      11540    12563    +1023     
- Partials     2011     2197     +186     
Flag Coverage Δ
unittests 65.81% <62.04%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/root.go 49.16% <100.00%> (+0.28%) ⬆️
pkg/schema/schema.go 93.13% <ø> (ø)
toolchain/add.go 100.00% <100.00%> (ø)
toolchain/aliases.go 100.00% <100.00%> (ø)
toolchain/http_client.go 100.00% <100.00%> (ø)
toolchain/setup.go 100.00% <100.00%> (ø)
toolchain/which.go 100.00% <100.00%> (ø)
toolchain/clean.go 93.02% <93.02%> (ø)
toolchain/exec.go 82.35% <82.35%> (ø)
toolchain/progress.go 56.25% <56.25%> (ø)
... and 15 more

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 146

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
website/src/components/Screengrabs/demo-stacks/define-your-stacks.html (1)

1-53: Sanitize Screengrabs for leaked local paths and script errors
All files under website/src/components/Screengrabs/demo-stacks/* (e.g. define-your-stacks.html, start-your-project.html, write-your-components.*) contain hardcoded /home/.../cloudposse/atmos or /Users/... paths and “bat: command not found” output. Remove or replace these placeholders with neutral paths or properly rendered content.

go.mod (1)

3-3: Update devcontainer Dockerfile Go image

  • .devcontainer/Dockerfile line 1: change FROM golang:1.22 AS confetty to FROM golang:1.24.6 AS confetty.
    (GitHub workflows already use actions/setup-go with go-version-file: go.mod, so they’ll pick up Go 1.24.6 automatically.)
cmd/toolchain.go (1)

1-75: Replace hardcoded “.tool-versions” in install.go with GetToolVersionsFilePath()
toolchain/install.go still calls

  • LoadToolVersions(".tool-versions") (≈ line 79)
  • AddToolToVersionsAsDefault(".tool-versions", …) (≈ line 123)
  • AddToolToVersions(".tool-versions", …) (≈ line 127)
  • AddToolToVersions(".tool-versions", …) in progress loop (≈ line 171)
    All should use GetToolVersionsFilePath() for consistency and configurability.

Comment thread cmd/toolchain_exec.go Resolved
Comment thread cmd/toolchain_list.go Outdated
Comment on lines +3 to +6
import (
"github.com/cloudposse/atmos/toolchain"
"github.com/spf13/cobra"
)

Copy link