# 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 sys
import pulumi
import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
if sys.version_info >= (3, 11):
    from typing import NotRequired, TypedDict, TypeAlias
else:
    from typing_extensions import NotRequired, TypedDict, TypeAlias
from . import _utilities
from . import outputs
from ._inputs import *

__all__ = ['ClickhouseGrantArgs', 'ClickhouseGrant']

@pulumi.input_type
class ClickhouseGrantArgs:
    def __init__(__self__, *,
                 project: pulumi.Input[str],
                 service_name: pulumi.Input[str],
                 privilege_grants: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 role_grants: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]]] = None,
                 user: Optional[pulumi.Input[str]] = None):
        """
        The set of arguments for constructing a ClickhouseGrant resource.
        :param pulumi.Input[str] project: The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] service_name: The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]] privilege_grants: Grant privileges. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] role: The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]] role_grants: Grant roles. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] user: The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        pulumi.set(__self__, "project", project)
        pulumi.set(__self__, "service_name", service_name)
        if privilege_grants is not None:
            pulumi.set(__self__, "privilege_grants", privilege_grants)
        if role is not None:
            pulumi.set(__self__, "role", role)
        if role_grants is not None:
            pulumi.set(__self__, "role_grants", role_grants)
        if user is not None:
            pulumi.set(__self__, "user", user)

    @property
    @pulumi.getter
    def project(self) -> pulumi.Input[str]:
        """
        The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "project")

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

    @property
    @pulumi.getter(name="serviceName")
    def service_name(self) -> pulumi.Input[str]:
        """
        The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "service_name")

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

    @property
    @pulumi.getter(name="privilegeGrants")
    def privilege_grants(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]]]:
        """
        Grant privileges. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "privilege_grants")

    @privilege_grants.setter
    def privilege_grants(self, value: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]]]):
        pulumi.set(self, "privilege_grants", value)

    @property
    @pulumi.getter
    def role(self) -> Optional[pulumi.Input[str]]:
        """
        The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "role")

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

    @property
    @pulumi.getter(name="roleGrants")
    def role_grants(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]]]:
        """
        Grant roles. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "role_grants")

    @role_grants.setter
    def role_grants(self, value: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]]]):
        pulumi.set(self, "role_grants", value)

    @property
    @pulumi.getter
    def user(self) -> Optional[pulumi.Input[str]]:
        """
        The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "user")

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


@pulumi.input_type
class _ClickhouseGrantState:
    def __init__(__self__, *,
                 privilege_grants: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]]] = None,
                 project: Optional[pulumi.Input[str]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 role_grants: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]]] = None,
                 service_name: Optional[pulumi.Input[str]] = None,
                 user: Optional[pulumi.Input[str]] = None):
        """
        Input properties used for looking up and filtering ClickhouseGrant resources.
        :param pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]] privilege_grants: Grant privileges. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] project: The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] role: The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]] role_grants: Grant roles. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] service_name: The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] user: The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        if privilege_grants is not None:
            pulumi.set(__self__, "privilege_grants", privilege_grants)
        if project is not None:
            pulumi.set(__self__, "project", project)
        if role is not None:
            pulumi.set(__self__, "role", role)
        if role_grants is not None:
            pulumi.set(__self__, "role_grants", role_grants)
        if service_name is not None:
            pulumi.set(__self__, "service_name", service_name)
        if user is not None:
            pulumi.set(__self__, "user", user)

    @property
    @pulumi.getter(name="privilegeGrants")
    def privilege_grants(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]]]:
        """
        Grant privileges. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "privilege_grants")

    @privilege_grants.setter
    def privilege_grants(self, value: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantPrivilegeGrantArgs']]]]):
        pulumi.set(self, "privilege_grants", value)

    @property
    @pulumi.getter
    def project(self) -> Optional[pulumi.Input[str]]:
        """
        The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "project")

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

    @property
    @pulumi.getter
    def role(self) -> Optional[pulumi.Input[str]]:
        """
        The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "role")

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

    @property
    @pulumi.getter(name="roleGrants")
    def role_grants(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]]]:
        """
        Grant roles. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "role_grants")

    @role_grants.setter
    def role_grants(self, value: Optional[pulumi.Input[Sequence[pulumi.Input['ClickhouseGrantRoleGrantArgs']]]]):
        pulumi.set(self, "role_grants", value)

    @property
    @pulumi.getter(name="serviceName")
    def service_name(self) -> Optional[pulumi.Input[str]]:
        """
        The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "service_name")

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

    @property
    @pulumi.getter
    def user(self) -> Optional[pulumi.Input[str]]:
        """
        The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "user")

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


class ClickhouseGrant(pulumi.CustomResource):
    @overload
    def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 privilege_grants: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantPrivilegeGrantArgs', 'ClickhouseGrantPrivilegeGrantArgsDict']]]]] = None,
                 project: Optional[pulumi.Input[str]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 role_grants: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantRoleGrantArgs', 'ClickhouseGrantRoleGrantArgsDict']]]]] = None,
                 service_name: Optional[pulumi.Input[str]] = None,
                 user: Optional[pulumi.Input[str]] = None,
                 __props__=None):
        """
        Creates and manages ClickHouse grants to give users and roles privileges to a ClickHouse service.

        **Note:**
        * Users cannot have the same name as roles.
        * To grant a privilege on all tables of a database, omit the table and only keep the database. Don't use `table="*"`.
        * Changes first revoke all grants and then reissue the remaining grants for convergence.

        ## Example Usage

        ```python
        import pulumi
        import pulumi_aiven as aiven

        example_role = aiven.ClickhouseRole("example_role",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            role="example-role")
        # Grant privileges to the example role.
        role_privileges = aiven.ClickhouseGrant("role_privileges",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            role=example_role.role,
            privilege_grants=[
                {
                    "privilege": "INSERT",
                    "database": example_db["name"],
                    "table": "example-table",
                },
                {
                    "privilege": "SELECT",
                    "database": example_db["name"],
                },
            ])
        # Grant the role to the user.
        example_user = aiven.ClickhouseUser("example_user",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            username="example-user")
        user_role_assignment = aiven.ClickhouseGrant("user_role_assignment",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            user=example_user.username,
            role_grants=[{
                "role": example_role.role,
            }])
        ```

        ## Import

        ```sh
        $ pulumi import aiven:index/clickhouseGrant:ClickhouseGrant example_grant PROJECT/SERVICE_NAME/ID
        ```

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantPrivilegeGrantArgs', 'ClickhouseGrantPrivilegeGrantArgsDict']]]] privilege_grants: Grant privileges. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] project: The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] role: The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantRoleGrantArgs', 'ClickhouseGrantRoleGrantArgsDict']]]] role_grants: Grant roles. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] service_name: The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] user: The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        ...
    @overload
    def __init__(__self__,
                 resource_name: str,
                 args: ClickhouseGrantArgs,
                 opts: Optional[pulumi.ResourceOptions] = None):
        """
        Creates and manages ClickHouse grants to give users and roles privileges to a ClickHouse service.

        **Note:**
        * Users cannot have the same name as roles.
        * To grant a privilege on all tables of a database, omit the table and only keep the database. Don't use `table="*"`.
        * Changes first revoke all grants and then reissue the remaining grants for convergence.

        ## Example Usage

        ```python
        import pulumi
        import pulumi_aiven as aiven

        example_role = aiven.ClickhouseRole("example_role",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            role="example-role")
        # Grant privileges to the example role.
        role_privileges = aiven.ClickhouseGrant("role_privileges",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            role=example_role.role,
            privilege_grants=[
                {
                    "privilege": "INSERT",
                    "database": example_db["name"],
                    "table": "example-table",
                },
                {
                    "privilege": "SELECT",
                    "database": example_db["name"],
                },
            ])
        # Grant the role to the user.
        example_user = aiven.ClickhouseUser("example_user",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            username="example-user")
        user_role_assignment = aiven.ClickhouseGrant("user_role_assignment",
            project=example_project["project"],
            service_name=example_clickhouse["serviceName"],
            user=example_user.username,
            role_grants=[{
                "role": example_role.role,
            }])
        ```

        ## Import

        ```sh
        $ pulumi import aiven:index/clickhouseGrant:ClickhouseGrant example_grant PROJECT/SERVICE_NAME/ID
        ```

        :param str resource_name: The name of the resource.
        :param ClickhouseGrantArgs 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(ClickhouseGrantArgs, 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,
                 privilege_grants: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantPrivilegeGrantArgs', 'ClickhouseGrantPrivilegeGrantArgsDict']]]]] = None,
                 project: Optional[pulumi.Input[str]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 role_grants: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantRoleGrantArgs', 'ClickhouseGrantRoleGrantArgsDict']]]]] = None,
                 service_name: Optional[pulumi.Input[str]] = None,
                 user: 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__ = ClickhouseGrantArgs.__new__(ClickhouseGrantArgs)

            __props__.__dict__["privilege_grants"] = privilege_grants
            if project is None and not opts.urn:
                raise TypeError("Missing required property 'project'")
            __props__.__dict__["project"] = project
            __props__.__dict__["role"] = role
            __props__.__dict__["role_grants"] = role_grants
            if service_name is None and not opts.urn:
                raise TypeError("Missing required property 'service_name'")
            __props__.__dict__["service_name"] = service_name
            __props__.__dict__["user"] = user
        super(ClickhouseGrant, __self__).__init__(
            'aiven:index/clickhouseGrant:ClickhouseGrant',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name: str,
            id: pulumi.Input[str],
            opts: Optional[pulumi.ResourceOptions] = None,
            privilege_grants: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantPrivilegeGrantArgs', 'ClickhouseGrantPrivilegeGrantArgsDict']]]]] = None,
            project: Optional[pulumi.Input[str]] = None,
            role: Optional[pulumi.Input[str]] = None,
            role_grants: Optional[pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantRoleGrantArgs', 'ClickhouseGrantRoleGrantArgsDict']]]]] = None,
            service_name: Optional[pulumi.Input[str]] = None,
            user: Optional[pulumi.Input[str]] = None) -> 'ClickhouseGrant':
        """
        Get an existing ClickhouseGrant 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[Sequence[pulumi.Input[Union['ClickhouseGrantPrivilegeGrantArgs', 'ClickhouseGrantPrivilegeGrantArgsDict']]]] privilege_grants: Grant privileges. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] project: The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] role: The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[Sequence[pulumi.Input[Union['ClickhouseGrantRoleGrantArgs', 'ClickhouseGrantRoleGrantArgsDict']]]] role_grants: Grant roles. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] service_name: The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        :param pulumi.Input[str] user: The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = _ClickhouseGrantState.__new__(_ClickhouseGrantState)

        __props__.__dict__["privilege_grants"] = privilege_grants
        __props__.__dict__["project"] = project
        __props__.__dict__["role"] = role
        __props__.__dict__["role_grants"] = role_grants
        __props__.__dict__["service_name"] = service_name
        __props__.__dict__["user"] = user
        return ClickhouseGrant(resource_name, opts=opts, __props__=__props__)

    @property
    @pulumi.getter(name="privilegeGrants")
    def privilege_grants(self) -> pulumi.Output[Optional[Sequence['outputs.ClickhouseGrantPrivilegeGrant']]]:
        """
        Grant privileges. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "privilege_grants")

    @property
    @pulumi.getter
    def project(self) -> pulumi.Output[str]:
        """
        The name of the project this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "project")

    @property
    @pulumi.getter
    def role(self) -> pulumi.Output[Optional[str]]:
        """
        The role to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "role")

    @property
    @pulumi.getter(name="roleGrants")
    def role_grants(self) -> pulumi.Output[Optional[Sequence['outputs.ClickhouseGrantRoleGrant']]]:
        """
        Grant roles. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "role_grants")

    @property
    @pulumi.getter(name="serviceName")
    def service_name(self) -> pulumi.Output[str]:
        """
        The name of the service that this resource belongs to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "service_name")

    @property
    @pulumi.getter
    def user(self) -> pulumi.Output[Optional[str]]:
        """
        The user to grant privileges or roles to. To set up proper dependencies please refer to this variable as a reference. Changing this property forces recreation of the resource.
        """
        return pulumi.get(self, "user")

