1. Secure Project Access Control with MongoDB Atlas Teams

    Python

    When working with MongoDB Atlas in a team environment, it's important to implement access controls to ensure that team members have appropriate permissions to the MongoDB Atlas projects and resources. To manage project access on MongoDB Atlas with Pulumi, you will implement the following:

    1. MongoDB Atlas Team: This resource allows you to create a team in your MongoDB Atlas organization. Team members can then be given specific access rights to projects.

    2. Project Access Control: To control access to projects, we will assign roles to the team, specifying which actions the team members can perform within the project.

    For creating a secure project access control structure, you'll typically need to perform the following steps:

    • Define a team with members.
    • Assign the team to a project.
    • Grant specific project roles to the team.

    Here's how you can use Pulumi to set up access control for a MongoDB Atlas project with teams:

    import pulumi import pulumi_mongodbatlas as mongodbatlas # Configure your MongoDB Atlas API Key for authentication with Pulumi using environment variables: # Set the environment variables `MONGODB_ATLAS_PUBLIC_KEY` and `MONGODB_ATLAS_PRIVATE_KEY` # Define the MongoDB Atlas Team # The `name` is a label for the team, `orgId` is your MongoDB Atlas organization ID, # and `usernames` is a list of the MongoDB Atlas usernames that will be part of the team. team = mongodbatlas.Teams("team", name="my-team", org_id="5d0f1f73cf09a29120e173cf", # replace with your Organization ID usernames=["user1@example.com", "user2@example.com"] # replace with actual usernames ) # Assuming you already have a project created either via the MongoDB Atlas UI or via Pulumi # Let's use the project Id which will be used to assign the team to. project_id = "5d0f1f73cf09a29120e173cc" # replace with your Project ID # Assign the team to the project with specific roles # Project roles determine what actions the team members can perform in the project. team_assignment = mongodbatlas.ProjectTeam("projectTeam", project_id=project_id, team_id=team.team_id, roles=["GROUP_READ_ONLY"]) # replace with appropriate roles as needed # Output the team ID and project assignment ID pulumi.export("team_id", team.team_id) pulumi.export("team_project_assignment", team_assignment.id)

    Here's an explanation of the above code:

    • We import pulumi and the pulumi_mongodbatlas module to work with the MongoDB Atlas resources.
    • We define a mongodbatlas.Teams resource named team to create a team under our MongoDB Atlas organization. This will group users into a single entity that can be collectively assigned to MongoDB Atlas projects.
    • Each team has a set of users specified by their MongoDB Atlas usernames.
    • Then we define a mongodbatlas.ProjectTeam resource named team_assignment which assigns the previously created team to a specific MongoDB Atlas project, giving the team a set of roles that define their access privileges within that project.
    • At the end, we export the team_id and the team_project_assignment to be accessed outside of Pulumi, if required.

    Note: Be sure to replace the placeholders like org_id, project_id, and usernames with your actual MongoDB Atlas organization ID, project ID, and user emails.

    With this Pulumi program, you've set up a MongoDB Atlas team and assigned it to a project with specific roles, effectively managing access control for your MongoDB Atlas project.