1. Packages
  2. Packages
  3. Mongodbatlas Provider
  4. API Docs
  5. getApiKeyProjectAssignments
Viewing docs for MongoDB Atlas v4.8.0
published on Thursday, Apr 23, 2026 by Pulumi
mongodbatlas logo
Viewing docs for MongoDB Atlas v4.8.0
published on Thursday, Apr 23, 2026 by Pulumi

    mongodbatlas.getApiKeyProjectAssignments provides an API Key Project Assignments data source. The data source lets you list all API key project assignments for an organization.

    Example Usage

    S

    import * as pulumi from "@pulumi/pulumi";
    import * as mongodbatlas from "@pulumi/mongodbatlas";
    
    const _this = new mongodbatlas.ApiKey("this", {
        orgId: orgId,
        description: "Test API Key",
        roleNames: ["ORG_READ_ONLY"],
    });
    const firstProject = new mongodbatlas.Project("first_project", {
        name: "First Project",
        orgId: orgId,
    });
    const secondProject = new mongodbatlas.Project("second_project", {
        name: "Second Project",
        orgId: orgId,
    });
    const firstAssignmentApiKeyProjectAssignment = new mongodbatlas.ApiKeyProjectAssignment("first_assignment", {
        projectId: firstProject.id,
        apiKeyId: _this.apiKeyId,
        roles: ["GROUP_OWNER"],
    });
    const secondAssignment = new mongodbatlas.ApiKeyProjectAssignment("second_assignment", {
        projectId: secondProject.id,
        apiKeyId: _this.apiKeyId,
        roles: ["GROUP_OWNER"],
    });
    // Add IP Access List Entry to Programmatic API Key 
    const thisAccessListApiKey = new mongodbatlas.AccessListApiKey("this", {
        orgId: orgId,
        cidrBlock: "0.0.0.0/1",
        apiKeyId: _this.apiKeyId,
    });
    // Data source to read a single API key project assignment
    const firstAssignment = mongodbatlas.getApiKeyProjectAssignmentOutput({
        projectId: firstAssignmentApiKeyProjectAssignment.projectId,
        apiKeyId: firstAssignmentApiKeyProjectAssignment.apiKeyId,
    });
    // Data source to read all API key project assignments for a project
    const allAssignments = mongodbatlas.getApiKeyProjectAssignmentsOutput({
        projectId: firstProject.id,
    });
    export const firstAssignmentProjectId = firstAssignment.apply(firstAssignment => firstAssignment.projectId);
    export const allAssignmentsProjectIds = allAssignments.apply(allAssignments => .map(assignment => (assignment.projectId)));
    
    import pulumi
    import pulumi_mongodbatlas as mongodbatlas
    
    this = mongodbatlas.ApiKey("this",
        org_id=org_id,
        description="Test API Key",
        role_names=["ORG_READ_ONLY"])
    first_project = mongodbatlas.Project("first_project",
        name="First Project",
        org_id=org_id)
    second_project = mongodbatlas.Project("second_project",
        name="Second Project",
        org_id=org_id)
    first_assignment_api_key_project_assignment = mongodbatlas.ApiKeyProjectAssignment("first_assignment",
        project_id=first_project.id,
        api_key_id=this.api_key_id,
        roles=["GROUP_OWNER"])
    second_assignment = mongodbatlas.ApiKeyProjectAssignment("second_assignment",
        project_id=second_project.id,
        api_key_id=this.api_key_id,
        roles=["GROUP_OWNER"])
    # Add IP Access List Entry to Programmatic API Key 
    this_access_list_api_key = mongodbatlas.AccessListApiKey("this",
        org_id=org_id,
        cidr_block="0.0.0.0/1",
        api_key_id=this.api_key_id)
    # Data source to read a single API key project assignment
    first_assignment = mongodbatlas.get_api_key_project_assignment_output(project_id=first_assignment_api_key_project_assignment.project_id,
        api_key_id=first_assignment_api_key_project_assignment.api_key_id)
    # Data source to read all API key project assignments for a project
    all_assignments = mongodbatlas.get_api_key_project_assignments_output(project_id=first_project.id)
    pulumi.export("firstAssignmentProjectId", first_assignment.project_id)
    pulumi.export("allAssignmentsProjectIds", all_assignments.apply(lambda all_assignments: [assignment.project_id for assignment in all_assignments.results]))
    
    Example coming soon!
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Mongodbatlas = Pulumi.Mongodbatlas;
    
    return await Deployment.RunAsync(() => 
    {
        var @this = new Mongodbatlas.Index.ApiKey("this", new()
        {
            OrgId = orgId,
            Description = "Test API Key",
            RoleNames = new[]
            {
                "ORG_READ_ONLY",
            },
        });
    
        var firstProject = new Mongodbatlas.Index.Project("first_project", new()
        {
            Name = "First Project",
            OrgId = orgId,
        });
    
        var secondProject = new Mongodbatlas.Index.Project("second_project", new()
        {
            Name = "Second Project",
            OrgId = orgId,
        });
    
        var firstAssignmentApiKeyProjectAssignment = new Mongodbatlas.Index.ApiKeyProjectAssignment("first_assignment", new()
        {
            ProjectId = firstProject.Id,
            ApiKeyId = @this.ApiKeyId,
            Roles = new[]
            {
                "GROUP_OWNER",
            },
        });
    
        var secondAssignment = new Mongodbatlas.Index.ApiKeyProjectAssignment("second_assignment", new()
        {
            ProjectId = secondProject.Id,
            ApiKeyId = @this.ApiKeyId,
            Roles = new[]
            {
                "GROUP_OWNER",
            },
        });
    
        // Add IP Access List Entry to Programmatic API Key 
        var thisAccessListApiKey = new Mongodbatlas.Index.AccessListApiKey("this", new()
        {
            OrgId = orgId,
            CidrBlock = "0.0.0.0/1",
            ApiKeyId = @this.ApiKeyId,
        });
    
        // Data source to read a single API key project assignment
        var firstAssignment = Mongodbatlas.Index.GetApiKeyProjectAssignment.Invoke(new()
        {
            ProjectId = firstAssignmentApiKeyProjectAssignment.ProjectId,
            ApiKeyId = firstAssignmentApiKeyProjectAssignment.ApiKeyId,
        });
    
        // Data source to read all API key project assignments for a project
        var allAssignments = Mongodbatlas.Index.GetApiKeyProjectAssignments.Invoke(new()
        {
            ProjectId = firstProject.Id,
        });
    
        return new Dictionary<string, object?>
        {
            ["firstAssignmentProjectId"] = firstAssignment.Apply(getApiKeyProjectAssignmentResult => getApiKeyProjectAssignmentResult.ProjectId),
            ["allAssignmentsProjectIds"] = .Select(assignment => 
            {
                return assignment.ProjectId;
            }).ToList(),
        };
    });
    
    Example coming soon!
    
    Example coming soon!
    

    Using getApiKeyProjectAssignments

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getApiKeyProjectAssignments(args: GetApiKeyProjectAssignmentsArgs, opts?: InvokeOptions): Promise<GetApiKeyProjectAssignmentsResult>
    function getApiKeyProjectAssignmentsOutput(args: GetApiKeyProjectAssignmentsOutputArgs, opts?: InvokeOptions): Output<GetApiKeyProjectAssignmentsResult>
    def get_api_key_project_assignments(project_id: Optional[str] = None,
                                        opts: Optional[InvokeOptions] = None) -> GetApiKeyProjectAssignmentsResult
    def get_api_key_project_assignments_output(project_id: Optional[pulumi.Input[str]] = None,
                                        opts: Optional[InvokeOptions] = None) -> Output[GetApiKeyProjectAssignmentsResult]
    func LookupApiKeyProjectAssignments(ctx *Context, args *LookupApiKeyProjectAssignmentsArgs, opts ...InvokeOption) (*LookupApiKeyProjectAssignmentsResult, error)
    func LookupApiKeyProjectAssignmentsOutput(ctx *Context, args *LookupApiKeyProjectAssignmentsOutputArgs, opts ...InvokeOption) LookupApiKeyProjectAssignmentsResultOutput

    > Note: This function is named LookupApiKeyProjectAssignments in the Go SDK.

    public static class GetApiKeyProjectAssignments 
    {
        public static Task<GetApiKeyProjectAssignmentsResult> InvokeAsync(GetApiKeyProjectAssignmentsArgs args, InvokeOptions? opts = null)
        public static Output<GetApiKeyProjectAssignmentsResult> Invoke(GetApiKeyProjectAssignmentsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetApiKeyProjectAssignmentsResult> getApiKeyProjectAssignments(GetApiKeyProjectAssignmentsArgs args, InvokeOptions options)
    public static Output<GetApiKeyProjectAssignmentsResult> getApiKeyProjectAssignments(GetApiKeyProjectAssignmentsArgs args, InvokeOptions options)
    
    fn::invoke:
      function: mongodbatlas:index/getApiKeyProjectAssignments:getApiKeyProjectAssignments
      arguments:
        # arguments dictionary

    The following arguments are supported:

    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    projectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    project_id str
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.

    getApiKeyProjectAssignments Result

    The following output properties are available:

    Id string
    The provider-assigned unique ID for this managed resource.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    Results List<GetApiKeyProjectAssignmentsResult>
    List of documents that MongoDB Cloud returns for this request.
    Id string
    The provider-assigned unique ID for this managed resource.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    Results []GetApiKeyProjectAssignmentsResult
    List of documents that MongoDB Cloud returns for this request.
    id String
    The provider-assigned unique ID for this managed resource.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    results List<GetApiKeyProjectAssignmentsResult>
    List of documents that MongoDB Cloud returns for this request.
    id string
    The provider-assigned unique ID for this managed resource.
    projectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    results GetApiKeyProjectAssignmentsResult[]
    List of documents that MongoDB Cloud returns for this request.
    id str
    The provider-assigned unique ID for this managed resource.
    project_id str
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    results Sequence[GetApiKeyProjectAssignmentsResult]
    List of documents that MongoDB Cloud returns for this request.
    id String
    The provider-assigned unique ID for this managed resource.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    results List<Property Map>
    List of documents that MongoDB Cloud returns for this request.

    Supporting Types

    GetApiKeyProjectAssignmentsResult

    ApiKeyId string
    Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    Roles List<string>
    Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
    ApiKeyId string
    Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    Roles []string
    Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
    apiKeyId String
    Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    roles List<String>
    Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
    apiKeyId string
    Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
    projectId string
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    roles string[]
    Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
    api_key_id str
    Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
    project_id str
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    roles Sequence[str]
    Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.
    apiKeyId String
    Unique 24-hexadecimal digit string that identifies this organization API key that you want to assign to one project.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project, also known as groupId in the official documentation.
    roles List<String>
    Human-readable label that identifies the collection of privileges that MongoDB Cloud grants a specific API key, MongoDB Cloud user, or MongoDB Cloud team. These roles include only the specific project-level roles.

    Package Details

    Repository
    MongoDB Atlas pulumi/pulumi-mongodbatlas
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the mongodbatlas Terraform Provider.
    mongodbatlas logo
    Viewing docs for MongoDB Atlas v4.8.0
    published on Thursday, Apr 23, 2026 by Pulumi
      Try Pulumi Cloud free. Your team will thank you.