> For the complete MongoDB documentation index, see www.mongodb.com/docs/llms.txt

# 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.

## Prerequisites

Before you begin, you must have the following:

- An Atlas user account.

- An Atlas organization and its organization ID.  You can retrieve the organization ID using the [atlas organizations list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-organizations-list.md#std-label-atlas-organizations-list) Atlas CLI command.

- The Atlas CLI installed and configured. To learn more, see [Install or Update the Atlas CLI](https://www.mongodb.com/docs/atlas/cli/current/install-atlas-cli.md#std-label-install-atlas-cli) and [Connect from the Atlas CLI.](https://www.mongodb.com/docs/atlas/cli/current/connect-atlas-cli.md#std-label-connect-atlas-cli)

## Procedure

1. Create a temporary project, cluster, and database user.

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

   Run the [atlas users describe](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-users-describe.md#std-label-atlas-users-describe) command to return your Atlas user ID. Replace `<userEmail>` with the email address that is associated with your Atlas user account.

   ```text
   atlas users describe --username <userEmail>
   ```

   Run the [atlas projects create](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-projects-create.md#std-label-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.

   ```text
   atlas projects create myTempProject --orgId <orgId> --ownerId <userId>
   ```

   Retrieve the project ID for the project you created from the response. In the following example response, the project ID is `64933bde48add154124e343f`.

   ```text
   Project '64933bde48add154124e343f' created.
   ```

   Alternatively, you can use the [atlas projects list](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-projects-list.md#std-label-atlas-projects-list) command to find the project ID.

   Run the [atlas setup](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-setup.md#std-label-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 (Amazon Web Services) `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 [Atlas Cluster Configuration Costs](https://www.mongodb.com/docs/atlas/billing/cluster-configuration-costs.md#std-label-cluster-config-costs) documentation.

   ```text
   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](https://www.mongodb.com/docs/manual/reference/connection-string-options.md#std-label-connections-connection-options) and connects to your cluster through [`mongosh`.](https://www.mongodb.com/docs/mongodb-shell.md#mongodb-binary-bin.mongosh)

2. Set up programmatic authentication to the temporary project.

   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:

   Create a service account for the temporary project.

   Follow the instructions in [Get Started with the Atlas Administration API](https://www.mongodb.com/docs/atlas/configure-api-access.md#std-label-atlas-admin-api-access) to create a service account for your temporary project. Save the client ID and client secret values for the service account.

   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](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-env-variables.md#std-label-atlas-cli-env-vars),  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. Test your automations on the temporary project.

   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. Delete the temporary project, cluster, and database user.

   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:

   Run the [atlas clusters delete](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-clusters-delete.md#std-label-atlas-clusters-delete) command to delete the temporary cluster and its database users. Replace `<projectId>` with the project ID for the temporary project.

   ```text
   atlas clusters delete myTempCluster --projectId <projectId> --force
   ```

   Run the [atlas projects delete](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-projects-delete.md#std-label-atlas-projects-delete) command to delete the temporary project. Replace `<projectId>` with the project ID for your temporary project.

   ```text
   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](https://www.mongodb.com/docs/atlas/cli/current/command/atlas-projects-list.md#std-label-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.
