# coding=utf-8
# *** WARNING: this file was generated by the Pulumi Terraform Bridge (tfgen) Tool. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import copy
import warnings
import pulumi
import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
from . import _utilities

__all__ = ['DatabasePermissionArgs', 'DatabasePermission']

@pulumi.input_type
class DatabasePermissionArgs:
    def __init__(__self__, *,
                 permission: pulumi.Input[str],
                 principal_id: pulumi.Input[str],
                 with_grant_option: Optional[pulumi.Input[bool]] = None):
        """
        The set of arguments for constructing a DatabasePermission resource.
        :param pulumi.Input[str] permission: Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        :param pulumi.Input[str] principal_id: `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        :param pulumi.Input[bool] with_grant_option: When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        pulumi.set(__self__, "permission", permission)
        pulumi.set(__self__, "principal_id", principal_id)
        if with_grant_option is not None:
            pulumi.set(__self__, "with_grant_option", with_grant_option)

    @property
    @pulumi.getter
    def permission(self) -> pulumi.Input[str]:
        """
        Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        """
        return pulumi.get(self, "permission")

    @permission.setter
    def permission(self, value: pulumi.Input[str]):
        pulumi.set(self, "permission", value)

    @property
    @pulumi.getter(name="principalId")
    def principal_id(self) -> pulumi.Input[str]:
        """
        `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        """
        return pulumi.get(self, "principal_id")

    @principal_id.setter
    def principal_id(self, value: pulumi.Input[str]):
        pulumi.set(self, "principal_id", value)

    @property
    @pulumi.getter(name="withGrantOption")
    def with_grant_option(self) -> Optional[pulumi.Input[bool]]:
        """
        When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        return pulumi.get(self, "with_grant_option")

    @with_grant_option.setter
    def with_grant_option(self, value: Optional[pulumi.Input[bool]]):
        pulumi.set(self, "with_grant_option", value)


@pulumi.input_type
class _DatabasePermissionState:
    def __init__(__self__, *,
                 permission: Optional[pulumi.Input[str]] = None,
                 principal_id: Optional[pulumi.Input[str]] = None,
                 with_grant_option: Optional[pulumi.Input[bool]] = None):
        """
        Input properties used for looking up and filtering DatabasePermission resources.
        :param pulumi.Input[str] permission: Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        :param pulumi.Input[str] principal_id: `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        :param pulumi.Input[bool] with_grant_option: When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        if permission is not None:
            pulumi.set(__self__, "permission", permission)
        if principal_id is not None:
            pulumi.set(__self__, "principal_id", principal_id)
        if with_grant_option is not None:
            pulumi.set(__self__, "with_grant_option", with_grant_option)

    @property
    @pulumi.getter
    def permission(self) -> Optional[pulumi.Input[str]]:
        """
        Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        """
        return pulumi.get(self, "permission")

    @permission.setter
    def permission(self, value: Optional[pulumi.Input[str]]):
        pulumi.set(self, "permission", value)

    @property
    @pulumi.getter(name="principalId")
    def principal_id(self) -> Optional[pulumi.Input[str]]:
        """
        `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        """
        return pulumi.get(self, "principal_id")

    @principal_id.setter
    def principal_id(self, value: Optional[pulumi.Input[str]]):
        pulumi.set(self, "principal_id", value)

    @property
    @pulumi.getter(name="withGrantOption")
    def with_grant_option(self) -> Optional[pulumi.Input[bool]]:
        """
        When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        return pulumi.get(self, "with_grant_option")

    @with_grant_option.setter
    def with_grant_option(self, value: Optional[pulumi.Input[bool]]):
        pulumi.set(self, "with_grant_option", value)


class DatabasePermission(pulumi.CustomResource):
    @overload
    def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 permission: Optional[pulumi.Input[str]] = None,
                 principal_id: Optional[pulumi.Input[str]] = None,
                 with_grant_option: Optional[pulumi.Input[bool]] = None,
                 __props__=None):
        """
        Grants database-level permission.

        ## Example Usage

        ```python
        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

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

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

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[str] permission: Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        :param pulumi.Input[str] principal_id: `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        :param pulumi.Input[bool] with_grant_option: When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        ...
    @overload
    def __init__(__self__,
                 resource_name: str,
                 args: DatabasePermissionArgs,
                 opts: Optional[pulumi.ResourceOptions] = None):
        """
        Grants database-level permission.

        ## Example Usage

        ```python
        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

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

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

        :param str resource_name: The name of the resource.
        :param DatabasePermissionArgs args: The arguments to use to populate this resource's properties.
        :param pulumi.ResourceOptions opts: Options for the resource.
        """
        ...
    def __init__(__self__, resource_name: str, *args, **kwargs):
        resource_args, opts = _utilities.get_resource_args_opts(DatabasePermissionArgs, pulumi.ResourceOptions, *args, **kwargs)
        if resource_args is not None:
            __self__._internal_init(resource_name, opts, **resource_args.__dict__)
        else:
            __self__._internal_init(resource_name, *args, **kwargs)

    def _internal_init(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 permission: Optional[pulumi.Input[str]] = None,
                 principal_id: Optional[pulumi.Input[str]] = None,
                 with_grant_option: Optional[pulumi.Input[bool]] = None,
                 __props__=None):
        opts = pulumi.ResourceOptions.merge(_utilities.get_resource_opts_defaults(), opts)
        if not isinstance(opts, pulumi.ResourceOptions):
            raise TypeError('Expected resource options to be a ResourceOptions instance')
        if opts.id is None:
            if __props__ is not None:
                raise TypeError('__props__ is only valid when passed in combination with a valid opts.id to get an existing resource')
            __props__ = DatabasePermissionArgs.__new__(DatabasePermissionArgs)

            if permission is None and not opts.urn:
                raise TypeError("Missing required property 'permission'")
            __props__.__dict__["permission"] = permission
            if principal_id is None and not opts.urn:
                raise TypeError("Missing required property 'principal_id'")
            __props__.__dict__["principal_id"] = principal_id
            __props__.__dict__["with_grant_option"] = with_grant_option
        super(DatabasePermission, __self__).__init__(
            'mssql:index/databasePermission:DatabasePermission',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name: str,
            id: pulumi.Input[str],
            opts: Optional[pulumi.ResourceOptions] = None,
            permission: Optional[pulumi.Input[str]] = None,
            principal_id: Optional[pulumi.Input[str]] = None,
            with_grant_option: Optional[pulumi.Input[bool]] = None) -> 'DatabasePermission':
        """
        Get an existing DatabasePermission resource's state with the given name, id, and optional extra
        properties used to qualify the lookup.

        :param str resource_name: The unique name of the resulting resource.
        :param pulumi.Input[str] id: The unique provider ID of the resource to lookup.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[str] permission: Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        :param pulumi.Input[str] principal_id: `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        :param pulumi.Input[bool] with_grant_option: When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = _DatabasePermissionState.__new__(_DatabasePermissionState)

        __props__.__dict__["permission"] = permission
        __props__.__dict__["principal_id"] = principal_id
        __props__.__dict__["with_grant_option"] = with_grant_option
        return DatabasePermission(resource_name, opts=opts, __props__=__props__)

    @property
    @pulumi.getter
    def permission(self) -> pulumi.Output[str]:
        """
        Name of database-level SQL permission. For full list of supported permissions, see [docs](https://learn.microsoft.com/en-us/sql/t-sql/statements/grant-database-permissions-transact-sql?view=azuresqldb-current#remarks)
        """
        return pulumi.get(self, "permission")

    @property
    @pulumi.getter(name="principalId")
    def principal_id(self) -> pulumi.Output[str]:
        """
        `<database_id>/<principal_id>`. Can be retrieved using `DatabaseRole`, `SqlUser`, `AzureadUser` or `AzureadServicePrincipal`.
        """
        return pulumi.get(self, "principal_id")

    @property
    @pulumi.getter(name="withGrantOption")
    def with_grant_option(self) -> pulumi.Output[bool]:
        """
        When set to `true`, `principal_id` will be allowed to grant the `permission` to other principals. Defaults to `false`.
        """
        return pulumi.get(self, "with_grant_option")

