Convert CLI automation config to C/OM API format
masterconvert package provides functionality to transform automation configuration files from the format used by the CLI into the specific format required by the C/OM API.repository·master·Indexed 41 days ago
https://github.com/mongodb/mongodb-atlas-cliA modern command-line interface for managing MongoDB Atlas deployments directly from a terminal. The CLI, invoked via the `atlas` binary, allows users to authenticate, manage IP access lists (create, delete, describe, and list), retrieve cluster access logs, and handle configuration through profiles and environment variables.
convert package provides functionality to transform automation configuration files from the format used by the CLI into the specific format required by the C/OM API.You can install the Atlas CLI using Homebrew, by downloading pre-built binaries, or by building from source.
On macOS or Linux systems with Homebrew installed, run:
brew install mongodb-atlas-cliDownload the appropriate version for your platform from the Atlas CLI releases. You can run the binary from any location without a global installation, which is useful for shared hosts where you lack privileged access. For ease of use, place the binary in a directory included in your PATH, such as /usr/local/bin.
To build the CLI from the source code, follow these steps:
git clone https://github.com/mongodb/mongodb-atlas-cli.git
cd mongodb-atlas-climake build to generate the atlas binary in the ./bin directory.make install to install the atlas binary into $GOPATH/bin. Note that make build is not required before running make install.brew install mongodb-atlas-cliTo begin using the CLI to manage your MongoDB Atlas resources, you must first authenticate. Run the following command and follow the interactive prompts in your terminal:
atlas auth loginatlas auth loginBefore authenticating with a Service Account, ensure you have the following:
You can authenticate an Atlas CLI profile using a Service Account (also known as an OAuth Application) to enable programmatic access via a Client ID and Client Secret. This is ideal for automation and CI/CD workflows.
To set up a profile interactively:
atlas auth login --profile <profile_name>.ServiceAccount from the authentication type prompt.Client ID and Client Secret when prompted.plaintext or json).For CI/CD or scripting where interactive prompts are not possible, set the following environment variables before running Atlas CLI commands:
MONGODB_ATLAS_CLIENT_IDMONGODB_ATLAS_CLIENT_SECRETOnce authenticated, use the --profile flag with any Atlas CLI command to execute it within the scope of that profile's permissions.
# Interactive setup
atlas auth login --profile myProfile
# Using the profile
atlas cluster list --profile myProfile
# Programmatic setup (Environment Variables)
export MONGODB_ATLAS_CLIENT_ID=<your-client-id>
export MONGODB_ATLAS_CLIENT_SECRET=<your-client-secret>
atlas cluster listIf you installed via Homebrew, shell completions are configured automatically. For other installation methods, you can generate completion scripts for your preferred shell (bash, zsh, fish, or powershell). To see the specific instructions and flags for your shell, run:
atlas completion <bash|zsh|fish|powershell> --helpatlas completion <bash|zsh|fish|powershell> --helpTo see a list of all available commands and their descriptions, use the help command:
atlas helpatlas helpThere is no direct command to rename an existing Atlas cluster. To achieve a rename, you must deploy a new cluster with the desired name using the configuration of the old cluster, and then delete the old one.
Warning: This process does not migrate data from the old cluster to the new cluster. You must handle data migration separately.
# 1. Export the configuration of the existing cluster to a JSON file
atlas cluster describe oldName --output json > oldcluster.json
# 2. Create a new cluster using that configuration file with a new name
atlas cluster create newName --file oldcluster.json
# 3. Delete the original cluster
atlas cluster delete oldName --forceThe Atlas CLI manages configuration through profiles and environment variables. The CLI automatically performs a migration of your configuration to the latest version upon startup using the DefaultMigrator.
Configuration is loaded via config.LoadAtlasCLIConfig(), which merges settings from the configuration file and any applicable environment variables. The active configuration is then injected into the command execution context.
The atlas backup restore start command enforces different required flags depending on the restore method selected:
automated: Requires --clusterName, --snapshotId, --targetClusterName, and --targetProjectId.pointInTime: Requires --clusterName, --targetClusterName, and --targetProjectId.download: Requires --snapshotId.Note: --clusterName is always required.
When creating a new MongoDB Atlas cluster via the CLI, you can specify several configuration options to define the cluster's topology, hardware, and metadata.
Key configuration parameters include:
Note: For non-tenant clusters, the default node count is 3 and the default priority is 7. For tenant clusters, the Provider option is used as the BackingProviderName.
The MongoDB Atlas CLI is invoked via the atlas binary. It uses a command-based structure (built with Cobra) to interact with MongoDB Atlas services. When running commands, the CLI automatically handles configuration loading, profile management, and telemetry tracking.
To learn more about connecting to Atlas via the CLI, visit the official documentation: https://www.mongodb.com/docs/atlas/cli/stable/connect-atlas-cli/
# Example of running the CLI (actual commands depend on the installed version)
atlas --help