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

mongodbatlas.ProjectApiKey

Explore with Pulumi AI

Example Usage

Create And Assign PAK Together

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

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

test = mongodbatlas.ProjectApiKey("test",
    description="Description of your API key",
    project_assignments=[{
        "project_id": "64259ee860c43338194b0f8e",
        "role_names": ["GROUP_OWNER"],
    }])
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_OWNER"),
					},
				},
			},
		})
		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 test = new Mongodbatlas.ProjectApiKey("test", new()
    {
        Description = "Description of your API key",
        ProjectAssignments = new[]
        {
            new Mongodbatlas.Inputs.ProjectApiKeyProjectAssignmentArgs
            {
                ProjectId = "64259ee860c43338194b0f8e",
                RoleNames = new[]
                {
                    "GROUP_OWNER",
                },
            },
        },
    });

});
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 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 test = new ProjectApiKey("test", ProjectApiKeyArgs.builder()
            .description("Description of your API key")
            .projectAssignments(ProjectApiKeyProjectAssignmentArgs.builder()
                .projectId("64259ee860c43338194b0f8e")
                .roleNames("GROUP_OWNER")
                .build())
            .build());

    }
}
Copy
resources:
  test:
    type: mongodbatlas:ProjectApiKey
    properties:
      description: Description of your API key
      projectAssignments:
        - projectId: 64259ee860c43338194b0f8e
          roleNames:
            - GROUP_OWNER
Copy

Create And Assign PAK To Multiple Projects

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

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

test = mongodbatlas.ProjectApiKey("test",
    description="Description of your API key",
    project_assignments=[
        {
            "project_id": "64259ee860c43338194b0f8e",
            "role_names": [
                "GROUP_READ_ONLY",
                "GROUP_OWNER",
            ],
        },
        {
            "project_id": "74259ee860c43338194b0f8e",
            "role_names": ["GROUP_READ_ONLY"],
        },
    ])
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"),
						pulumi.String("GROUP_OWNER"),
					},
				},
				&mongodbatlas.ProjectApiKeyProjectAssignmentArgs{
					ProjectId: pulumi.String("74259ee860c43338194b0f8e"),
					RoleNames: pulumi.StringArray{
						pulumi.String("GROUP_READ_ONLY"),
					},
				},
			},
		})
		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 test = new Mongodbatlas.ProjectApiKey("test", new()
    {
        Description = "Description of your API key",
        ProjectAssignments = new[]
        {
            new Mongodbatlas.Inputs.ProjectApiKeyProjectAssignmentArgs
            {
                ProjectId = "64259ee860c43338194b0f8e",
                RoleNames = new[]
                {
                    "GROUP_READ_ONLY",
                    "GROUP_OWNER",
                },
            },
            new Mongodbatlas.Inputs.ProjectApiKeyProjectAssignmentArgs
            {
                ProjectId = "74259ee860c43338194b0f8e",
                RoleNames = new[]
                {
                    "GROUP_READ_ONLY",
                },
            },
        },
    });

});
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 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 test = new ProjectApiKey("test", ProjectApiKeyArgs.builder()
            .description("Description of your API key")
            .projectAssignments(            
                ProjectApiKeyProjectAssignmentArgs.builder()
                    .projectId("64259ee860c43338194b0f8e")
                    .roleNames(                    
                        "GROUP_READ_ONLY",
                        "GROUP_OWNER")
                    .build(),
                ProjectApiKeyProjectAssignmentArgs.builder()
                    .projectId("74259ee860c43338194b0f8e")
                    .roleNames("GROUP_READ_ONLY")
                    .build())
            .build());

    }
}
Copy
resources:
  test:
    type: mongodbatlas:ProjectApiKey
    properties:
      description: Description of your API key
      projectAssignments:
        - projectId: 64259ee860c43338194b0f8e
          roleNames:
            - GROUP_READ_ONLY
            - GROUP_OWNER
        - projectId: 74259ee860c43338194b0f8e
          roleNames:
            - GROUP_READ_ONLY
Copy

Create ProjectApiKey Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new ProjectApiKey(name: string, args: ProjectApiKeyArgs, opts?: CustomResourceOptions);
@overload
def ProjectApiKey(resource_name: str,
                  args: ProjectApiKeyArgs,
                  opts: Optional[ResourceOptions] = None)

@overload
def ProjectApiKey(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  description: Optional[str] = None,
                  project_assignments: Optional[Sequence[ProjectApiKeyProjectAssignmentArgs]] = None)
func NewProjectApiKey(ctx *Context, name string, args ProjectApiKeyArgs, opts ...ResourceOption) (*ProjectApiKey, error)
public ProjectApiKey(string name, ProjectApiKeyArgs args, CustomResourceOptions? opts = null)
public ProjectApiKey(String name, ProjectApiKeyArgs args)
public ProjectApiKey(String name, ProjectApiKeyArgs args, CustomResourceOptions options)
type: mongodbatlas:ProjectApiKey
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. ProjectApiKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. ProjectApiKeyArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. ProjectApiKeyArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. ProjectApiKeyArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. ProjectApiKeyArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var projectApiKeyResource = new Mongodbatlas.ProjectApiKey("projectApiKeyResource", new()
{
    Description = "string",
    ProjectAssignments = new[]
    {
        new Mongodbatlas.Inputs.ProjectApiKeyProjectAssignmentArgs
        {
            ProjectId = "string",
            RoleNames = new[]
            {
                "string",
            },
        },
    },
});
Copy
example, err := mongodbatlas.NewProjectApiKey(ctx, "projectApiKeyResource", &mongodbatlas.ProjectApiKeyArgs{
	Description: pulumi.String("string"),
	ProjectAssignments: mongodbatlas.ProjectApiKeyProjectAssignmentArray{
		&mongodbatlas.ProjectApiKeyProjectAssignmentArgs{
			ProjectId: pulumi.String("string"),
			RoleNames: pulumi.StringArray{
				pulumi.String("string"),
			},
		},
	},
})
Copy
var projectApiKeyResource = new ProjectApiKey("projectApiKeyResource", ProjectApiKeyArgs.builder()
    .description("string")
    .projectAssignments(ProjectApiKeyProjectAssignmentArgs.builder()
        .projectId("string")
        .roleNames("string")
        .build())
    .build());
Copy
project_api_key_resource = mongodbatlas.ProjectApiKey("projectApiKeyResource",
    description="string",
    project_assignments=[{
        "project_id": "string",
        "role_names": ["string"],
    }])
Copy
const projectApiKeyResource = new mongodbatlas.ProjectApiKey("projectApiKeyResource", {
    description: "string",
    projectAssignments: [{
        projectId: "string",
        roleNames: ["string"],
    }],
});
Copy
type: mongodbatlas:ProjectApiKey
properties:
    description: string
    projectAssignments:
        - projectId: string
          roleNames:
            - string
Copy

ProjectApiKey Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The ProjectApiKey resource accepts the following input properties:

Description This property is required. string

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

ProjectAssignments This property is required. List<ProjectApiKeyProjectAssignment>
Description This property is required. string

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

ProjectAssignments This property is required. []ProjectApiKeyProjectAssignmentArgs
description This property is required. String

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

projectAssignments This property is required. List<ProjectApiKeyProjectAssignment>
description This property is required. string

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

projectAssignments This property is required. ProjectApiKeyProjectAssignment[]
description This property is required. str

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

project_assignments This property is required. Sequence[ProjectApiKeyProjectAssignmentArgs]
description This property is required. String

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

projectAssignments This property is required. List<Property Map>

Outputs

All input properties are implicitly available as output properties. Additionally, the ProjectApiKey resource produces the following output properties:

ApiKeyId string
Unique identifier for this Project API key.
Id string
The provider-assigned unique ID for this managed resource.
PrivateKey string
PublicKey string
ApiKeyId string
Unique identifier for this Project API key.
Id string
The provider-assigned unique ID for this managed resource.
PrivateKey string
PublicKey string
apiKeyId String
Unique identifier for this Project API key.
id String
The provider-assigned unique ID for this managed resource.
privateKey String
publicKey String
apiKeyId string
Unique identifier for this Project API key.
id string
The provider-assigned unique ID for this managed resource.
privateKey string
publicKey string
api_key_id str
Unique identifier for this Project API key.
id str
The provider-assigned unique ID for this managed resource.
private_key str
public_key str
apiKeyId String
Unique identifier for this Project API key.
id String
The provider-assigned unique ID for this managed resource.
privateKey String
publicKey String

Look up Existing ProjectApiKey Resource

Get an existing ProjectApiKey resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: ProjectApiKeyState, opts?: CustomResourceOptions): ProjectApiKey
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        api_key_id: Optional[str] = None,
        description: Optional[str] = None,
        private_key: Optional[str] = None,
        project_assignments: Optional[Sequence[ProjectApiKeyProjectAssignmentArgs]] = None,
        public_key: Optional[str] = None) -> ProjectApiKey
func GetProjectApiKey(ctx *Context, name string, id IDInput, state *ProjectApiKeyState, opts ...ResourceOption) (*ProjectApiKey, error)
public static ProjectApiKey Get(string name, Input<string> id, ProjectApiKeyState? state, CustomResourceOptions? opts = null)
public static ProjectApiKey get(String name, Output<String> id, ProjectApiKeyState state, CustomResourceOptions options)
resources:  _:    type: mongodbatlas:ProjectApiKey    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
ApiKeyId string
Unique identifier for this Project API key.
Description string

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

PrivateKey string
ProjectAssignments List<ProjectApiKeyProjectAssignment>
PublicKey string
ApiKeyId string
Unique identifier for this Project API key.
Description string

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

PrivateKey string
ProjectAssignments []ProjectApiKeyProjectAssignmentArgs
PublicKey string
apiKeyId String
Unique identifier for this Project API key.
description String

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

privateKey String
projectAssignments List<ProjectApiKeyProjectAssignment>
publicKey String
apiKeyId string
Unique identifier for this Project API key.
description string

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

privateKey string
projectAssignments ProjectApiKeyProjectAssignment[]
publicKey string
api_key_id str
Unique identifier for this Project API key.
description str

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

private_key str
project_assignments Sequence[ProjectApiKeyProjectAssignmentArgs]
public_key str
apiKeyId String
Unique identifier for this Project API key.
description String

Description of this Project API key.

NOTE: Project created by API Keys must belong to an existing organization.

privateKey String
projectAssignments List<Property Map>
publicKey String

Supporting Types

ProjectApiKeyProjectAssignment
, ProjectApiKeyProjectAssignmentArgs

ProjectId This property is required. string
Project ID to assign to Access Key
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
Project ID to assign to Access Key
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
Project ID to assign to Access Key
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
Project ID to assign to Access Key
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
Project ID to assign to Access Key
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
Project ID to assign to Access Key
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.

Import

API Keys must be imported using project ID, API Key ID e.g.

$ pulumi import mongodbatlas:index/projectApiKey:ProjectApiKey test 5d09d6a59ccf6445652a444a-6576974933969669
Copy

See MongoDB Atlas API - API Key - Documentation for more information.

To learn more about importing existing cloud resources, see Importing resources.

Package Details

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