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

mssql.getDatabasePermissions

Explore with Pulumi AI

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

    Returns all permissions granted in a DB to given principal

    Example Usage

    import * as pulumi from "@pulumi/pulumi";
    import * as mssql from "@pulumi/mssql";
    
    const exampleDatabase = mssql.getDatabase({
        name: "example",
    });
    const exampleSqlUser = exampleDatabase.then(exampleDatabase => mssql.getSqlUser({
        name: "example_user",
        databaseId: exampleDatabase.id,
    }));
    const exampleDatabasePermissions = exampleSqlUser.then(exampleSqlUser => mssql.getDatabasePermissions({
        principalId: exampleSqlUser.id,
    }));
    export const permissions = exampleDatabasePermissions.then(exampleDatabasePermissions => exampleDatabasePermissions.permissions);
    
    import pulumi
    import pulumi_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)
    example_database_permissions = mssql.get_database_permissions(principal_id=example_sql_user.id)
    pulumi.export("permissions", example_database_permissions.permissions)
    
    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
    		}
    		exampleDatabasePermissions, err := mssql.GetDatabasePermissions(ctx, &mssql.GetDatabasePermissionsArgs{
    			PrincipalId: exampleSqlUser.Id,
    		}, nil)
    		if err != nil {
    			return err
    		}
    		ctx.Export("permissions", exampleDatabasePermissions.Permissions)
    		return nil
    	})
    }
    
    using System.Collections.Generic;
    using System.Linq;
    using Pulumi;
    using Mssql = Pulumi.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 exampleDatabasePermissions = Mssql.GetDatabasePermissions.Invoke(new()
        {
            PrincipalId = exampleSqlUser.Apply(getSqlUserResult => getSqlUserResult.Id),
        });
    
        return new Dictionary<string, object?>
        {
            ["permissions"] = exampleDatabasePermissions.Apply(getDatabasePermissionsResult => getDatabasePermissionsResult.Permissions),
        };
    });
    
    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.inputs.GetDatabasePermissionsArgs;
    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());
    
            final var exampleDatabasePermissions = MssqlFunctions.getDatabasePermissions(GetDatabasePermissionsArgs.builder()
                .principalId(exampleSqlUser.applyValue(getSqlUserResult -> getSqlUserResult.id()))
                .build());
    
            ctx.export("permissions", exampleDatabasePermissions.applyValue(getDatabasePermissionsResult -> getDatabasePermissionsResult.permissions()));
        }
    }
    
    variables:
      exampleDatabase:
        fn::invoke:
          Function: mssql:getDatabase
          Arguments:
            name: example
      exampleSqlUser:
        fn::invoke:
          Function: mssql:getSqlUser
          Arguments:
            name: example_user
            databaseId: ${exampleDatabase.id}
      exampleDatabasePermissions:
        fn::invoke:
          Function: mssql:getDatabasePermissions
          Arguments:
            principalId: ${exampleSqlUser.id}
    outputs:
      permissions: ${exampleDatabasePermissions.permissions}
    

    Using getDatabasePermissions

    Two invocation forms are available. The direct form accepts plain arguments and either blocks until the result value is available, or returns a Promise-wrapped result. The output form accepts Input-wrapped arguments and returns an Output-wrapped result.

    function getDatabasePermissions(args: GetDatabasePermissionsArgs, opts?: InvokeOptions): Promise<GetDatabasePermissionsResult>
    function getDatabasePermissionsOutput(args: GetDatabasePermissionsOutputArgs, opts?: InvokeOptions): Output<GetDatabasePermissionsResult>
    def get_database_permissions(principal_id: Optional[str] = None,
                                 opts: Optional[InvokeOptions] = None) -> GetDatabasePermissionsResult
    def get_database_permissions_output(principal_id: Optional[pulumi.Input[str]] = None,
                                 opts: Optional[InvokeOptions] = None) -> Output[GetDatabasePermissionsResult]
    func GetDatabasePermissions(ctx *Context, args *GetDatabasePermissionsArgs, opts ...InvokeOption) (*GetDatabasePermissionsResult, error)
    func GetDatabasePermissionsOutput(ctx *Context, args *GetDatabasePermissionsOutputArgs, opts ...InvokeOption) GetDatabasePermissionsResultOutput

    > Note: This function is named GetDatabasePermissions in the Go SDK.

    public static class GetDatabasePermissions 
    {
        public static Task<GetDatabasePermissionsResult> InvokeAsync(GetDatabasePermissionsArgs args, InvokeOptions? opts = null)
        public static Output<GetDatabasePermissionsResult> Invoke(GetDatabasePermissionsInvokeArgs args, InvokeOptions? opts = null)
    }
    public static CompletableFuture<GetDatabasePermissionsResult> getDatabasePermissions(GetDatabasePermissionsArgs args, InvokeOptions options)
    // Output-based functions aren't available in Java yet
    
    fn::invoke:
      function: mssql:index/getDatabasePermissions:getDatabasePermissions
      arguments:
        # arguments dictionary

    The following arguments are supported:

    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    principalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    principal_id str
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.

    getDatabasePermissions Result

    The following output properties are available:

    Id string
    <database_id>/<principal_id>.
    Permissions List<Pulumiverse.Mssql.Outputs.GetDatabasePermissionsPermission>
    Set of permissions granted to the principal
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    Id string
    <database_id>/<principal_id>.
    Permissions []GetDatabasePermissionsPermission
    Set of permissions granted to the principal
    PrincipalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    id String
    <database_id>/<principal_id>.
    permissions List<GetDatabasePermissionsPermission>
    Set of permissions granted to the principal
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    id string
    <database_id>/<principal_id>.
    permissions GetDatabasePermissionsPermission[]
    Set of permissions granted to the principal
    principalId string
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    id str
    <database_id>/<principal_id>.
    permissions Sequence[GetDatabasePermissionsPermission]
    Set of permissions granted to the principal
    principal_id str
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.
    id String
    <database_id>/<principal_id>.
    permissions List<Property Map>
    Set of permissions granted to the principal
    principalId String
    <database_id>/<principal_id>. Can be retrieved using mssql.DatabaseRole, mssql.SqlUser, mssql.AzureadUser or mssql.AzureadServicePrincipal.

    Supporting Types

    GetDatabasePermissionsPermission

    Permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    WithGrantOption bool
    When set to true, principal_id will be allowed to grant the permission to other principals.
    Permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    WithGrantOption bool
    When set to true, principal_id will be allowed to grant the permission to other principals.
    permission String
    Name of database-level SQL permission. For full list of supported permissions, see docs
    withGrantOption Boolean
    When set to true, principal_id will be allowed to grant the permission to other principals.
    permission string
    Name of database-level SQL permission. For full list of supported permissions, see docs
    withGrantOption boolean
    When set to true, principal_id will be allowed to grant the permission to other principals.
    permission str
    Name of database-level SQL permission. For full list of supported permissions, see docs
    with_grant_option bool
    When set to true, principal_id will be allowed to grant the permission to other principals.
    permission String
    Name of database-level SQL permission. For full list of supported permissions, see docs
    withGrantOption Boolean
    When set to true, principal_id will be allowed to grant the permission to other principals.

    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