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

mssql.DatabasePermission

Explore with Pulumi AI

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

    Grants database-level permission.

    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 exampleSqlUser = Mssql.GetSqlUser.Invoke(new()
        {
            Name = "example_user",
            DatabaseId = exampleDatabase.Apply(getDatabaseResult => getDatabaseResult.Id),
        });
    
        var deleteToExample = new Mssql.DatabasePermission("deleteToExample", new()
        {
            PrincipalId = exampleSqlUser.Apply(getSqlUserResult => getSqlUserResult.Id),
            Permission = "DELETE",
        });
    
    });
    
    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
    		}
    		exampleSqlUser, err := mssql.LookupSqlUser(ctx, &mssql.LookupSqlUserArgs{
    			Name:       "example_user",
    			DatabaseId: pulumi.StringRef(exampleDatabase.Id),
    		}, nil)
    		if err != nil {
    			return err
    		}
    		_, err = mssql.NewDatabasePermission(ctx, "deleteToExample", &mssql.DatabasePermissionArgs{
    			PrincipalId: *pulumi.String(exampleSqlUser.Id),
    			Permission:  pulumi.String("DELETE"),
    		})
    		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.DatabasePermission;
    import com.pulumi.mssql.DatabasePermissionArgs;
    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 exampleSqlUser = MssqlFunctions.getSqlUser(GetSqlUserArgs.builder()
                .name("example_user")
                .databaseId(exampleDatabase.applyValue(getDatabaseResult -> getDatabaseResult.id()))
                .build());
    
            var deleteToExample = new DatabasePermission("deleteToExample", DatabasePermissionArgs.builder()        
                .principalId(exampleSqlUser.applyValue(getSqlUserResult -> getSqlUserResult.id()))
                .permission("DELETE")
                .build());
    
        }
    }
    
    import pulumi
    import pulumi_mssql as mssql
    import pulumiverse_mssql as mssql
    
    example_database = mssql.get_database(name="example")
    example_sql_user = mssql.get_sql_user(name="example_user",
        database_id=example_database.id)
    delete_to_example = mssql.DatabasePermission("deleteToExample",
        principal_id=example_sql_user.id,
        permission="DELETE")
    
    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 exampleSqlUser = exampleDatabase.then(exampleDatabase => mssql.getSqlUser({
        name: "example_user",
        databaseId: exampleDatabase.id,
    }));
    const deleteToExample = new mssql.DatabasePermission("deleteToExample", {
        principalId: exampleSqlUser.then(exampleSqlUser => exampleSqlUser.id),
        permission: "DELETE",
    });
    
    resources:
      deleteToExample:
        type: mssql:DatabasePermission
        properties:
          principalId: ${exampleSqlUser.id}
          permission: DELETE
    variables:
      exampleDatabase:
        fn::invoke:
          Function: mssql:getDatabase
          Arguments:
            name: example
      exampleSqlUser:
        fn::invoke:
          Function: mssql:getSqlUser
          Arguments:
            name: example_user
            databaseId: ${exampleDatabase.id}
    

    Create DatabasePermission Resource

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

    Constructor syntax

    new DatabasePermission(name: string, args: DatabasePermissionArgs, opts?: CustomResourceOptions);
    @overload
    def DatabasePermission(resource_name: str,
                           args: DatabasePermissionArgs,
                           opts: Optional[ResourceOptions] = None)
    
    @overload
    def DatabasePermission(resource_name: str,
                           opts: Optional[ResourceOptions] = None,
                           permission: Optional[str] = None,
                           principal_id: Optional[str] = None,
                           with_grant_option: Optional[bool] = None)
    func NewDatabasePermission(ctx *Context, name string, args DatabasePermissionArgs, opts ...ResourceOption) (*DatabasePermission, error)
    public DatabasePermission(string name, DatabasePermissionArgs args, CustomResourceOptions? opts = null)
    public DatabasePermission(String name, DatabasePermissionArgs args)
    public DatabasePermission(String name, DatabasePermissionArgs args, CustomResourceOptions options)
    
    type: mssql:DatabasePermission
    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 DatabasePermissionArgs
    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 DatabasePermissionArgs
    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 DatabasePermissionArgs
    The arguments to resource properties.
    opts ResourceOption
    Bag of options to control resource's behavior.
    name string
    The unique name of the resource.
    args DatabasePermissionArgs
    The arguments to resource properties.
    opts CustomResourceOptions
    Bag of options to control resource's behavior.
    name String
    The unique name of the resource.
    args DatabasePermissionArgs
    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 databasePermissionResource = new Mssql.DatabasePermission("databasePermissionResource", new()
    {
        Permission = "string",
        PrincipalId = "string",
        WithGrantOption = false,
    });
    
    example, err := mssql.NewDatabasePermission(ctx, "databasePermissionResource", &mssql.DatabasePermissionArgs{
    	Permission:      pulumi.String("string"),
    	PrincipalId:     pulumi.String("string"),
    	WithGrantOption: pulumi.Bool(false),
    })
    
    var databasePermissionResource = new DatabasePermission("databasePermissionResource", DatabasePermissionArgs.builder()
        .permission("string")
        .principalId("string")
        .withGrantOption(false)
        .build());
    
    database_permission_resource = mssql.DatabasePermission("databasePermissionResource",
        permission="string",
        principal_id="string",
        with_grant_option=False)
    
    const databasePermissionResource = new mssql.DatabasePermission("databasePermissionResource", {
        permission: "string",
        principalId: "string",
        withGrantOption: false,
    });
    
    type: mssql:DatabasePermission
    properties:
        permission: string
        principalId: string
        withGrantOption: false
    

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

    Permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    WithGrantOption bool
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    Permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    WithGrantOption bool
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission String
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    withGrantOption Boolean
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    withGrantOption boolean
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission str
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principal_id str
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    with_grant_option bool
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission String
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    withGrantOption Boolean
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.

    Outputs

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

    Get an existing DatabasePermission 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?: DatabasePermissionState, opts?: CustomResourceOptions): DatabasePermission
    @staticmethod
    def get(resource_name: str,
            id: str,
            opts: Optional[ResourceOptions] = None,
            permission: Optional[str] = None,
            principal_id: Optional[str] = None,
            with_grant_option: Optional[bool] = None) -> DatabasePermission
    func GetDatabasePermission(ctx *Context, name string, id IDInput, state *DatabasePermissionState, opts ...ResourceOption) (*DatabasePermission, error)
    public static DatabasePermission Get(string name, Input<string> id, DatabasePermissionState? state, CustomResourceOptions? opts = null)
    public static DatabasePermission get(String name, Output<String> id, DatabasePermissionState 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:
    Permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    WithGrantOption bool
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    Permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    WithGrantOption bool
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission String
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    withGrantOption Boolean
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    withGrantOption boolean
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission str
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principal_id str
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    with_grant_option bool
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.
    permission String
    Name of database-level SQL permission. For full list of supported permissions, see docs
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    withGrantOption Boolean
    When set to true, principal_id will be allowed to grant the permission to other principals. Defaults to false.

    Import

    import using <db_id>/<principal_id>/ - can be retrieved using SELECT CONCAT(DB_ID(), '/', DATABASE_PRINCIPAL_ID('<principal_name>'), '/DELETE')

     $ pulumi import mssql:index/databasePermission:DatabasePermission example '7/5/DELETE'
    

    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