1. Atlas Private IP for Enhanced Database Security


    To create a secure MongoDB Atlas deployment with enhanced database security using a private endpoint, Pulumi provides a resource called mongodbatlas.PrivateEndpointRegionalMode from the MongoDB Atlas provider. This resource allows you to enable regional mode for your private endpoints, which can improve network security and data privacy by ensuring that all traffic to and from your MongoDB Atlas project must use private networking.

    Below is a Pulumi program in Python that enables regional mode for private endpoints in a MongoDB Atlas project, which secures database traffic within a VPC (Virtual Private Cloud). Here's how it works:

    1. We start by importing necessary Pulumi libraries and setting up the MongoDB Atlas provider.
    2. We define our MongoDB Atlas project, ensuring that we have a project to work within.
    3. We then configure the private endpoint regional mode, associating it with our MongoDB Atlas project and specifying network details.

    Let's go through the Pulumi program:

    import pulumi import pulumi_mongodbatlas as mongodbatlas # MongoDB Atlas requires an API key with appropriate privileges and your organization/project IDs. # These can be set via configuration or environment variables. config = pulumi.Config() mongo_atlas_api_key = config.require_secret("mongoAtlasApiKey") atlas_project_id = config.require("atlasProjectId") # Configure the MongoDB Atlas provider with your API key. mongodbatlas_provider = mongodbatlas.Provider("MongoDBAtlasProvider", public_key=mongo_atlas_api_key.public_key, private_key=mongo_atlas_api_key.private_key) # Create or select an existing MongoDB Atlas project. project = mongodbatlas.Project("my-mongo-project", org_id="your_mongo_atlas_org_id", name="my-mongo-project", opts=pulumi.ResourceOptions(provider=mongodbatlas_provider)) # Enable regional mode for your private endpoints within the specified project. private_endpoint = mongodbatlas.PrivateEndpointRegionalMode("my-private-endpoint", enabled=True, project_id=project.id) # Export the MongoDB Atlas project ID and private endpoint ID for easy access. pulumi.export("project_id", project.id) pulumi.export("private_endpoint_id", private_endpoint.id)

    The above program does the following:

    • We create a new project or use an existing MongoDB Atlas project to enable private endpoints.
    • Next, we enable the private endpoint regional mode by providing the project_id and setting enabled to True.
    • Lastly, we are exporting the project_id and private_endpoint_id to view them in the Pulumi Console once the deployment is successful.

    When you run this Pulumi program, it provisions the necessary resources in your MongoDB Atlas account to increase the security of your MongoDB deployments using private IPs, limiting access to your database only through your private network.

    Remember to replace the placeholder "your_mongo_atlas_org_id" with your actual MongoDB Atlas organization ID and set the confidential API key value via Pulumi's secrets management for security purposes.

    For more information, you can refer to the PrivateEndpointRegionalMode documentation.

    This is a simple example showcasing how to enhance the security of your MongoDB Atlas cluster using Pulumi's infrastructure as code approach. You can extend this example by integrating more network configuration details and Atlas resources according to your requirements.