# 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
from .. import _utilities, _tables

__all__ = ['ClientServiceAccountRealmRole']


class ClientServiceAccountRealmRole(pulumi.CustomResource):
    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,
                 __name__=None,
                 __opts__=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).
        """
        if __name__ is not None:
            warnings.warn("explicit use of __name__ is deprecated", DeprecationWarning)
            resource_name = __name__
        if __opts__ is not None:
            warnings.warn("explicit use of __opts__ is deprecated, use 'opts' instead", DeprecationWarning)
            opts = __opts__
        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__ = dict()

            if realm_id is None and not opts.urn:
                raise TypeError("Missing required property 'realm_id'")
            __props__['realm_id'] = realm_id
            if role is None and not opts.urn:
                raise TypeError("Missing required property 'role'")
            __props__['role'] = role
            if service_account_user_id is None and not opts.urn:
                raise TypeError("Missing required property 'service_account_user_id'")
            __props__['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__ = dict()

        __props__["realm_id"] = realm_id
        __props__["role"] = role
        __props__["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")

    def translate_output_property(self, prop):
        return _tables.CAMEL_TO_SNAKE_CASE_TABLE.get(prop) or prop

    def translate_input_property(self, prop):
        return _tables.SNAKE_TO_CAMEL_CASE_TABLE.get(prop) or prop

