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

mssql.SqlUser

Explore with Pulumi AI

Manages database-level user, based on SQL login.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as mssql from "@pulumi/mssql";
import * as mssql from "@pulumiverse/mssql";

const exampleDatabase = mssql.getDatabase({
    name: "example",
});
const exampleSqlLogin = new mssql.SqlLogin("exampleSqlLogin", {
    password: "Str0ngPa$$word12",
    mustChangePassword: true,
    defaultDatabaseId: exampleDatabase.then(exampleDatabase => exampleDatabase.id),
    defaultLanguage: "english",
    checkPasswordExpiration: true,
    checkPasswordPolicy: true,
});
const exampleSqlUser = new mssql.SqlUser("exampleSqlUser", {
    databaseId: exampleDatabase.then(exampleDatabase => exampleDatabase.id),
    loginId: exampleSqlLogin.id,
});
export const userId = exampleSqlUser.id;
Copy
import pulumi
import pulumi_mssql as mssql
import pulumiverse_mssql as mssql

example_database = mssql.get_database(name="example")
example_sql_login = mssql.SqlLogin("exampleSqlLogin",
    password="Str0ngPa$$word12",
    must_change_password=True,
    default_database_id=example_database.id,
    default_language="english",
    check_password_expiration=True,
    check_password_policy=True)
example_sql_user = mssql.SqlUser("exampleSqlUser",
    database_id=example_database.id,
    login_id=example_sql_login.id)
pulumi.export("userId", example_sql_user.id)
Copy
package main

import (
	"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
		}
		exampleSqlLogin, err := mssql.NewSqlLogin(ctx, "exampleSqlLogin", &mssql.SqlLoginArgs{
			Password:                pulumi.String("Str0ngPa$$word12"),
			MustChangePassword:      pulumi.Bool(true),
			DefaultDatabaseId:       pulumi.String(exampleDatabase.Id),
			DefaultLanguage:         pulumi.String("english"),
			CheckPasswordExpiration: pulumi.Bool(true),
			CheckPasswordPolicy:     pulumi.Bool(true),
		})
		if err != nil {
			return err
		}
		exampleSqlUser, err := mssql.NewSqlUser(ctx, "exampleSqlUser", &mssql.SqlUserArgs{
			DatabaseId: pulumi.String(exampleDatabase.Id),
			LoginId:    exampleSqlLogin.ID(),
		})
		if err != nil {
			return err
		}
		ctx.Export("userId", exampleSqlUser.ID())
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Mssql = Pulumi.Mssql;
using Mssql = Pulumiverse.Mssql;

return await Deployment.RunAsync(() => 
{
    var exampleDatabase = Mssql.GetDatabase.Invoke(new()
    {
        Name = "example",
    });

    var exampleSqlLogin = new Mssql.SqlLogin("exampleSqlLogin", new()
    {
        Password = "Str0ngPa$$word12",
        MustChangePassword = true,
        DefaultDatabaseId = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.Id),
        DefaultLanguage = "english",
        CheckPasswordExpiration = true,
        CheckPasswordPolicy = true,
    });

    var exampleSqlUser = new Mssql.SqlUser("exampleSqlUser", new()
    {
        DatabaseId = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.Id),
        LoginId = exampleSqlLogin.Id,
    });

    return new Dictionary<string, object?>
    {
        ["userId"] = exampleSqlUser.Id,
    };
});
Copy
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.mssql.SqlLogin;
import com.pulumi.mssql.SqlLoginArgs;
import com.pulumi.mssql.SqlUser;
import com.pulumi.mssql.SqlUserArgs;
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());

        var exampleSqlLogin = new SqlLogin("exampleSqlLogin", SqlLoginArgs.builder()
            .password("Str0ngPa$$word12")
            .mustChangePassword(true)
            .defaultDatabaseId(exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id()))
            .defaultLanguage("english")
            .checkPasswordExpiration(true)
            .checkPasswordPolicy(true)
            .build());

        var exampleSqlUser = new SqlUser("exampleSqlUser", SqlUserArgs.builder()
            .databaseId(exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id()))
            .loginId(exampleSqlLogin.id())
            .build());

        ctx.export("userId", exampleSqlUser.id());
    }
}
Copy
resources:
  exampleSqlLogin:
    type: mssql:SqlLogin
    properties:
      password: Str0ngPa$$word12
      mustChangePassword: true
      defaultDatabaseId: ${exampleDatabase.id}
      defaultLanguage: english
      checkPasswordExpiration: true
      checkPasswordPolicy: true
  exampleSqlUser:
    type: mssql:SqlUser
    properties:
      databaseId: ${exampleDatabase.id}
      loginId: ${exampleSqlLogin.id}
variables:
  exampleDatabase:
    fn::invoke:
      Function: mssql:getDatabase
      Arguments:
        name: example
outputs:
  userId: ${exampleSqlUser.id}
Copy

Create SqlUser Resource

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

Constructor syntax

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

@overload
def SqlUser(resource_name: str,
            opts: Optional[ResourceOptions] = None,
            login_id: Optional[str] = None,
            database_id: Optional[str] = None,
            name: Optional[str] = None)
func NewSqlUser(ctx *Context, name string, args SqlUserArgs, opts ...ResourceOption) (*SqlUser, error)
public SqlUser(string name, SqlUserArgs args, CustomResourceOptions? opts = null)
public SqlUser(String name, SqlUserArgs args)
public SqlUser(String name, SqlUserArgs args, CustomResourceOptions options)
type: mssql:SqlUser
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. SqlUserArgs
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. SqlUserArgs
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. SqlUserArgs
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. SqlUserArgs
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. SqlUserArgs
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 sqlUserResource = new Mssql.SqlUser("sqlUserResource", new()
{
    LoginId = "string",
    DatabaseId = "string",
    Name = "string",
});
Copy
example, err := mssql.NewSqlUser(ctx, "sqlUserResource", &mssql.SqlUserArgs{
	LoginId:    pulumi.String("string"),
	DatabaseId: pulumi.String("string"),
	Name:       pulumi.String("string"),
})
Copy
var sqlUserResource = new SqlUser("sqlUserResource", SqlUserArgs.builder()
    .loginId("string")
    .databaseId("string")
    .name("string")
    .build());
Copy
sql_user_resource = mssql.SqlUser("sqlUserResource",
    login_id="string",
    database_id="string",
    name="string")
Copy
const sqlUserResource = new mssql.SqlUser("sqlUserResource", {
    loginId: "string",
    databaseId: "string",
    name: "string",
});
Copy
type: mssql:SqlUser
properties:
    databaseId: string
    loginId: string
    name: string
Copy

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

LoginId This property is required. string
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
DatabaseId string
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
Name string
User name. Cannot be longer than 128 chars.
LoginId This property is required. string
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
DatabaseId string
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
Name string
User name. Cannot be longer than 128 chars.
loginId This property is required. String
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
databaseId String
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
name String
User name. Cannot be longer than 128 chars.
loginId This property is required. string
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
databaseId string
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
name string
User name. Cannot be longer than 128 chars.
login_id This property is required. str
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
database_id str
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
name str
User name. Cannot be longer than 128 chars.
loginId This property is required. String
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
databaseId String
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
name String
User name. Cannot be longer than 128 chars.

Outputs

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

Get an existing SqlUser 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?: SqlUserState, opts?: CustomResourceOptions): SqlUser
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        database_id: Optional[str] = None,
        login_id: Optional[str] = None,
        name: Optional[str] = None) -> SqlUser
func GetSqlUser(ctx *Context, name string, id IDInput, state *SqlUserState, opts ...ResourceOption) (*SqlUser, error)
public static SqlUser Get(string name, Input<string> id, SqlUserState? state, CustomResourceOptions? opts = null)
public static SqlUser get(String name, Output<String> id, SqlUserState state, CustomResourceOptions options)
resources:  _:    type: mssql:SqlUser    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:
DatabaseId string
ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
LoginId string
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
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>'). Defaults to ID of master.
LoginId string
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
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>'). Defaults to ID of master.
loginId String
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
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>'). Defaults to ID of master.
loginId string
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
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>'). Defaults to ID of master.
login_id str
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_name>').
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>'). Defaults to ID of master.
loginId String
SID of SQL login. Can be retrieved using mssql.SqlLogin or SELECT SUSER_SID('<login_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(), '/', DATABASE_PRINCIPAL_ID('<username>'))

$ pulumi import mssql:index/sqlUser:SqlUser example '7/5'
Copy

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.