Skip to content

Atlas CLI GitHub Action

Actions
Use AtlasCLI in your GitHub workflow
v0.2.1
Latest
Star (16)

atlas-github-action

This is the official GitHub Action for the MongoDB Atlas CLI, published on the GitHub Marketplace

Getting started

Run Atlas CLI Commands with GitHub Actions

This guide provides getting started instructions for the official Atlas CLI GitHub Action.

This Action allows you to run any Atlas CLI command in your own GitHub workflows. By default, this Action uses the latest version of the Atlas CLI. The version can be configured with the 'version' input parameter, but only the latest version is officially supported.

Complete the prerequisites

Before you begin, complete the following prerequisites:

  1. Configure programmatic authenticaiton for your organization or project.

  2. Add the authentication credentials to the repository secrets.

  3. In your workflow, set the appropriate environment variables using the secrets you configured in step 2.

    • For Service Account authentication, set MONGODB_ATLAS_CLIENT_ID and MONGODB_ATLAS_CLIENT_SECRET.
    • For API key authentication, set MONGODB_ATLAS_PUBLIC_API_KEY and MONGODB_ATLAS_PRIVATE_API_KEY.

    See Atlas CLI Environment Variables for all supported environment variables.

Configuration

To run CLI commands with this Action you can either use Atlas CLI commands from a bash shell (see Basic workflow below) or use configuration parameters to run predefined workflows. See action.yml for available inputs/outputs.

Example workflows

See test.yml for more examples.

Basic

This workflow installs the CLI and prints the CLI version.

on: [push]

name: Atlas CLI Action Sample

jobs:
  use-atlas-cli:
    runs-on: ubuntu-latest
    
    steps:
      - name: Setup AtlasCLI
        uses: mongodb/[email protected]
      - name: Use AtlasCLI
        shell: bash
        run: atlas --version # Print Atlas CLI Version

Setup and Teardown

This workflow sets up a project and creates a free cluster using an API Key to authenticate. It retrieves the connection string which can be used to connect to the new cluster. Afterwards, it deletes the project and cluster.

on: [push]

name: Atlas CLI Action Sample

env:
  MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.PUBLIC_API_KEY }}
  MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.PRIVATE_API_KEY }}
  MONGODB_ATLAS_ORG_ID: ${{ secrets.ORG_ID }} # default organisation ID
  MONGODB_ATLAS_PROJECT_ID: ${{ secrets.PROJECT_ID }} # default project ID

jobs:
  setup:
    runs-on: ubuntu-latest

    steps:
      - name: Setup AtlasCLI and create a project
        id: create-project
        uses: mongodb/[email protected]
        with:
          create-project-name: test-setup-project
      - name: Run setup
        id: setup
        uses: mongodb/[email protected]
        with:
          run-setup: true
          project-id: ${{ steps.create-project.outputs.create-project-id }}
          cluster-name: test-cluster
          username: test-user
          password: test-password
      - name: Retrieve Connection String
        shell: bash
        run: |
          echo "${{ steps.setup.outputs.connection-string }}"
      - name: Teardown
        uses: mongodb/[email protected]
        with:
          delete-project-id: ${{ steps.create-project.outputs.create-project-id }}
          delete-cluster-name: test-cluster

List Clusters with Service Account Credentials

This workflow uses Service Account credentials to authenticate and lists all clusters in a specified project. The output is saved to a file for later use.

on: [push]

name: Atlas CLI List Clusters Example

env:
  MONGODB_ATLAS_CLIENT_ID: ${{ secrets.CLIENT_ID }}
  MONGODB_ATLAS_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
  MONGODB_ATLAS_ORG_ID: ${{ secrets.ORG_ID }} # default organisation ID
  MONGODB_ATLAS_PROJECT_ID: ${{ secrets.PROJECT_ID }} # default project ID

jobs:
  list-clusters:
    runs-on: ubuntu-latest

    steps:
      - name: Setup AtlasCLI
        uses: mongodb/[email protected]
      - name: List Clusters
        shell: bash
        run: |
          atlas cluster list --projectId "$MONGODB_ATLAS_PROJECT_ID" --output json > clusters.json
      - name: Upload Cluster List
        uses: actions/upload-artifact@v4
        with:
          name: clusters-list
          path: clusters.json

Limitations

This Action supports only Linux runners (e.g. ubuntu-latest).

License

The Atlas CLI GitHub Action is released under the Apache 2.0 license. See LICENSE.

Atlas CLI GitHub Action is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Use AtlasCLI in your GitHub workflow
v0.2.1
Latest

Atlas CLI GitHub Action is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.