1. Packages
  2. MSSQL
  3. API Docs
  4. AzureadServicePrincipal
Microsoft SQL Server v0.1.0 published on Tuesday, Oct 8, 2024 by pulumiverse

mssql.AzureadServicePrincipal

Explore with Pulumi AI

mssql logo
Microsoft SQL Server v0.1.0 published on Tuesday, Oct 8, 2024 by pulumiverse

    Managed database-level user mapped to Azure AD identity (service principal or managed identity).

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

    Example Usage

    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 exampleServicePrincipal = azuread.getServicePrincipal({
        displayName: "test-application",
    });
    const exampleAzureadServicePrincipal = new mssql.AzureadServicePrincipal("exampleAzureadServicePrincipal", {
        databaseId: exampleDatabase.then(exampleDatabase => exampleDatabase.id),
        clientId: exampleServicePrincipal.then(exampleServicePrincipal => exampleServicePrincipal.applicationId),
    });
    export const userId = exampleAzureadServicePrincipal.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_service_principal = azuread.get_service_principal(display_name="test-application")
    example_azuread_service_principal = mssql.AzureadServicePrincipal("exampleAzureadServicePrincipal",
        database_id=example_database.id,
        client_id=example_service_principal.application_id)
    pulumi.export("userId", example_azuread_service_principal.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
    		}
    		exampleServicePrincipal, err := azuread.LookupServicePrincipal(ctx, &azuread.LookupServicePrincipalArgs{
    			DisplayName: pulumi.StringRef("test-application"),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		exampleAzureadServicePrincipal, err := mssql.NewAzureadServicePrincipal(ctx, "exampleAzureadServicePrincipal", &mssql.AzureadServicePrincipalArgs{
    			DatabaseId: pulumi.String(exampleDatabase.Id),
    			ClientId:   pulumi.String(exampleServicePrincipal.ApplicationId),
    		})
    		if err != nil {
    			return err
    		}
    		ctx.Export("userId", exampleAzureadServicePrincipal.ID())
    		return nil
    	})
    }
    
    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 exampleServicePrincipal = AzureAD.GetServicePrincipal.Invoke(new()
        {
            DisplayName = "test-application",
        });
    
        var exampleAzureadServicePrincipal = new Mssql.AzureadServicePrincipal("exampleAzureadServicePrincipal", new()
        {
            DatabaseId = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.Id),
            ClientId = exampleServicePrincipal.Apply(getServicePrincipalResult => getServicePrincipalResult.ApplicationId),
        });
    
        return new Dictionary<string, object?>
        {
            ["userId"] = exampleAzureadServicePrincipal.Id,
        };
    });
    
    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.GetServicePrincipalArgs;
    import com.pulumi.mssql.AzureadServicePrincipal;
    import com.pulumi.mssql.AzureadServicePrincipalArgs;
    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 exampleServicePrincipal = AzureadFunctions.getServicePrincipal(GetServicePrincipalArgs.builder()
                .displayName("test-application")
                .build());
    
            var exampleAzureadServicePrincipal = new AzureadServicePrincipal("exampleAzureadServicePrincipal", AzureadServicePrincipalArgs.builder()
                .databaseId(exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id()))
                .clientId(exampleServicePrincipal.applyValue(getServicePrincipalResult -> getServicePrincipalResult.applicationId()))
                .build());
    
            ctx.export("userId", exampleAzureadServicePrincipal.id());
        }
    }
    
    resources:
      exampleAzureadServicePrincipal:
        type: mssql:AzureadServicePrincipal
        properties:
          databaseId: ${exampleDatabase.id}
          clientId: ${exampleServicePrincipal.applicationId}
    variables:
      exampleDatabase:
        fn::invoke:
          Function: mssql:getDatabase
          Arguments:
            name: example
      exampleServicePrincipal:
        fn::invoke:
          Function: azuread:getServicePrincipal
          Arguments:
            displayName: test-application
    outputs:
      userId: ${exampleAzureadServicePrincipal.id}
    

    Create AzureadServicePrincipal Resource

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

    Constructor syntax

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

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

    ClientId string
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    ClientId string
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    clientId String
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    clientId string
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    client_id str
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    clientId String
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.

    Outputs

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

    Get an existing AzureadServicePrincipal 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?: AzureadServicePrincipalState, opts?: CustomResourceOptions): AzureadServicePrincipal
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            client_id: Optional[str] = None,
            database_id: Optional[str] = None,
            name: Optional[str] = None) -> AzureadServicePrincipal
    func GetAzureadServicePrincipal(ctx *Context, name string, id IDInput, state *AzureadServicePrincipalState, opts ...ResourceOption) (*AzureadServicePrincipal, error)
    public static AzureadServicePrincipal Get(string name, Input<string> id, AzureadServicePrincipalState? state, CustomResourceOptions? opts = null)
    public static AzureadServicePrincipal get(String name, Output<String> id, AzureadServicePrincipalState 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:
    ClientId string
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    ClientId string
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    clientId String
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    clientId string
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    client_id str
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.
    clientId String
    Azure AD client_id of the Service Principal. This can be either regular Service Principal or Managed Service Identity.
    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.

    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/azureadServicePrincipal:AzureadServicePrincipal 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.1.0 published on Tuesday, Oct 8, 2024 by pulumiverse