mssql.SqlUser
Explore with Pulumi AI
Manages database-level user, based on SQL login.
Example Usage
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,
};
});
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
})
}
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());
}
}
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)
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;
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}
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 string
- The unique name of the resource.
- args SqlUserArgs
- 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 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 string
- The unique name of the resource.
- args SqlUserArgs
- The arguments to resource properties.
- opts ResourceOption
- Bag of options to control resource's behavior.
- name string
- The unique name of the resource.
- args SqlUserArgs
- The arguments to resource properties.
- opts CustomResourceOptions
- Bag of options to control resource's behavior.
- name String
- The unique name of the resource.
- args 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",
});
example, err := mssql.NewSqlUser(ctx, "sqlUserResource", &mssql.SqlUserArgs{
LoginId: pulumi.String("string"),
DatabaseId: pulumi.String("string"),
Name: pulumi.String("string"),
})
var sqlUserResource = new SqlUser("sqlUserResource", SqlUserArgs.builder()
.loginId("string")
.databaseId("string")
.name("string")
.build());
sql_user_resource = mssql.SqlUser("sqlUserResource",
login_id="string",
database_id="string",
name="string")
const sqlUserResource = new mssql.SqlUser("sqlUserResource", {
loginId: "string",
databaseId: "string",
name: "string",
});
type: mssql:SqlUser
properties:
databaseId: string
loginId: string
name: string
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
The SqlUser resource accepts the following input properties:
- Login
Id string - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - Database
Id string - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - Name string
- User name. Cannot be longer than 128 chars.
- Login
Id string - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - Database
Id string - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - Name string
- User name. Cannot be longer than 128 chars.
- login
Id String - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - database
Id String - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - name String
- User name. Cannot be longer than 128 chars.
- login
Id string - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - database
Id string - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - name string
- User name. Cannot be longer than 128 chars.
- login_
id str - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - database_
id str - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - name str
- User name. Cannot be longer than 128 chars.
- login
Id String - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - database
Id String - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - 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)
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.
- Database
Id string - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - Login
Id string - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - Name string
- User name. Cannot be longer than 128 chars.
- Database
Id string - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - Login
Id string - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - Name string
- User name. Cannot be longer than 128 chars.
- database
Id String - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - login
Id String - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - name String
- User name. Cannot be longer than 128 chars.
- database
Id string - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - login
Id string - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT 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
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - login_
id str - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT SUSER_SID('<login_name>')
. - name str
- User name. Cannot be longer than 128 chars.
- database
Id String - ID of database. Can be retrieved using
mssql.Database
orSELECT DB_ID('<db_name>')
. Defaults to ID ofmaster
. - login
Id String - SID of SQL login. Can be retrieved using
mssql.SqlLogin
orSELECT 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'
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.