For AI agents: a documentation index is available at https://www.mongodb.com/ko-kr/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Test Automations with Temporary Projects and Clusters

This tutorial describes how to create and delete an Atlas project and cluster to use as a temporary testing environment during automation script development. Use this workflow to validate scripts against a test cluster without leaving behind resources after you finish testing.

Before you begin, you must have the following:

1

Run the following Atlas CLI commands to create a testing environment that you can delete when you are finished testing:

  1. Run the atlas users describe command to return your Atlas user ID. Replace <userEmail> with the email address that is associated with your Atlas user account.

    atlas users describe --username <userEmail>
  2. Run the atlas projects create command to create a new project named myTempProject in your Atlas organization. Replace <orgId> with your organization ID and replace <userId> with the Atlas user ID that you retrieved in the previous step.

    atlas projects create myTempProject --orgId <orgId> --ownerId <userId>
  3. Retrieve the project ID for the project you created from the response. In the following example response, the project ID is 64933bde48add154124e343f.

    Project '64933bde48add154124e343f' created.

    Alternatively, you can use the atlas projects list command to find the project ID.

  4. Run the atlas setup command to create an Atlas cluster and database user in your new project. The following command creates an M10 cluster in the AWS US_EAST_1 region, with the temporary user myTempUser.

    Replace <password> with a password for the database user and replace <projectId> with the project ID for the project you created.

    Important

    An M10 cluster is not free. The cluster you create will incur hourly charges until you delete it. For more information about Atlas cluster billing, see the Cluster Configuration Costs documentation.

    atlas setup --clusterName myTempCluster --provider AWS --region US_EAST_1 --tier M10 --username myTempUser --password <password> --currentIp --skipSampleData --projectId <projectId> --force

    After Atlas creates the cluster, the Atlas CLI provides the cluster connection string and connects to your cluster through mongosh.

2

To run Atlas CLI commands from your automation scripts, you need a way for your automation to authenticate to the Atlas control plane programmatically. One way to do this is to create a service account for your project and add its credentials to your environment:

  1. Create a service account for the temporary project.

    Follow the instructions in Get Started with the Atlas Administration API to create a service account for your temporary project. Save the client ID and client secret values for the service account.

  2. Add service account credentials to your test environment.

    To enable your script to run Atlas CLI commands without requiring interactive authentication, you must add the service account credentials to your testing environment. You can do this by setting the MONGODB_ATLAS_CLIENT_ID and MONGODB_ATLAS_CLIENT_SECRET environment variables, running atlas auth login in the testing environment, or adding the credentials to a named profile and appending --profile <profileName> to each Atlas CLI command in your script.

3

Use the project and cluster you created in the previous steps to validate scripts that automate Atlas CLI actions, such as creating, updating, pausing, or deleting Atlas resources.

4

Run the following Atlas CLI commands to delete the testing environment. This ensures that all resources you created for testing are properly removed and stop incurring charges on your Atlas account:

  1. Run the atlas clusters delete command to delete the temporary cluster and its database users. Replace <projectId> with the project ID for the temporary project.

    atlas clusters delete myTempCluster --projectId <projectId> --force
  2. Run the atlas projects delete command to delete the temporary project. Replace <projectId> with the project ID for your temporary project.

    atlas projects delete <projectId> --force

    Note

    You can't delete the temporary project until the temporary cluster finishes shutting down. If you get an error stating CANNOT_CLOSE_GROUP_ACTIVE_ATLAS_CLUSTERS, wait five minutes, then run the atlas projects delete command again.

You can run the atlas projects list command to confirm successful deletion of the temporary project and cluster. If the temporary project is missing from the list, you successfully deleted both the project and the cluster.