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

mssql.DatabaseRole

Explore with Pulumi AI

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

    Manages database-level role.

    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 owner = Mssql.GetSqlUser.Invoke(new()
        {
            Name = "example_user",
        });
    
        var exampleDatabaseRole = new Mssql.DatabaseRole("exampleDatabaseRole", new()
        {
            DatabaseId = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.Id),
            OwnerId = owner.Apply(getSqlUserResult => getSqlUserResult.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
    		}
    		owner, err := mssql.LookupSqlUser(ctx, &mssql.LookupSqlUserArgs{
    			Name: "example_user",
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = mssql.NewDatabaseRole(ctx, "exampleDatabaseRole", &mssql.DatabaseRoleArgs{
    			DatabaseId: *pulumi.String(exampleDatabase.Id),
    			OwnerId:    *pulumi.String(owner.Id),
    		})
    		if err != nil {
    			return err
    		}
    		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.inputs.GetSqlUserArgs;
    import com.pulumi.mssql.DatabaseRole;
    import com.pulumi.mssql.DatabaseRoleArgs;
    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 owner = MssqlFunctions.getSqlUser(GetSqlUserArgs.builder()
                .name("example_user")
                .build());
    
            var exampleDatabaseRole = new DatabaseRole("exampleDatabaseRole", DatabaseRoleArgs.builder()        
                .databaseId(exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id()))
                .ownerId(owner.applyValue(getSqlUserResult -> getSqlUserResult.id()))
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_mssql as mssql
    import pulumiverse_mssql as mssql
    
    example_database = mssql.get_database(name="example")
    owner = mssql.get_sql_user(name="example_user")
    example_database_role = mssql.DatabaseRole("exampleDatabaseRole",
        database_id=example_database.id,
        owner_id=owner.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 owner = mssql.getSqlUser({
        name: "example_user",
    });
    const exampleDatabaseRole = new mssql.DatabaseRole("exampleDatabaseRole", {
        databaseId: exampleDatabase.then(exampleDatabase => exampleDatabase.id),
        ownerId: owner.then(owner => owner.id),
    });
    
    resources:
      exampleDatabaseRole:
        type: mssql:DatabaseRole
        properties:
          databaseId: ${exampleDatabase.id}
          ownerId: ${owner.id}
    variables:
      exampleDatabase:
        fn::invoke:
          Function: mssql:getDatabase
          Arguments:
            name: example
      owner:
        fn::invoke:
          Function: mssql:getSqlUser
          Arguments:
            name: example_user
    

    Create DatabaseRole Resource

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

    Constructor syntax

    new DatabaseRole(name: string, args?: DatabaseRoleArgs, opts?: CustomResourceOptions);
    @overload
    def DatabaseRole(resource_name: str,
                     args: Optional[DatabaseRoleArgs] = None,
                     opts: Optional[ResourceOptions] = None)
    
    @overload
    def DatabaseRole(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     database_id: Optional[str] = None,
                     name: Optional[str] = None,
                     owner_id: Optional[str] = None)
    func NewDatabaseRole(ctx *Context, name string, args *DatabaseRoleArgs, opts ...ResourceOption) (*DatabaseRole, error)
    public DatabaseRole(string name, DatabaseRoleArgs? args = null, CustomResourceOptions? opts = null)
    public DatabaseRole(String name, DatabaseRoleArgs args)
    public DatabaseRole(String name, DatabaseRoleArgs args, CustomResourceOptions options)
    
    type: mssql:DatabaseRole
    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 DatabaseRoleArgs
    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 DatabaseRoleArgs
    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 DatabaseRoleArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args DatabaseRoleArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args DatabaseRoleArgs
    The arguments to resource properties.
    options CustomResourceOptions
    Bag of options to control resource's behavior.

    Example

    The following reference example uses placeholder values for all input properties.

    var databaseRoleResource = new Mssql.DatabaseRole("databaseRoleResource", new()
    {
        DatabaseId = "string",
        Name = "string",
        OwnerId = "string",
    });
    
    example, err := mssql.NewDatabaseRole(ctx, "databaseRoleResource", &mssql.DatabaseRoleArgs{
    	DatabaseId: pulumi.String("string"),
    	Name:       pulumi.String("string"),
    	OwnerId:    pulumi.String("string"),
    })
    
    var databaseRoleResource = new DatabaseRole("databaseRoleResource", DatabaseRoleArgs.builder()
        .databaseId("string")
        .name("string")
        .ownerId("string")
        .build());
    
    database_role_resource = mssql.DatabaseRole("databaseRoleResource",
        database_id="string",
        name="string",
        owner_id="string")
    
    const databaseRoleResource = new mssql.DatabaseRole("databaseRoleResource", {
        databaseId: "string",
        name: "string",
        ownerId: "string",
    });
    
    type: mssql:DatabaseRole
    properties:
        databaseId: string
        name: string
        ownerId: string
    

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

    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    Name string
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    OwnerId string
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    Name string
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    OwnerId string
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    name String
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    ownerId String
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    databaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    name string
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    ownerId string
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    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
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    owner_id str
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    name String
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    ownerId String
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.

    Outputs

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

    Get an existing DatabaseRole 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?: DatabaseRoleState, opts?: CustomResourceOptions): DatabaseRole
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            database_id: Optional[str] = None,
            name: Optional[str] = None,
            owner_id: Optional[str] = None) -> DatabaseRole
    func GetDatabaseRole(ctx *Context, name string, id IDInput, state *DatabaseRoleState, opts ...ResourceOption) (*DatabaseRole, error)
    public static DatabaseRole Get(string name, Input<string> id, DatabaseRoleState? state, CustomResourceOptions? opts = null)
    public static DatabaseRole get(String name, Output<String> id, DatabaseRoleState 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>'). Defaults to ID of master.
    Name string
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    OwnerId string
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    DatabaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    Name string
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    OwnerId string
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    name String
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    ownerId String
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    databaseId string
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    name string
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    ownerId string
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    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
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    owner_id str
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.
    databaseId String
    ID of database. Can be retrieved using mssql.Database or SELECT DB_ID('<db_name>'). Defaults to ID of master.
    name String
    Role name. Must follow Regular Identifiers rules and cannot be longer than 128 chars.
    ownerId String
    ID of another database role or user owning this role. Can be retrieved using mssql_database_role or mssql_sql_user. Defaults to ID of current user, used to authorize the Terraform provider.

    Import

    import using <db_id>/<role_id> - can be retrieved using SELECT CONCAT(DB_ID(), '/', DATABASE_PRINCIPAL_ID('<role_name>'))

     $ pulumi import mssql:index/databaseRole:DatabaseRole 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