1. Packages
  2. MSSQL
  3. API Docs
  4. AzureadUser
Microsoft SQL Server v0.0.8 published on Wednesday, Nov 1, 2023 by pulumiverse

mssql.AzureadUser

Explore with Pulumi AI

mssql logo
Microsoft SQL Server v0.0.8 published on Wednesday, Nov 1, 2023 by pulumiverse

    Managed database-level user mapped to Azure AD identity (user or group).

    Note When using this resource, Azure SQL server managed identity does not need any AzureAD role assignments.

    Example Usage

    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using AzureAD = Pulumi.AzureAD;
    using Mssql = Pulumi.Mssql;
    using Mssql = Pulumiverse.Mssql;
    
    return await Deployment.RunAsync(() => 
    {
        var exampleDatabase = Mssql.GetDatabase.Invoke(new()
        {
            Name = "example",
        });
    
        var exampleUser = AzureAD.GetUser.Invoke(new()
        {
            UserPrincipalName = "user@example.com",
        });
    
        var exampleAzureadUser = new Mssql.AzureadUser("exampleAzureadUser", new()
        {
            DatabaseId = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.Id),
            UserObjectId = exampleUser.Apply(getUserResult => getUserResult.ObjectId),
        });
    
        return new Dictionary<string, object?>
        {
            ["userId"] = exampleAzureadUser.Id,
        };
    });
    
    package main
    
    import (
    	"github.com/pulumi/pulumi-azuread/sdk/v5/go/azuread"
    	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
    	"github.com/pulumiverse/pulumi-mssql/sdk/go/mssql"
    )
    
    func main() {
    	pulumi.Run(func(ctx *pulumi.Context) error {
    		exampleDatabase, err := mssql.LookupDatabase(ctx, &mssql.LookupDatabaseArgs{
    			Name: "example",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		exampleUser, err := azuread.LookupUser(ctx, &azuread.LookupUserArgs{
    			UserPrincipalName: pulumi.StringRef("user@example.com"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		exampleAzureadUser, err := mssql.NewAzureadUser(ctx, "exampleAzureadUser", &mssql.AzureadUserArgs{
    			DatabaseId:   *pulumi.String(exampleDatabase.Id),
    			UserObjectId: *pulumi.String(exampleUser.ObjectId),
    		})
    		if err != nil {
    			return err
    		}
    		ctx.Export("userId", exampleAzureadUser.ID())
    		return nil
    	})
    }
    
    package generated_program;
    
    import com.pulumi.Context;
    import com.pulumi.Pulumi;
    import com.pulumi.core.Output;
    import com.pulumi.mssql.MssqlFunctions;
    import com.pulumi.mssql.inputs.GetDatabaseArgs;
    import com.pulumi.azuread.AzureadFunctions;
    import com.pulumi.azuread.inputs.GetUserArgs;
    import com.pulumi.mssql.AzureadUser;
    import com.pulumi.mssql.AzureadUserArgs;
    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) {
            final var exampleDatabase = MssqlFunctions.getDatabase(GetDatabaseArgs.builder()
                .name("example")
                .build());
    
            final var exampleUser = AzureadFunctions.getUser(GetUserArgs.builder()
                .userPrincipalName("user@example.com")
                .build());
    
            var exampleAzureadUser = new AzureadUser("exampleAzureadUser", AzureadUserArgs.builder()        
                .databaseId(exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id()))
                .userObjectId(exampleUser.applyValue(getUserResult -> getUserResult.objectId()))
                .build());
    
            ctx.export("userId", exampleAzureadUser.id());
        }
    }
    
    import pulumi
    import pulumi_azuread as azuread
    import pulumi_mssql as mssql
    import pulumiverse_mssql as mssql
    
    example_database = mssql.get_database(name="example")
    example_user = azuread.get_user(user_principal_name="user@example.com")
    example_azuread_user = mssql.AzureadUser("exampleAzureadUser",
        database_id=example_database.id,
        user_object_id=example_user.object_id)
    pulumi.export("userId", example_azuread_user.id)
    
    import * as pulumi from "@pulumi/pulumi";
    import * as azuread from "@pulumi/azuread";
    import * as mssql from "@pulumi/mssql";
    import * as mssql from "@pulumiverse/mssql";
    
    const exampleDatabase = mssql.getDatabase({
        name: "example",
    });
    const exampleUser = azuread.getUser({
        userPrincipalName: "user@example.com",
    });
    const exampleAzureadUser = new mssql.AzureadUser("exampleAzureadUser", {
        databaseId: exampleDatabase.then(exampleDatabase => exampleDatabase.id),
        userObjectId: exampleUser.then(exampleUser => exampleUser.objectId),
    });
    export const userId = exampleAzureadUser.id;
    
    resources:
      exampleAzureadUser:
        type: mssql:AzureadUser
        properties:
          databaseId: ${exampleDatabase.id}
          userObjectId: ${exampleUser.objectId}
    variables:
      exampleDatabase:
        fn::invoke:
          Function: mssql:getDatabase
          Arguments:
            name: example
      exampleUser:
        fn::invoke:
          Function: azuread:getUser
          Arguments:
            userPrincipalName: user@example.com
    outputs:
      userId: ${exampleAzureadUser.id}
    

    Create AzureadUser Resource

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

    Constructor syntax

    new AzureadUser(name: string, args: AzureadUserArgs, opts?: CustomResourceOptions);
    @overload
    def AzureadUser(resource_name: str,
                    args: AzureadUserArgs,
                    opts: Optional[ResourceOptions] = None)
    
    @overload
    def AzureadUser(resource_name: str,
                    opts: Optional[ResourceOptions] = None,
                    database_id: Optional[str] = None,
                    user_object_id: Optional[str] = None,
                    name: Optional[str] = None)
    func NewAzureadUser(ctx *Context, name string, args AzureadUserArgs, opts ...ResourceOption) (*AzureadUser, error)
    public AzureadUser(string name, AzureadUserArgs args, CustomResourceOptions? opts = null)
    public AzureadUser(String name, AzureadUserArgs args)
    public AzureadUser(String name, AzureadUserArgs args, CustomResourceOptions options)
    
    type: mssql:AzureadUser
    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 AzureadUserArgs
    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 AzureadUserArgs
    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 AzureadUserArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args AzureadUserArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args AzureadUserArgs
    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 azureadUserResource = new Mssql.AzureadUser("azureadUserResource", new()
    {
        DatabaseId = "string",
        UserObjectId = "string",
        Name = "string",
    });
    
    example, err := mssql.NewAzureadUser(ctx, "azureadUserResource", &mssql.AzureadUserArgs{
    	DatabaseId:   pulumi.String("string"),
    	UserObjectId: pulumi.String("string"),
    	Name:         pulumi.String("string"),
    })
    
    var azureadUserResource = new AzureadUser("azureadUserResource", AzureadUserArgs.builder()
        .databaseId("string")
        .userObjectId("string")
        .name("string")
        .build());
    
    azuread_user_resource = mssql.AzureadUser("azureadUserResource",
        database_id="string",
        user_object_id="string",
        name="string")
    
    const azureadUserResource = new mssql.AzureadUser("azureadUserResource", {
        databaseId: "string",
        userObjectId: "string",
        name: "string",
    });
    
    type: mssql:AzureadUser
    properties:
        databaseId: string
        name: string
        userObjectId: string
    

    AzureadUser Resource Properties

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

    Inputs

    The AzureadUser resource accepts the following input properties:

    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    UserObjectId string
    Azure AD object_id of the user. This can be either regular user or a group.
    Name string
    User name. Cannot be longer than 128 chars.
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    UserObjectId string
    Azure AD object_id of the user. This can be either regular user or a group.
    Name string
    User name. Cannot be longer than 128 chars.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    userObjectId String
    Azure AD object_id of the user. This can be either regular user or a group.
    name String
    User name. Cannot be longer than 128 chars.
    databaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    userObjectId string
    Azure AD object_id of the user. This can be either regular user or a group.
    name string
    User name. Cannot be longer than 128 chars.
    database_id str
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    user_object_id str
    Azure AD object_id of the user. This can be either regular user or a group.
    name str
    User name. Cannot be longer than 128 chars.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    userObjectId String
    Azure AD object_id of the user. This can be either regular user or a group.
    name String
    User name. Cannot be longer than 128 chars.

    Outputs

    All input properties are implicitly available as output properties. Additionally, the AzureadUser 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 AzureadUser Resource

    Get an existing AzureadUser 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?: AzureadUserState, opts?: CustomResourceOptions): AzureadUser
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            database_id: Optional[str] = None,
            name: Optional[str] = None,
            user_object_id: Optional[str] = None) -> AzureadUser
    func GetAzureadUser(ctx *Context, name string, id IDInput, state *AzureadUserState, opts ...ResourceOption) (*AzureadUser, error)
    public static AzureadUser Get(string name, Input<string> id, AzureadUserState? state, CustomResourceOptions? opts = null)
    public static AzureadUser get(String name, Output<String> id, AzureadUserState state, CustomResourceOptions options)
    Resource lookup is not supported in YAML
    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:
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    Name string
    User name. Cannot be longer than 128 chars.
    UserObjectId string
    Azure AD object_id of the user. This can be either regular user or a group.
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    Name string
    User name. Cannot be longer than 128 chars.
    UserObjectId string
    Azure AD object_id of the user. This can be either regular user or a group.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    name String
    User name. Cannot be longer than 128 chars.
    userObjectId String
    Azure AD object_id of the user. This can be either regular user or a group.
    databaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    name string
    User name. Cannot be longer than 128 chars.
    userObjectId string
    Azure AD object_id of the user. This can be either regular user or a group.
    database_id str
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    name str
    User name. Cannot be longer than 128 chars.
    user_object_id str
    Azure AD object_id of the user. This can be either regular user or a group.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>').
    name String
    User name. Cannot be longer than 128 chars.
    userObjectId String
    Azure AD object_id of the user. This can be either regular user or a group.

    Import

    import using <db_id>/<user_id> - can be retrieved using SELECT CONCAT(DB_ID(), '/', principal_id) FROM sys.database_principals WHERE [name] = '<username>'

     $ pulumi import mssql:index/azureadUser:AzureadUser example '7/5'
    

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

    Package Details

    Repository
    mssql pulumiverse/pulumi-mssql
    License
    Apache-2.0
    Notes
    This Pulumi package is based on the mssql Terraform Provider.
    mssql logo
    Microsoft SQL Server v0.0.8 published on Wednesday, Nov 1, 2023 by pulumiverse