1. Packages
  2. Mongodbatlas Provider
  3. API Docs
  4. getProjectApiKey
MongoDB Atlas v3.30.0 published on Friday, Mar 21, 2025 by Pulumi

mongodbatlas.getProjectApiKey

Explore with Pulumi AI

Example Usage

Using project_id and api_key_id attribute to query

import * as pulumi from "@pulumi/pulumi";
import * as mongodbatlas from "@pulumi/mongodbatlas";

const testProjectApiKey = new mongodbatlas.ProjectApiKey("test", {
    description: "Description of your API key",
    projectAssignments: [{
        projectId: "64259ee860c43338194b0f8e",
        roleNames: ["GROUP_READ_ONLY"],
    }],
});
const test = mongodbatlas.getProjectApiKey({
    projectId: "64259ee860c43338194b0f8e",
    apiKeyId: testMongodbatlasApiKey.apiKeyId,
});
Copy
import pulumi
import pulumi_mongodbatlas as mongodbatlas

test_project_api_key = mongodbatlas.ProjectApiKey("test",
    description="Description of your API key",
    project_assignments=[{
        "project_id": "64259ee860c43338194b0f8e",
        "role_names": ["GROUP_READ_ONLY"],
    }])
test = mongodbatlas.get_project_api_key(project_id="64259ee860c43338194b0f8e",
    api_key_id=test_mongodbatlas_api_key["apiKeyId"])
Copy
package main

import (
	"github.com/pulumi/pulumi-mongodbatlas/sdk/v3/go/mongodbatlas"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := mongodbatlas.NewProjectApiKey(ctx, "test", &mongodbatlas.ProjectApiKeyArgs{
			Description: pulumi.String("Description of your API key"),
			ProjectAssignments: mongodbatlas.ProjectApiKeyProjectAssignmentArray{
				&mongodbatlas.ProjectApiKeyProjectAssignmentArgs{
					ProjectId: pulumi.String("64259ee860c43338194b0f8e"),
					RoleNames: pulumi.StringArray{
						pulumi.String("GROUP_READ_ONLY"),
					},
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = mongodbatlas.LookupProjectApiKey(ctx, &mongodbatlas.LookupProjectApiKeyArgs{
			ProjectId: "64259ee860c43338194b0f8e",
			ApiKeyId:  testMongodbatlasApiKey.ApiKeyId,
		}, nil)
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Mongodbatlas = Pulumi.Mongodbatlas;

return await Deployment.RunAsync(() => 
{
    var testProjectApiKey = new Mongodbatlas.ProjectApiKey("test", new()
    {
        Description = "Description of your API key",
        ProjectAssignments = new[]
        {
            new Mongodbatlas.Inputs.ProjectApiKeyProjectAssignmentArgs
            {
                ProjectId = "64259ee860c43338194b0f8e",
                RoleNames = new[]
                {
                    "GROUP_READ_ONLY",
                },
            },
        },
    });

    var test = Mongodbatlas.GetProjectApiKey.Invoke(new()
    {
        ProjectId = "64259ee860c43338194b0f8e",
        ApiKeyId = testMongodbatlasApiKey.ApiKeyId,
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.mongodbatlas.ProjectApiKey;
import com.pulumi.mongodbatlas.ProjectApiKeyArgs;
import com.pulumi.mongodbatlas.inputs.ProjectApiKeyProjectAssignmentArgs;
import com.pulumi.mongodbatlas.MongodbatlasFunctions;
import com.pulumi.mongodbatlas.inputs.GetProjectApiKeyArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var testProjectApiKey = new ProjectApiKey("testProjectApiKey", ProjectApiKeyArgs.builder()
            .description("Description of your API key")
            .projectAssignments(ProjectApiKeyProjectAssignmentArgs.builder()
                .projectId("64259ee860c43338194b0f8e")
                .roleNames("GROUP_READ_ONLY")
                .build())
            .build());

        final var test = MongodbatlasFunctions.getProjectApiKey(GetProjectApiKeyArgs.builder()
            .projectId("64259ee860c43338194b0f8e")
            .apiKeyId(testMongodbatlasApiKey.apiKeyId())
            .build());

    }
}
Copy
resources:
  testProjectApiKey:
    type: mongodbatlas:ProjectApiKey
    name: test
    properties:
      description: Description of your API key
      projectAssignments:
        - projectId: 64259ee860c43338194b0f8e
          roleNames:
            - GROUP_READ_ONLY
variables:
  test:
    fn::invoke:
      function: mongodbatlas:getProjectApiKey
      arguments:
        projectId: 64259ee860c43338194b0f8e
        apiKeyId: ${testMongodbatlasApiKey.apiKeyId}
Copy

Using getProjectApiKey

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 getProjectApiKey(args: GetProjectApiKeyArgs, opts?: InvokeOptions): Promise<GetProjectApiKeyResult>
function getProjectApiKeyOutput(args: GetProjectApiKeyOutputArgs, opts?: InvokeOptions): Output<GetProjectApiKeyResult>
Copy
def get_project_api_key(api_key_id: Optional[str] = None,
                        project_id: Optional[str] = None,
                        opts: Optional[InvokeOptions] = None) -> GetProjectApiKeyResult
def get_project_api_key_output(api_key_id: Optional[pulumi.Input[str]] = None,
                        project_id: Optional[pulumi.Input[str]] = None,
                        opts: Optional[InvokeOptions] = None) -> Output[GetProjectApiKeyResult]
Copy
func LookupProjectApiKey(ctx *Context, args *LookupProjectApiKeyArgs, opts ...InvokeOption) (*LookupProjectApiKeyResult, error)
func LookupProjectApiKeyOutput(ctx *Context, args *LookupProjectApiKeyOutputArgs, opts ...InvokeOption) LookupProjectApiKeyResultOutput
Copy

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

public static class GetProjectApiKey 
{
    public static Task<GetProjectApiKeyResult> InvokeAsync(GetProjectApiKeyArgs args, InvokeOptions? opts = null)
    public static Output<GetProjectApiKeyResult> Invoke(GetProjectApiKeyInvokeArgs args, InvokeOptions? opts = null)
}
Copy
public static CompletableFuture<GetProjectApiKeyResult> getProjectApiKey(GetProjectApiKeyArgs args, InvokeOptions options)
public static Output<GetProjectApiKeyResult> getProjectApiKey(GetProjectApiKeyArgs args, InvokeOptions options)
Copy
fn::invoke:
  function: mongodbatlas:index/getProjectApiKey:getProjectApiKey
  arguments:
    # arguments dictionary
Copy

The following arguments are supported:

ApiKeyId This property is required. string
Unique identifier for this Project API key.
ProjectId This property is required. string
The unique ID for the project.
ApiKeyId This property is required. string
Unique identifier for this Project API key.
ProjectId This property is required. string
The unique ID for the project.
apiKeyId This property is required. String
Unique identifier for this Project API key.
projectId This property is required. String
The unique ID for the project.
apiKeyId This property is required. string
Unique identifier for this Project API key.
projectId This property is required. string
The unique ID for the project.
api_key_id This property is required. str
Unique identifier for this Project API key.
project_id This property is required. str
The unique ID for the project.
apiKeyId This property is required. String
Unique identifier for this Project API key.
projectId This property is required. String
The unique ID for the project.

getProjectApiKey Result

The following output properties are available:

ApiKeyId string
Description string
Description of this Project API key.
Id string
The provider-assigned unique ID for this managed resource.
PrivateKey string
Private key for this Organization API key.
ProjectAssignments List<GetProjectApiKeyProjectAssignment>
ProjectId string
Project ID to assign to Access Key
PublicKey string
Public key for this Organization API key.
ApiKeyId string
Description string
Description of this Project API key.
Id string
The provider-assigned unique ID for this managed resource.
PrivateKey string
Private key for this Organization API key.
ProjectAssignments []GetProjectApiKeyProjectAssignment
ProjectId string
Project ID to assign to Access Key
PublicKey string
Public key for this Organization API key.
apiKeyId String
description String
Description of this Project API key.
id String
The provider-assigned unique ID for this managed resource.
privateKey String
Private key for this Organization API key.
projectAssignments List<GetProjectApiKeyProjectAssignment>
projectId String
Project ID to assign to Access Key
publicKey String
Public key for this Organization API key.
apiKeyId string
description string
Description of this Project API key.
id string
The provider-assigned unique ID for this managed resource.
privateKey string
Private key for this Organization API key.
projectAssignments GetProjectApiKeyProjectAssignment[]
projectId string
Project ID to assign to Access Key
publicKey string
Public key for this Organization API key.
api_key_id str
description str
Description of this Project API key.
id str
The provider-assigned unique ID for this managed resource.
private_key str
Private key for this Organization API key.
project_assignments Sequence[GetProjectApiKeyProjectAssignment]
project_id str
Project ID to assign to Access Key
public_key str
Public key for this Organization API key.
apiKeyId String
description String
Description of this Project API key.
id String
The provider-assigned unique ID for this managed resource.
privateKey String
Private key for this Organization API key.
projectAssignments List<Property Map>
projectId String
Project ID to assign to Access Key
publicKey String
Public key for this Organization API key.

Supporting Types

GetProjectApiKeyProjectAssignment

ProjectId This property is required. string
The unique ID for the project.
RoleNames This property is required. List<string>
List of Project roles that the Programmatic API key needs to have. Ensure you provide: at least one role and ensure all roles are valid for the Project. You must specify an array even if you are only associating a single role with the Programmatic API key. The MongoDB Documentation describes the valid roles that can be assigned.
ProjectId This property is required. string
The unique ID for the project.
RoleNames This property is required. []string
List of Project roles that the Programmatic API key needs to have. Ensure you provide: at least one role and ensure all roles are valid for the Project. You must specify an array even if you are only associating a single role with the Programmatic API key. The MongoDB Documentation describes the valid roles that can be assigned.
projectId This property is required. String
The unique ID for the project.
roleNames This property is required. List<String>
List of Project roles that the Programmatic API key needs to have. Ensure you provide: at least one role and ensure all roles are valid for the Project. You must specify an array even if you are only associating a single role with the Programmatic API key. The MongoDB Documentation describes the valid roles that can be assigned.
projectId This property is required. string
The unique ID for the project.
roleNames This property is required. string[]
List of Project roles that the Programmatic API key needs to have. Ensure you provide: at least one role and ensure all roles are valid for the Project. You must specify an array even if you are only associating a single role with the Programmatic API key. The MongoDB Documentation describes the valid roles that can be assigned.
project_id This property is required. str
The unique ID for the project.
role_names This property is required. Sequence[str]
List of Project roles that the Programmatic API key needs to have. Ensure you provide: at least one role and ensure all roles are valid for the Project. You must specify an array even if you are only associating a single role with the Programmatic API key. The MongoDB Documentation describes the valid roles that can be assigned.
projectId This property is required. String
The unique ID for the project.
roleNames This property is required. List<String>
List of Project roles that the Programmatic API key needs to have. Ensure you provide: at least one role and ensure all roles are valid for the Project. You must specify an array even if you are only associating a single role with the Programmatic API key. The MongoDB Documentation describes the valid roles that can be assigned.

Package Details

Repository
MongoDB Atlas pulumi/pulumi-mongodbatlas
License
Apache-2.0
Notes
This Pulumi package is based on the mongodbatlas Terraform Provider.