# 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 warnings
import pulumi
import pulumi.runtime
from typing import Any, Mapping, Optional, Sequence, Union, overload
from .. import _utilities

__all__ = ['ClientServiceAccountRealmRoleArgs', 'ClientServiceAccountRealmRole']

@pulumi.input_type
class ClientServiceAccountRealmRoleArgs:
    def __init__(__self__, *,
                 realm_id: pulumi.Input[str],
                 role: pulumi.Input[str],
                 service_account_user_id: pulumi.Input[str]):
        """
        The set of arguments for constructing a ClientServiceAccountRealmRole resource.
        :param pulumi.Input[str] realm_id: The realm that the client and role belong to.
        :param pulumi.Input[str] role: The name of the role that is assigned.
        :param pulumi.Input[str] service_account_user_id: The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        pulumi.set(__self__, "realm_id", realm_id)
        pulumi.set(__self__, "role", role)
        pulumi.set(__self__, "service_account_user_id", service_account_user_id)

    @property
    @pulumi.getter(name="realmId")
    def realm_id(self) -> pulumi.Input[str]:
        """
        The realm that the client and role belong to.
        """
        return pulumi.get(self, "realm_id")

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

    @property
    @pulumi.getter
    def role(self) -> pulumi.Input[str]:
        """
        The name of the role that is assigned.
        """
        return pulumi.get(self, "role")

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

    @property
    @pulumi.getter(name="serviceAccountUserId")
    def service_account_user_id(self) -> pulumi.Input[str]:
        """
        The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        return pulumi.get(self, "service_account_user_id")

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


@pulumi.input_type
class _ClientServiceAccountRealmRoleState:
    def __init__(__self__, *,
                 realm_id: Optional[pulumi.Input[str]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 service_account_user_id: Optional[pulumi.Input[str]] = None):
        """
        Input properties used for looking up and filtering ClientServiceAccountRealmRole resources.
        :param pulumi.Input[str] realm_id: The realm that the client and role belong to.
        :param pulumi.Input[str] role: The name of the role that is assigned.
        :param pulumi.Input[str] service_account_user_id: The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        if realm_id is not None:
            pulumi.set(__self__, "realm_id", realm_id)
        if role is not None:
            pulumi.set(__self__, "role", role)
        if service_account_user_id is not None:
            pulumi.set(__self__, "service_account_user_id", service_account_user_id)

    @property
    @pulumi.getter(name="realmId")
    def realm_id(self) -> Optional[pulumi.Input[str]]:
        """
        The realm that the client and role belong to.
        """
        return pulumi.get(self, "realm_id")

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

    @property
    @pulumi.getter
    def role(self) -> Optional[pulumi.Input[str]]:
        """
        The name of the role that is assigned.
        """
        return pulumi.get(self, "role")

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

    @property
    @pulumi.getter(name="serviceAccountUserId")
    def service_account_user_id(self) -> Optional[pulumi.Input[str]]:
        """
        The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        return pulumi.get(self, "service_account_user_id")

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


class ClientServiceAccountRealmRole(pulumi.CustomResource):
    @overload
    def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 realm_id: Optional[pulumi.Input[str]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 service_account_user_id: Optional[pulumi.Input[str]] = None,
                 __props__=None):
        """
        Allows for assigning realm roles to the service account of an openid client.
        You need to set `service_accounts_enabled` to `true` for the openid client that should be assigned the role.

        If you'd like to attach client roles to a service account, please use the `openid.ClientServiceAccountRole`
        resource.

        ## Example Usage

        ```python
        import pulumi
        import pulumi_keycloak as keycloak

        realm = keycloak.Realm("realm",
            realm="my-realm",
            enabled=True)
        realm_role = keycloak.Role("realmRole", realm_id=realm.id)
        client = keycloak.openid.Client("client",
            realm_id=realm.id,
            service_accounts_enabled=True)
        client_service_account_role = keycloak.openid.ClientServiceAccountRealmRole("clientServiceAccountRole",
            realm_id=realm.id,
            service_account_user_id=client.service_account_user_id,
            role=realm_role.name)
        ```

        ## Import

        This resource can be imported using the format `{{realmId}}/{{serviceAccountUserId}}/{{roleId}}`. Examplebash

        ```sh
         $ pulumi import keycloak:openid/clientServiceAccountRealmRole:ClientServiceAccountRealmRole client_service_account_role my-realm/489ba513-1ceb-49ba-ae0b-1ab1f5099ebf/c7230ab7-8e4e-4135-995d-e81b50696ad8
        ```

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[str] realm_id: The realm that the client and role belong to.
        :param pulumi.Input[str] role: The name of the role that is assigned.
        :param pulumi.Input[str] service_account_user_id: The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        ...
    @overload
    def __init__(__self__,
                 resource_name: str,
                 args: ClientServiceAccountRealmRoleArgs,
                 opts: Optional[pulumi.ResourceOptions] = None):
        """
        Allows for assigning realm roles to the service account of an openid client.
        You need to set `service_accounts_enabled` to `true` for the openid client that should be assigned the role.

        If you'd like to attach client roles to a service account, please use the `openid.ClientServiceAccountRole`
        resource.

        ## Example Usage

        ```python
        import pulumi
        import pulumi_keycloak as keycloak

        realm = keycloak.Realm("realm",
            realm="my-realm",
            enabled=True)
        realm_role = keycloak.Role("realmRole", realm_id=realm.id)
        client = keycloak.openid.Client("client",
            realm_id=realm.id,
            service_accounts_enabled=True)
        client_service_account_role = keycloak.openid.ClientServiceAccountRealmRole("clientServiceAccountRole",
            realm_id=realm.id,
            service_account_user_id=client.service_account_user_id,
            role=realm_role.name)
        ```

        ## Import

        This resource can be imported using the format `{{realmId}}/{{serviceAccountUserId}}/{{roleId}}`. Examplebash

        ```sh
         $ pulumi import keycloak:openid/clientServiceAccountRealmRole:ClientServiceAccountRealmRole client_service_account_role my-realm/489ba513-1ceb-49ba-ae0b-1ab1f5099ebf/c7230ab7-8e4e-4135-995d-e81b50696ad8
        ```

        :param str resource_name: The name of the resource.
        :param ClientServiceAccountRealmRoleArgs 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(ClientServiceAccountRealmRoleArgs, 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,
                 realm_id: Optional[pulumi.Input[str]] = None,
                 role: Optional[pulumi.Input[str]] = None,
                 service_account_user_id: Optional[pulumi.Input[str]] = None,
                 __props__=None):
        if opts is None:
            opts = pulumi.ResourceOptions()
        if not isinstance(opts, pulumi.ResourceOptions):
            raise TypeError('Expected resource options to be a ResourceOptions instance')
        if opts.version is None:
            opts.version = _utilities.get_version()
        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__ = ClientServiceAccountRealmRoleArgs.__new__(ClientServiceAccountRealmRoleArgs)

            if realm_id is None and not opts.urn:
                raise TypeError("Missing required property 'realm_id'")
            __props__.__dict__["realm_id"] = realm_id
            if role is None and not opts.urn:
                raise TypeError("Missing required property 'role'")
            __props__.__dict__["role"] = role
            if service_account_user_id is None and not opts.urn:
                raise TypeError("Missing required property 'service_account_user_id'")
            __props__.__dict__["service_account_user_id"] = service_account_user_id
        super(ClientServiceAccountRealmRole, __self__).__init__(
            'keycloak:openid/clientServiceAccountRealmRole:ClientServiceAccountRealmRole',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name: str,
            id: pulumi.Input[str],
            opts: Optional[pulumi.ResourceOptions] = None,
            realm_id: Optional[pulumi.Input[str]] = None,
            role: Optional[pulumi.Input[str]] = None,
            service_account_user_id: Optional[pulumi.Input[str]] = None) -> 'ClientServiceAccountRealmRole':
        """
        Get an existing ClientServiceAccountRealmRole 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] realm_id: The realm that the client and role belong to.
        :param pulumi.Input[str] role: The name of the role that is assigned.
        :param pulumi.Input[str] service_account_user_id: The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = _ClientServiceAccountRealmRoleState.__new__(_ClientServiceAccountRealmRoleState)

        __props__.__dict__["realm_id"] = realm_id
        __props__.__dict__["role"] = role
        __props__.__dict__["service_account_user_id"] = service_account_user_id
        return ClientServiceAccountRealmRole(resource_name, opts=opts, __props__=__props__)

    @property
    @pulumi.getter(name="realmId")
    def realm_id(self) -> pulumi.Output[str]:
        """
        The realm that the client and role belong to.
        """
        return pulumi.get(self, "realm_id")

    @property
    @pulumi.getter
    def role(self) -> pulumi.Output[str]:
        """
        The name of the role that is assigned.
        """
        return pulumi.get(self, "role")

    @property
    @pulumi.getter(name="serviceAccountUserId")
    def service_account_user_id(self) -> pulumi.Output[str]:
        """
        The id of the service account that is assigned the role (the service account of the client that "consumes" the role).
        """
        return pulumi.get(self, "service_account_user_id")

