# 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__ = ['AzureadUserArgs', 'AzureadUser']

@pulumi.input_type
class AzureadUserArgs:
    def __init__(__self__, *,
                 database_id: pulumi.Input[str],
                 user_object_id: pulumi.Input[str],
                 name: Optional[pulumi.Input[str]] = None):
        """
        The set of arguments for constructing a AzureadUser resource.
        :param pulumi.Input[str] database_id: ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        :param pulumi.Input[str] user_object_id: Azure AD object_id of the user. This can be either regular user or a group.
        :param pulumi.Input[str] name: User name. Cannot be longer than 128 chars.
        """
        pulumi.set(__self__, "database_id", database_id)
        pulumi.set(__self__, "user_object_id", user_object_id)
        if name is not None:
            pulumi.set(__self__, "name", name)

    @property
    @pulumi.getter(name="databaseId")
    def database_id(self) -> pulumi.Input[str]:
        """
        ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        """
        return pulumi.get(self, "database_id")

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

    @property
    @pulumi.getter(name="userObjectId")
    def user_object_id(self) -> pulumi.Input[str]:
        """
        Azure AD object_id of the user. This can be either regular user or a group.
        """
        return pulumi.get(self, "user_object_id")

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

    @property
    @pulumi.getter
    def name(self) -> Optional[pulumi.Input[str]]:
        """
        User name. Cannot be longer than 128 chars.
        """
        return pulumi.get(self, "name")

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


@pulumi.input_type
class _AzureadUserState:
    def __init__(__self__, *,
                 database_id: Optional[pulumi.Input[str]] = None,
                 name: Optional[pulumi.Input[str]] = None,
                 user_object_id: Optional[pulumi.Input[str]] = None):
        """
        Input properties used for looking up and filtering AzureadUser resources.
        :param pulumi.Input[str] database_id: ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        :param pulumi.Input[str] name: User name. Cannot be longer than 128 chars.
        :param pulumi.Input[str] user_object_id: Azure AD object_id of the user. This can be either regular user or a group.
        """
        if database_id is not None:
            pulumi.set(__self__, "database_id", database_id)
        if name is not None:
            pulumi.set(__self__, "name", name)
        if user_object_id is not None:
            pulumi.set(__self__, "user_object_id", user_object_id)

    @property
    @pulumi.getter(name="databaseId")
    def database_id(self) -> Optional[pulumi.Input[str]]:
        """
        ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        """
        return pulumi.get(self, "database_id")

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

    @property
    @pulumi.getter
    def name(self) -> Optional[pulumi.Input[str]]:
        """
        User name. Cannot be longer than 128 chars.
        """
        return pulumi.get(self, "name")

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

    @property
    @pulumi.getter(name="userObjectId")
    def user_object_id(self) -> Optional[pulumi.Input[str]]:
        """
        Azure AD object_id of the user. This can be either regular user or a group.
        """
        return pulumi.get(self, "user_object_id")

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


class AzureadUser(pulumi.CustomResource):
    @overload
    def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 database_id: Optional[pulumi.Input[str]] = None,
                 name: Optional[pulumi.Input[str]] = None,
                 user_object_id: Optional[pulumi.Input[str]] = None,
                 __props__=None):
        """
        Managed database-level user mapped to Azure AD identity (user or group).

        > **Note** When using this resource, Azure SQL server managed identity does not need any [AzureAD role assignments](https://docs.microsoft.com/en-us/azure/azure-sql/database/authentication-aad-service-principal?view=azuresql).

        ## Example Usage

        ```python
        import pulumi
        import pulumi_azuread as azuread
        import pulumi_mssql as mssql
        import pulumiverse_mssql as mssql

        example_database = mssql.get_database(name="example")
        example_user = azuread.get_user(user_principal_name="user@example.com")
        example_azuread_user = mssql.AzureadUser("exampleAzureadUser",
            database_id=example_database.id,
            user_object_id=example_user.object_id)
        pulumi.export("userId", example_azuread_user.id)
        ```

        ## Import

        import using <db_id>/<user_id> - can be retrieved using `SELECT CONCAT(DB_ID(), '/', principal_id) FROM sys.database_principals WHERE [name] = '<username>'`

        ```sh
        $ pulumi import mssql:index/azureadUser:AzureadUser example '7/5'
        ```

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[str] database_id: ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        :param pulumi.Input[str] name: User name. Cannot be longer than 128 chars.
        :param pulumi.Input[str] user_object_id: Azure AD object_id of the user. This can be either regular user or a group.
        """
        ...
    @overload
    def __init__(__self__,
                 resource_name: str,
                 args: AzureadUserArgs,
                 opts: Optional[pulumi.ResourceOptions] = None):
        """
        Managed database-level user mapped to Azure AD identity (user or group).

        > **Note** When using this resource, Azure SQL server managed identity does not need any [AzureAD role assignments](https://docs.microsoft.com/en-us/azure/azure-sql/database/authentication-aad-service-principal?view=azuresql).

        ## Example Usage

        ```python
        import pulumi
        import pulumi_azuread as azuread
        import pulumi_mssql as mssql
        import pulumiverse_mssql as mssql

        example_database = mssql.get_database(name="example")
        example_user = azuread.get_user(user_principal_name="user@example.com")
        example_azuread_user = mssql.AzureadUser("exampleAzureadUser",
            database_id=example_database.id,
            user_object_id=example_user.object_id)
        pulumi.export("userId", example_azuread_user.id)
        ```

        ## Import

        import using <db_id>/<user_id> - can be retrieved using `SELECT CONCAT(DB_ID(), '/', principal_id) FROM sys.database_principals WHERE [name] = '<username>'`

        ```sh
        $ pulumi import mssql:index/azureadUser:AzureadUser example '7/5'
        ```

        :param str resource_name: The name of the resource.
        :param AzureadUserArgs 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(AzureadUserArgs, 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,
                 database_id: Optional[pulumi.Input[str]] = None,
                 name: Optional[pulumi.Input[str]] = None,
                 user_object_id: Optional[pulumi.Input[str]] = 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__ = AzureadUserArgs.__new__(AzureadUserArgs)

            if database_id is None and not opts.urn:
                raise TypeError("Missing required property 'database_id'")
            __props__.__dict__["database_id"] = database_id
            __props__.__dict__["name"] = name
            if user_object_id is None and not opts.urn:
                raise TypeError("Missing required property 'user_object_id'")
            __props__.__dict__["user_object_id"] = user_object_id
        super(AzureadUser, __self__).__init__(
            'mssql:index/azureadUser:AzureadUser',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name: str,
            id: pulumi.Input[str],
            opts: Optional[pulumi.ResourceOptions] = None,
            database_id: Optional[pulumi.Input[str]] = None,
            name: Optional[pulumi.Input[str]] = None,
            user_object_id: Optional[pulumi.Input[str]] = None) -> 'AzureadUser':
        """
        Get an existing AzureadUser 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] database_id: ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        :param pulumi.Input[str] name: User name. Cannot be longer than 128 chars.
        :param pulumi.Input[str] user_object_id: Azure AD object_id of the user. This can be either regular user or a group.
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = _AzureadUserState.__new__(_AzureadUserState)

        __props__.__dict__["database_id"] = database_id
        __props__.__dict__["name"] = name
        __props__.__dict__["user_object_id"] = user_object_id
        return AzureadUser(resource_name, opts=opts, __props__=__props__)

    @property
    @pulumi.getter(name="databaseId")
    def database_id(self) -> pulumi.Output[str]:
        """
        ID of database. Can be retrieved using `Database` or `SELECT DB_ID('<db_name>')`.
        """
        return pulumi.get(self, "database_id")

    @property
    @pulumi.getter
    def name(self) -> pulumi.Output[str]:
        """
        User name. Cannot be longer than 128 chars.
        """
        return pulumi.get(self, "name")

    @property
    @pulumi.getter(name="userObjectId")
    def user_object_id(self) -> pulumi.Output[str]:
        """
        Azure AD object_id of the user. This can be either regular user or a group.
        """
        return pulumi.get(self, "user_object_id")

