matlas-cli

command module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 1 Imported by: 0

README ΒΆ

πŸš€ matlas β€” one CLI for Atlas and MongoDB

🌟 The unified, Go-powered CLI that bridges MongoDB Atlas management and database operations

Matlas is your all-in-one command center for MongoDB Atlas and database management. Think of it as the friendly bridge between the Atlas SDK and the MongoDB Go Driver β€” spin up projects and clusters, configure network access, and seamlessly dive into database tasks like listing collections or inspecting indexes, all from a single, powerful tool! ⚑

πŸ’‘ Why we built it

  • πŸ”„ Context switching hurts: Cloud management lives in one world (Atlas APIs), while day‑to‑day database tasks live in another (drivers and shells). We wanted both, together.
  • 🧠 A single mental model: One set of flags, one config, one output style for both Atlas and database operations.
  • ⚑ Grease the path: From "create a cluster" to "inspect collections" in seconds β€” no hunting for another CLI.

🎯 Inspired by Terraform and kubectl: meet Discover

We love how Terraform plans changes before applying, and how kubectl lets you declare desired state. Matlas combines those vibes:

  • πŸ“Έ Discover: Snapshot your Atlas org/project (and optionally databases) into clean YAML:
    matlas discover --project-id <id> -o atlas.yaml --include-databases
    
  • πŸ” Plan/Diff: Treat that YAML as your desired state, compare it to reality:
    matlas infra plan -f atlas.yaml
    matlas infra diff -f atlas.yaml
    
  • πŸš€ Apply (dry-run first): Roll changes out, Terraform‑style:
    matlas infra -f atlas.yaml --dry-run
    matlas infra -f atlas.yaml --auto-approve
    

✨ Matlas doesn't try to be Terraform or kubectl. It borrows the best ideas so Atlas work feels safe, reviewable, and repeatable β€” and it keeps database tasks close at hand.

πŸ› οΈ What you can do

Feature Description
🌐 Atlas List/get/create/update/delete projects, clusters, users, network access, peering, and network containers
πŸ—„οΈ Databases List/create/delete databases, collections, and indexes β€” either via connection string or Atlas cluster reference
πŸ“‹ Infra Discover current state, plan/diff/apply/destroy via declarative YAML

πŸ“¦ Install

Prerequisites

  • 🐹 Go 1.22+ required

Download from GitHub Releases

Download the archive for your OS/architecture from the Releases page, extract, and place matlas in your PATH.

Build from source

# Quick build
make build

# Or manually
go build -o bin/matlas ./...

πŸ” Authenticate

Environment Variables

export ATLAS_PUB_KEY="your-public-key"
export ATLAS_API_KEY="your-api-key"
# Optional
export ATLAS_PROJECT_ID="your-project-id"
export ATLAS_ORG_ID="your-org-id"

YAML Configuration

Create ~/.matlas/config.yaml:

apiKey: your-api-key
publicKey: your-public-key
projectId: your-project-id  # optional
orgId: your-org-id          # optional
output: json                # optional
timeout: 30s                # optional

Command Line Flags

matlas --api-key <key> --pub-key <key> --project-id <id> --org-id <id> [command]

πŸš€ Quick start

Atlas Management

# List projects
matlas atlas projects list --org-id <id>

# Get a specific project  
matlas atlas projects get --project-id <id>

# List database users
matlas atlas users list --project-id <id>

# List network access rules
matlas atlas network list --project-id <id>

πŸ—„οΈ Database Operations

# List databases (via connection string)
matlas database list --connection-string "mongodb+srv://..."

# List databases (via Atlas cluster)
matlas database list --cluster <name> --project-id <id> --use-temp-user

# List collections in a database
matlas database collections list --connection-string ... --database mydb

# List indexes in a collection
matlas database collections indexes list \
  --connection-string ... \
  --database mydb \
  --collection mycoll

πŸ“‹ Declarative Infrastructure Workflows

# πŸ” Discover current state
matlas discover --project-id <id> -o atlas.yaml --include-databases --convert-to-apply

# πŸ“Š Plan and preview changes
matlas infra plan -f config.yaml
matlas infra diff -f config.yaml

# πŸš€ Apply changes (with safety checks)
matlas infra -f config.yaml --dry-run              # Preview first
matlas infra -f config.yaml --auto-approve         # Apply changes

# πŸ“Έ Show current state
matlas infra show --project-id <id>

# πŸ—‘οΈ Destroy resources
matlas infra destroy -f config.yaml                # From config
matlas infra destroy --discovery-only --project-id <id>  # Discovery only

βš™οΈ Configuration

Configuration Priority (highest to lowest)

  1. πŸ—οΈ Built-in defaults
  2. πŸ“„ YAML file: ~/.matlas/config.yaml or --config / ATLAS_CONFIG_FILE
  3. 🌍 Environment variables: ATLAS_* prefix (e.g., ATLAS_OUTPUT, ATLAS_TIMEOUT)
  4. 🚩 Command flags: --api-key, --project-id, etc.

πŸ”‘ Credentials Resolution

Matlas looks for credentials in this order:

  1. Command flags/YAML config
  2. Environment variables (ATLAS_API_KEY, ATLAS_PUB_KEY)
  3. macOS Keychain (fallback)

🐚 Shell Completion

Enable auto-completion for your shell:

# Choose your shell
matlas completion bash | sudo tee /etc/bash_completion.d/matlas
matlas completion zsh > ~/.zsh/completions/_matlas
matlas completion fish > ~/.config/fish/completions/matlas.fish
matlas completion powershell > matlas.ps1

πŸ“š Learn More

Topic Documentation
🌐 Atlas Commands docs/atlas.md
πŸ—„οΈ Database Commands docs/database.md
πŸ“‹ Infrastructure Workflows docs/infra.md
πŸ” Authentication & Config docs/auth.md

πŸ› οΈ Development

Commands

# Run tests
make test                    # See scripts/test/*.sh for details

# Code quality  
make lint                    # Lint code
make fmt                     # Format code

# Generate mocks
make generate-mocks         # Update test mocks

Feature tracking

Create a brief, per-feature summary in features/ using the provided template. This helps reviewers and users understand what was achieved and where it was wired end-to-end (CLI + YAML ApplyDocument).

cp features/TEMPLATE.md features/$(date +%F)-<short-slug>.md

⚠️ Current Limitations

  • πŸ” Atlas Search: Commands exist but return unsupported errors
  • πŸ”— VPC Endpoints: Hidden in current build

πŸ“„ License

MIT License - see LICENSE for details.


Built with ❀️ for the MongoDB community

⭐ Star this repo β€’ πŸ› Report issues β€’ πŸ’‘ Request features

Documentation ΒΆ

Overview ΒΆ

Package main is the entry point for matlas-cli.

Directories ΒΆ

Path Synopsis
cmd
internal
cli
Package cli provides command-line user experience helpers (errors, completion, recovery).
Package cli provides command-line user experience helpers (errors, completion, recovery).
clients/atlas
Package atlas provides a thin wrapper over the Atlas Go SDK with retries and helpers.
Package atlas provides a thin wrapper over the Atlas Go SDK with retries and helpers.
clients/mongodb
Package mongodb contains a light wrapper around the official MongoDB Go driver.
Package mongodb contains a light wrapper around the official MongoDB Go driver.
config
Package config defines the runtime configuration model and helpers.
Package config defines the runtime configuration model and helpers.
logging
Package logging provides structured logging utilities used across the CLI and services.
Package logging provides structured logging utilities used across the CLI and services.
output
Package output contains user-facing formatters for CLI output.
Package output contains user-facing formatters for CLI output.
types
Package types contains shared domain types used by apply, services and CLI layers.
Package types contains shared domain types used by apply, services and CLI layers.
ui
validation
Package validation implements schema and cross-resource dependency validation.
Package validation implements schema and cross-resource dependency validation.
Package main contains a standalone demo binary showcasing observability features.
Package main contains a standalone demo binary showcasing observability features.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL