1. Automated Snapshot Policies for MongoDB Atlas


    Automated snapshot policies in MongoDB Atlas allow you to create a schedule for taking snapshots of your MongoDB databases, which helps with data backup and recovery. To implement this using Pulumi, we'll primarily use the mongodbatlas.Cluster resource, which has properties related to backup and snapshot configurations.

    In the following Pulumi program, I'll demonstrate how to create a MongoDB Atlas cluster and configure its backup schedule:

    1. mongodbatlas.Cluster: A resource that creates a MongoDB cluster on Atlas. We can define the backup policies as part of the cluster configuration. The properties you'll see related to backups include:
      • providerBackupEnabled: This will enable the cloud provider snapshots.
      • pitEnabled: This is to enable Point-in-Time restore, which requires continuous cloud backups.

    Here's the Pulumi program written in Python that will set up a MongoDB Atlas cluster with snapshot policies:

    import pulumi import pulumi_mongodbatlas as mongodbatlas # Create a MongoDB Atlas project. project = mongodbatlas.Project("myProject", org_id="<Your MongoDB Atlas Organization ID>") # Create a MongoDB Atlas cluster with backup and snapshot policies enabled. cluster = mongodbatlas.Cluster("myCluster", project_id=project.id, # Specify the cluster configuration here. cluster_type="REPLICASET", # The type of the cluster, can be "REPLICASET" or "SHARDED". replication_factor=3, # Number of replica set members. provider_instance_size_name="M10", # The instance size name. provider_name="AWS", # Cloud provider name, for example, "AWS", "GCP", "AZURE". provider_region_name="us-west-2", # The region to deploy the cluster. provider_backup_enabled=True, # Enable cloud provider snapshots. pit_enabled=True, # Enable point-in-time restores. # Define the preferred backup window and snapshot retention policy here. provider_backup_schedule={ "frequency_type": "daily", # Frequency of the snapshot, "daily", "weekly", or customized. "frequency_interval": 1, # The interval at which to take snapshots. "retention_unit": "days", # The unit for the retention value. "retention_value": 7 # The number of days to keep the snapshots. } ) # Export the cluster's connection strings for application use. pulumi.export("mongo_uri", cluster.connection_strings["standard_srv"])

    In this code, replace <Your MongoDB Atlas Organization ID> with your actual MongoDB Atlas organization ID. The cluster is set up with a simple snapshot policy. However, the Pulumi MongoDB Atlas provider currently may not support very fine-grained backup schedules within the resource definition.

    Therefore, if you need to configure more specific snapshot policies (e.g., more complex retention schedules, different backup frequencies, etc.) you can either:

    • Manage the snapshot policies directly through the MongoDB Atlas UI or API after cluster creation.
    • Look into extending the functionality with custom providers or dynamic providers if supported.

    Remember to set up your Pulumi MongoDB Atlas provider and have the necessary credentials configured on your machine or CI/CD environment. You also need to install the Pulumi MongoDB Atlas plugin using the command pulumi plugin install resource mongodbatlas vX.Y.Z where X.Y.Z is the version number which has the features you require. This program will create the Atlas project and cluster with the defined snapshot scheduling policy.