1. Packages
  2. Mongodbatlas Provider
  3. API Docs
  4. ServiceAccountProjectAssignment
MongoDB Atlas v4.2.0 published on Friday, Jan 23, 2026 by Pulumi
mongodbatlas logo
MongoDB Atlas v4.2.0 published on Friday, Jan 23, 2026 by Pulumi

    Example Usage

    S

    import * as pulumi from "@pulumi/pulumi";
    import * as mongodbatlas from "@pulumi/mongodbatlas";
    
    const thisServiceAccount = new mongodbatlas.ServiceAccount("this", {
        orgId: orgId,
        name: "example-service-account",
        description: "Example Service Account",
        roles: ["ORG_MEMBER"],
        secretExpiresAfterHours: 2160,
    });
    const thisServiceAccountProjectAssignment = new mongodbatlas.ServiceAccountProjectAssignment("this", {
        projectId: projectId,
        clientId: thisServiceAccount.clientId,
        roles: ["GROUP_READ_ONLY"],
    });
    const _this = mongodbatlas.getServiceAccountProjectAssignmentOutput({
        projectId: thisServiceAccountProjectAssignment.projectId,
        clientId: thisServiceAccountProjectAssignment.clientId,
    });
    const thisGetServiceAccountProjectAssignments = thisServiceAccount.clientId.apply(clientId => mongodbatlas.getServiceAccountProjectAssignmentsOutput({
        orgId: orgId,
        clientId: clientId,
    }));
    export const serviceAccountProjectRoles = _this.apply(_this => _this.roles);
    export const serviceAccountAssignedProjects = thisGetServiceAccountProjectAssignments.apply(thisGetServiceAccountProjectAssignments => thisGetServiceAccountProjectAssignments.results);
    
    import pulumi
    import pulumi_mongodbatlas as mongodbatlas
    
    this_service_account = mongodbatlas.ServiceAccount("this",
        org_id=org_id,
        name="example-service-account",
        description="Example Service Account",
        roles=["ORG_MEMBER"],
        secret_expires_after_hours=2160)
    this_service_account_project_assignment = mongodbatlas.ServiceAccountProjectAssignment("this",
        project_id=project_id,
        client_id=this_service_account.client_id,
        roles=["GROUP_READ_ONLY"])
    this = mongodbatlas.get_service_account_project_assignment_output(project_id=this_service_account_project_assignment.project_id,
        client_id=this_service_account_project_assignment.client_id)
    this_get_service_account_project_assignments = this_service_account.client_id.apply(lambda client_id: mongodbatlas.get_service_account_project_assignments_output(org_id=org_id,
        client_id=client_id))
    pulumi.export("serviceAccountProjectRoles", this.roles)
    pulumi.export("serviceAccountAssignedProjects", this_get_service_account_project_assignments.results)
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-mongodbatlas/sdk/v4/go/mongodbatlas"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    )
    func main() {
    pulumi.Run(func(ctx *pulumi.Context) error {
    thisServiceAccount, err := mongodbatlas.NewServiceAccount(ctx, "this", &mongodbatlas.ServiceAccountArgs{
    OrgId: pulumi.Any(orgId),
    Name: pulumi.String("example-service-account"),
    Description: pulumi.String("Example Service Account"),
    Roles: pulumi.StringArray{
    pulumi.String("ORG_MEMBER"),
    },
    SecretExpiresAfterHours: pulumi.Int(2160),
    })
    if err != nil {
    return err
    }
    thisServiceAccountProjectAssignment, err := mongodbatlas.NewServiceAccountProjectAssignment(ctx, "this", &mongodbatlas.ServiceAccountProjectAssignmentArgs{
    ProjectId: pulumi.Any(projectId),
    ClientId: thisServiceAccount.ClientId,
    Roles: pulumi.StringArray{
    pulumi.String("GROUP_READ_ONLY"),
    },
    })
    if err != nil {
    return err
    }
    this := mongodbatlas.LookupServiceAccountProjectAssignmentOutput(ctx, mongodbatlas.GetServiceAccountProjectAssignmentOutputArgs{
    ProjectId: thisServiceAccountProjectAssignment.ProjectId,
    ClientId: thisServiceAccountProjectAssignment.ClientId,
    }, nil);
    thisGetServiceAccountProjectAssignments := thisServiceAccount.ClientId.ApplyT(func(clientId string) (mongodbatlas.GetServiceAccountProjectAssignmentsResult, error) {
    return mongodbatlas.GetServiceAccountProjectAssignmentsResult(interface{}(mongodbatlas.LookupServiceAccountProjectAssignments(ctx, &mongodbatlas.LookupServiceAccountProjectAssignmentsArgs{
    OrgId: orgId,
    ClientId: clientId,
    }, nil))), nil
    }).(mongodbatlas.GetServiceAccountProjectAssignmentsResultOutput)
    ctx.Export("serviceAccountProjectRoles", this.ApplyT(func(this mongodbatlas.GetServiceAccountProjectAssignmentResult) (interface{}, error) {
    return this.Roles, nil
    }).(pulumi.Interface{}Output))
    ctx.Export("serviceAccountAssignedProjects", thisGetServiceAccountProjectAssignments.ApplyT(func(thisGetServiceAccountProjectAssignments mongodbatlas.GetServiceAccountProjectAssignmentsResult) ([]mongodbatlas.GetServiceAccountProjectAssignmentsResult, error) {
    return []mongodbatlas.GetServiceAccountProjectAssignmentsResult(thisGetServiceAccountProjectAssignments.Results), nil
    }).([]mongodbatlas.GetServiceAccountProjectAssignmentsResultOutput))
    return nil
    })
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Mongodbatlas = Pulumi.Mongodbatlas;
    
    return await Deployment.RunAsync(() => 
    {
        var thisServiceAccount = new Mongodbatlas.ServiceAccount("this", new()
        {
            OrgId = orgId,
            Name = "example-service-account",
            Description = "Example Service Account",
            Roles = new[]
            {
                "ORG_MEMBER",
            },
            SecretExpiresAfterHours = 2160,
        });
    
        var thisServiceAccountProjectAssignment = new Mongodbatlas.ServiceAccountProjectAssignment("this", new()
        {
            ProjectId = projectId,
            ClientId = thisServiceAccount.ClientId,
            Roles = new[]
            {
                "GROUP_READ_ONLY",
            },
        });
    
        var @this = Mongodbatlas.GetServiceAccountProjectAssignment.Invoke(new()
        {
            ProjectId = thisServiceAccountProjectAssignment.ProjectId,
            ClientId = thisServiceAccountProjectAssignment.ClientId,
        });
    
        var thisGetServiceAccountProjectAssignments = Mongodbatlas.GetServiceAccountProjectAssignments.Invoke(new()
        {
            OrgId = orgId,
            ClientId = thisServiceAccount.ClientId,
        });
    
        return new Dictionary<string, object?>
        {
            ["serviceAccountProjectRoles"] = @this.Apply(@this => @this.Apply(getServiceAccountProjectAssignmentResult => getServiceAccountProjectAssignmentResult.Roles)),
            ["serviceAccountAssignedProjects"] = thisGetServiceAccountProjectAssignments.Apply(getServiceAccountProjectAssignmentsResult => getServiceAccountProjectAssignmentsResult.Results),
        };
    });
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.mongodbatlas.ServiceAccount;
    import com.pulumi.mongodbatlas.ServiceAccountArgs;
    import com.pulumi.mongodbatlas.ServiceAccountProjectAssignment;
    import com.pulumi.mongodbatlas.ServiceAccountProjectAssignmentArgs;
    import com.pulumi.mongodbatlas.MongodbatlasFunctions;
    import com.pulumi.mongodbatlas.inputs.GetServiceAccountProjectAssignmentArgs;
    import com.pulumi.mongodbatlas.inputs.GetServiceAccountProjectAssignmentsArgs;
    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 thisServiceAccount = new ServiceAccount("thisServiceAccount", ServiceAccountArgs.builder()
                .orgId(orgId)
                .name("example-service-account")
                .description("Example Service Account")
                .roles("ORG_MEMBER")
                .secretExpiresAfterHours(2160)
                .build());
    
            var thisServiceAccountProjectAssignment = new ServiceAccountProjectAssignment("thisServiceAccountProjectAssignment", ServiceAccountProjectAssignmentArgs.builder()
                .projectId(projectId)
                .clientId(thisServiceAccount.clientId())
                .roles("GROUP_READ_ONLY")
                .build());
    
            final var this = MongodbatlasFunctions.getServiceAccountProjectAssignment(GetServiceAccountProjectAssignmentArgs.builder()
                .projectId(thisServiceAccountProjectAssignment.projectId())
                .clientId(thisServiceAccountProjectAssignment.clientId())
                .build());
    
            final var thisGetServiceAccountProjectAssignments = thisServiceAccount.clientId().applyValue(_clientId -> MongodbatlasFunctions.getServiceAccountProjectAssignments(GetServiceAccountProjectAssignmentsArgs.builder()
                .orgId(orgId)
                .clientId(_clientId)
                .build()));
    
            ctx.export("serviceAccountProjectRoles", this_.applyValue(_this_ -> _this_.roles()));
            ctx.export("serviceAccountAssignedProjects", thisGetServiceAccountProjectAssignments.applyValue(_thisGetServiceAccountProjectAssignments -> _thisGetServiceAccountProjectAssignments.results()));
        }
    }
    
    resources:
      thisServiceAccount:
        type: mongodbatlas:ServiceAccount
        name: this
        properties:
          orgId: ${orgId}
          name: example-service-account
          description: Example Service Account
          roles:
            - ORG_MEMBER
          secretExpiresAfterHours: 2160 # 90 days
      thisServiceAccountProjectAssignment:
        type: mongodbatlas:ServiceAccountProjectAssignment
        name: this
        properties:
          projectId: ${projectId}
          clientId: ${thisServiceAccount.clientId}
          roles:
            - GROUP_READ_ONLY
    variables:
      this:
        fn::invoke:
          function: mongodbatlas:getServiceAccountProjectAssignment
          arguments:
            projectId: ${thisServiceAccountProjectAssignment.projectId}
            clientId: ${thisServiceAccountProjectAssignment.clientId}
      thisGetServiceAccountProjectAssignments:
        fn::invoke:
          function: mongodbatlas:getServiceAccountProjectAssignments
          arguments:
            orgId: ${orgId}
            clientId: ${thisServiceAccount.clientId}
    outputs:
      serviceAccountProjectRoles: ${this.roles}
      serviceAccountAssignedProjects: ${thisGetServiceAccountProjectAssignments.results}
    

    Create ServiceAccountProjectAssignment Resource

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

    Constructor syntax

    new ServiceAccountProjectAssignment(name: string, args: ServiceAccountProjectAssignmentArgs, opts?: CustomResourceOptions);
    @overload
    def ServiceAccountProjectAssignment(resource_name: str,
                                        args: ServiceAccountProjectAssignmentArgs,
                                        opts: Optional[ResourceOptions] = None)
    
    @overload
    def ServiceAccountProjectAssignment(resource_name: str,
                                        opts: Optional[ResourceOptions] = None,
                                        client_id: Optional[str] = None,
                                        project_id: Optional[str] = None,
                                        roles: Optional[Sequence[str]] = None)
    func NewServiceAccountProjectAssignment(ctx *Context, name string, args ServiceAccountProjectAssignmentArgs, opts ...ResourceOption) (*ServiceAccountProjectAssignment, error)
    public ServiceAccountProjectAssignment(string name, ServiceAccountProjectAssignmentArgs args, CustomResourceOptions? opts = null)
    public ServiceAccountProjectAssignment(String name, ServiceAccountProjectAssignmentArgs args)
    public ServiceAccountProjectAssignment(String name, ServiceAccountProjectAssignmentArgs args, CustomResourceOptions options)
    
    type: mongodbatlas:ServiceAccountProjectAssignment
    properties: # The arguments to resource properties.
    options: # Bag of options to control resource's behavior.
    
    

    Parameters

    name string
    The unique name of the resource.
    args ServiceAccountProjectAssignmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    resource_name str
    The unique name of the resource.
    args ServiceAccountProjectAssignmentArgs
    The arguments to resource properties.
    opts ResourceOptions
    Bag of options to control resource's behavior.
    ctx Context
    Context object for the current deployment.
    name string
    The unique name of the resource.
    args ServiceAccountProjectAssignmentArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args ServiceAccountProjectAssignmentArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args ServiceAccountProjectAssignmentArgs
    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 serviceAccountProjectAssignmentResource = new Mongodbatlas.ServiceAccountProjectAssignment("serviceAccountProjectAssignmentResource", new()
    {
        ClientId = "string",
        ProjectId = "string",
        Roles = new[]
        {
            "string",
        },
    });
    
    example, err := mongodbatlas.NewServiceAccountProjectAssignment(ctx, "serviceAccountProjectAssignmentResource", &mongodbatlas.ServiceAccountProjectAssignmentArgs{
    	ClientId:  pulumi.String("string"),
    	ProjectId: pulumi.String("string"),
    	Roles: pulumi.StringArray{
    		pulumi.String("string"),
    	},
    })
    
    var serviceAccountProjectAssignmentResource = new ServiceAccountProjectAssignment("serviceAccountProjectAssignmentResource", ServiceAccountProjectAssignmentArgs.builder()
        .clientId("string")
        .projectId("string")
        .roles("string")
        .build());
    
    service_account_project_assignment_resource = mongodbatlas.ServiceAccountProjectAssignment("serviceAccountProjectAssignmentResource",
        client_id="string",
        project_id="string",
        roles=["string"])
    
    const serviceAccountProjectAssignmentResource = new mongodbatlas.ServiceAccountProjectAssignment("serviceAccountProjectAssignmentResource", {
        clientId: "string",
        projectId: "string",
        roles: ["string"],
    });
    
    type: mongodbatlas:ServiceAccountProjectAssignment
    properties:
        clientId: string
        projectId: string
        roles:
            - string
    

    ServiceAccountProjectAssignment 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 ServiceAccountProjectAssignment resource accepts the following input properties:

    ClientId string
    The Client ID of the Service Account.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project.
    Roles List<string>
    The Project permissions for the Service Account in the specified Project.
    ClientId string
    The Client ID of the Service Account.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project.
    Roles []string
    The Project permissions for the Service Account in the specified Project.
    clientId String
    The Client ID of the Service Account.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project.
    roles List<String>
    The Project permissions for the Service Account in the specified Project.
    clientId string
    The Client ID of the Service Account.
    projectId string
    Unique 24-hexadecimal digit string that identifies your project.
    roles string[]
    The Project permissions for the Service Account in the specified Project.
    client_id str
    The Client ID of the Service Account.
    project_id str
    Unique 24-hexadecimal digit string that identifies your project.
    roles Sequence[str]
    The Project permissions for the Service Account in the specified Project.
    clientId String
    The Client ID of the Service Account.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project.
    roles List<String>
    The Project permissions for the Service Account in the specified Project.

    Outputs

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

    Id string
    The provider-assigned unique ID for this managed resource.
    Id string
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.
    id string
    The provider-assigned unique ID for this managed resource.
    id str
    The provider-assigned unique ID for this managed resource.
    id String
    The provider-assigned unique ID for this managed resource.

    Look up Existing ServiceAccountProjectAssignment Resource

    Get an existing ServiceAccountProjectAssignment 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?: ServiceAccountProjectAssignmentState, opts?: CustomResourceOptions): ServiceAccountProjectAssignment
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            client_id: Optional[str] = None,
            project_id: Optional[str] = None,
            roles: Optional[Sequence[str]] = None) -> ServiceAccountProjectAssignment
    func GetServiceAccountProjectAssignment(ctx *Context, name string, id IDInput, state *ServiceAccountProjectAssignmentState, opts ...ResourceOption) (*ServiceAccountProjectAssignment, error)
    public static ServiceAccountProjectAssignment Get(string name, Input<string> id, ServiceAccountProjectAssignmentState? state, CustomResourceOptions? opts = null)
    public static ServiceAccountProjectAssignment get(String name, Output<String> id, ServiceAccountProjectAssignmentState state, CustomResourceOptions options)
    resources:  _:    type: mongodbatlas:ServiceAccountProjectAssignment    get:      id: ${id}
    name
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    The unique provider ID of the resource to lookup.
    name
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    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
    The unique name of the resulting resource.
    id
    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:
    ClientId string
    The Client ID of the Service Account.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project.
    Roles List<string>
    The Project permissions for the Service Account in the specified Project.
    ClientId string
    The Client ID of the Service Account.
    ProjectId string
    Unique 24-hexadecimal digit string that identifies your project.
    Roles []string
    The Project permissions for the Service Account in the specified Project.
    clientId String
    The Client ID of the Service Account.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project.
    roles List<String>
    The Project permissions for the Service Account in the specified Project.
    clientId string
    The Client ID of the Service Account.
    projectId string
    Unique 24-hexadecimal digit string that identifies your project.
    roles string[]
    The Project permissions for the Service Account in the specified Project.
    client_id str
    The Client ID of the Service Account.
    project_id str
    Unique 24-hexadecimal digit string that identifies your project.
    roles Sequence[str]
    The Project permissions for the Service Account in the specified Project.
    clientId String
    The Client ID of the Service Account.
    projectId String
    Unique 24-hexadecimal digit string that identifies your project.
    roles List<String>
    The Project permissions for the Service Account in the specified Project.

    Import

    Import the Service Account Project Assignment resource by using the Project ID and Client ID in the format PROJECT_ID/CLIENT_ID, e.g.

    $ pulumi import mongodbatlas:index/serviceAccountProjectAssignment:ServiceAccountProjectAssignment test 6117ac2fe2a3d04ed27a987v/mdb_sa_id_1234567890abcdef12345678
    

    For more information, see Assign One Service Account to One Project in the MongoDB Atlas API documentation.

    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.
    mongodbatlas logo
    MongoDB Atlas v4.2.0 published on Friday, Jan 23, 2026 by Pulumi
      Meet Neo: Your AI Platform Teammate