# coding=utf-8
# *** WARNING: this file was generated by pulumi-language-python. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import builtins as _builtins
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__ = ['ReadReplicaArgs', 'ReadReplica']

@pulumi.input_type
class ReadReplicaArgs:
    def __init__(__self__, *,
                 instance_id: pulumi.Input[_builtins.str],
                 direct_access: Optional[pulumi.Input['ReadReplicaDirectAccessArgs']] = None,
                 private_network: Optional[pulumi.Input['ReadReplicaPrivateNetworkArgs']] = None,
                 region: Optional[pulumi.Input[_builtins.str]] = None,
                 same_zone: Optional[pulumi.Input[_builtins.bool]] = None):
        """
        The set of arguments for constructing a ReadReplica resource.
        :param pulumi.Input[_builtins.str] instance_id: UUID of the rdb instance.
               
               > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        :param pulumi.Input['ReadReplicaDirectAccessArgs'] direct_access: Creates a direct access endpoint to rdb replica.
        :param pulumi.Input['ReadReplicaPrivateNetworkArgs'] private_network: Create an endpoint in a Private Netork.
        :param pulumi.Input[_builtins.str] region: `region`) The region
               in which the Read Replica should be created.
        :param pulumi.Input[_builtins.bool] same_zone: Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        pulumi.set(__self__, "instance_id", instance_id)
        if direct_access is not None:
            pulumi.set(__self__, "direct_access", direct_access)
        if private_network is not None:
            pulumi.set(__self__, "private_network", private_network)
        if region is not None:
            pulumi.set(__self__, "region", region)
        if same_zone is not None:
            pulumi.set(__self__, "same_zone", same_zone)

    @_builtins.property
    @pulumi.getter(name="instanceId")
    def instance_id(self) -> pulumi.Input[_builtins.str]:
        """
        UUID of the rdb instance.

        > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        """
        return pulumi.get(self, "instance_id")

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

    @_builtins.property
    @pulumi.getter(name="directAccess")
    def direct_access(self) -> Optional[pulumi.Input['ReadReplicaDirectAccessArgs']]:
        """
        Creates a direct access endpoint to rdb replica.
        """
        return pulumi.get(self, "direct_access")

    @direct_access.setter
    def direct_access(self, value: Optional[pulumi.Input['ReadReplicaDirectAccessArgs']]):
        pulumi.set(self, "direct_access", value)

    @_builtins.property
    @pulumi.getter(name="privateNetwork")
    def private_network(self) -> Optional[pulumi.Input['ReadReplicaPrivateNetworkArgs']]:
        """
        Create an endpoint in a Private Netork.
        """
        return pulumi.get(self, "private_network")

    @private_network.setter
    def private_network(self, value: Optional[pulumi.Input['ReadReplicaPrivateNetworkArgs']]):
        pulumi.set(self, "private_network", value)

    @_builtins.property
    @pulumi.getter
    def region(self) -> Optional[pulumi.Input[_builtins.str]]:
        """
        `region`) The region
        in which the Read Replica should be created.
        """
        return pulumi.get(self, "region")

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

    @_builtins.property
    @pulumi.getter(name="sameZone")
    def same_zone(self) -> Optional[pulumi.Input[_builtins.bool]]:
        """
        Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        return pulumi.get(self, "same_zone")

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


@pulumi.input_type
class _ReadReplicaState:
    def __init__(__self__, *,
                 direct_access: Optional[pulumi.Input['ReadReplicaDirectAccessArgs']] = None,
                 instance_id: Optional[pulumi.Input[_builtins.str]] = None,
                 private_network: Optional[pulumi.Input['ReadReplicaPrivateNetworkArgs']] = None,
                 region: Optional[pulumi.Input[_builtins.str]] = None,
                 same_zone: Optional[pulumi.Input[_builtins.bool]] = None):
        """
        Input properties used for looking up and filtering ReadReplica resources.
        :param pulumi.Input['ReadReplicaDirectAccessArgs'] direct_access: Creates a direct access endpoint to rdb replica.
        :param pulumi.Input[_builtins.str] instance_id: UUID of the rdb instance.
               
               > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        :param pulumi.Input['ReadReplicaPrivateNetworkArgs'] private_network: Create an endpoint in a Private Netork.
        :param pulumi.Input[_builtins.str] region: `region`) The region
               in which the Read Replica should be created.
        :param pulumi.Input[_builtins.bool] same_zone: Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        if direct_access is not None:
            pulumi.set(__self__, "direct_access", direct_access)
        if instance_id is not None:
            pulumi.set(__self__, "instance_id", instance_id)
        if private_network is not None:
            pulumi.set(__self__, "private_network", private_network)
        if region is not None:
            pulumi.set(__self__, "region", region)
        if same_zone is not None:
            pulumi.set(__self__, "same_zone", same_zone)

    @_builtins.property
    @pulumi.getter(name="directAccess")
    def direct_access(self) -> Optional[pulumi.Input['ReadReplicaDirectAccessArgs']]:
        """
        Creates a direct access endpoint to rdb replica.
        """
        return pulumi.get(self, "direct_access")

    @direct_access.setter
    def direct_access(self, value: Optional[pulumi.Input['ReadReplicaDirectAccessArgs']]):
        pulumi.set(self, "direct_access", value)

    @_builtins.property
    @pulumi.getter(name="instanceId")
    def instance_id(self) -> Optional[pulumi.Input[_builtins.str]]:
        """
        UUID of the rdb instance.

        > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        """
        return pulumi.get(self, "instance_id")

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

    @_builtins.property
    @pulumi.getter(name="privateNetwork")
    def private_network(self) -> Optional[pulumi.Input['ReadReplicaPrivateNetworkArgs']]:
        """
        Create an endpoint in a Private Netork.
        """
        return pulumi.get(self, "private_network")

    @private_network.setter
    def private_network(self, value: Optional[pulumi.Input['ReadReplicaPrivateNetworkArgs']]):
        pulumi.set(self, "private_network", value)

    @_builtins.property
    @pulumi.getter
    def region(self) -> Optional[pulumi.Input[_builtins.str]]:
        """
        `region`) The region
        in which the Read Replica should be created.
        """
        return pulumi.get(self, "region")

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

    @_builtins.property
    @pulumi.getter(name="sameZone")
    def same_zone(self) -> Optional[pulumi.Input[_builtins.bool]]:
        """
        Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        return pulumi.get(self, "same_zone")

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


@pulumi.type_token("scaleway:databases/readReplica:ReadReplica")
class ReadReplica(pulumi.CustomResource):
    @overload
    def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 direct_access: Optional[pulumi.Input[Union['ReadReplicaDirectAccessArgs', 'ReadReplicaDirectAccessArgsDict']]] = None,
                 instance_id: Optional[pulumi.Input[_builtins.str]] = None,
                 private_network: Optional[pulumi.Input[Union['ReadReplicaPrivateNetworkArgs', 'ReadReplicaPrivateNetworkArgsDict']]] = None,
                 region: Optional[pulumi.Input[_builtins.str]] = None,
                 same_zone: Optional[pulumi.Input[_builtins.bool]] = None,
                 __props__=None):
        """
        Creates and manages Read Replicas.
        For more information refer to the [API documentation](https://www.scaleway.com/en/developers/api/managed-database-postgre-mysql/).

        ## Example Usage

        ### Basic

        ```python
        import pulumi
        import pulumiverse_scaleway as scaleway

        instance = scaleway.databases.Instance("instance",
            name="test-rdb-rr-update",
            node_type="db-dev-s",
            engine="PostgreSQL-14",
            is_ha_cluster=False,
            disable_backup=True,
            user_name="my_initial_user",
            password="thiZ_is_v&ry_s3cret",
            tags=[
                "terraform-test",
                "scaleway_rdb_read_replica",
                "minimal",
            ])
        replica = scaleway.databases.ReadReplica("replica",
            instance_id=instance.id,
            direct_access={})
        ```

        ### Private network with static endpoint

        ```python
        import pulumi
        import pulumiverse_scaleway as scaleway

        instance = scaleway.databases.Instance("instance",
            name="rdb_instance",
            node_type="db-dev-s",
            engine="PostgreSQL-14",
            is_ha_cluster=False,
            disable_backup=True,
            user_name="my_initial_user",
            password="thiZ_is_v&ry_s3cret")
        pn = scaleway.network.PrivateNetwork("pn")
        replica = scaleway.databases.ReadReplica("replica",
            instance_id=instance.id,
            private_network={
                "private_network_id": pn.id,
                "service_ip": "192.168.1.254/24",
            })
        ```

        ### Private network with IPAM

        ```python
        import pulumi
        import pulumiverse_scaleway as scaleway

        instance = scaleway.databases.Instance("instance",
            name="rdb_instance",
            node_type="db-dev-s",
            engine="PostgreSQL-14",
            is_ha_cluster=False,
            disable_backup=True,
            user_name="my_initial_user",
            password="thiZ_is_v&ry_s3cret")
        pn = scaleway.network.PrivateNetwork("pn")
        replica = scaleway.databases.ReadReplica("replica",
            instance_id=instance.id,
            private_network={
                "private_network_id": pn.id,
                "enable_ipam": True,
            })
        ```

        ## Import

        Read Replicas can be imported using the `{region}/{id}`, e.g.

        bash

        ```sh
        $ pulumi import scaleway:databases/readReplica:ReadReplica rr fr-par/11111111-1111-1111-1111-111111111111
        ```

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[Union['ReadReplicaDirectAccessArgs', 'ReadReplicaDirectAccessArgsDict']] direct_access: Creates a direct access endpoint to rdb replica.
        :param pulumi.Input[_builtins.str] instance_id: UUID of the rdb instance.
               
               > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        :param pulumi.Input[Union['ReadReplicaPrivateNetworkArgs', 'ReadReplicaPrivateNetworkArgsDict']] private_network: Create an endpoint in a Private Netork.
        :param pulumi.Input[_builtins.str] region: `region`) The region
               in which the Read Replica should be created.
        :param pulumi.Input[_builtins.bool] same_zone: Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        ...
    @overload
    def __init__(__self__,
                 resource_name: str,
                 args: ReadReplicaArgs,
                 opts: Optional[pulumi.ResourceOptions] = None):
        """
        Creates and manages Read Replicas.
        For more information refer to the [API documentation](https://www.scaleway.com/en/developers/api/managed-database-postgre-mysql/).

        ## Example Usage

        ### Basic

        ```python
        import pulumi
        import pulumiverse_scaleway as scaleway

        instance = scaleway.databases.Instance("instance",
            name="test-rdb-rr-update",
            node_type="db-dev-s",
            engine="PostgreSQL-14",
            is_ha_cluster=False,
            disable_backup=True,
            user_name="my_initial_user",
            password="thiZ_is_v&ry_s3cret",
            tags=[
                "terraform-test",
                "scaleway_rdb_read_replica",
                "minimal",
            ])
        replica = scaleway.databases.ReadReplica("replica",
            instance_id=instance.id,
            direct_access={})
        ```

        ### Private network with static endpoint

        ```python
        import pulumi
        import pulumiverse_scaleway as scaleway

        instance = scaleway.databases.Instance("instance",
            name="rdb_instance",
            node_type="db-dev-s",
            engine="PostgreSQL-14",
            is_ha_cluster=False,
            disable_backup=True,
            user_name="my_initial_user",
            password="thiZ_is_v&ry_s3cret")
        pn = scaleway.network.PrivateNetwork("pn")
        replica = scaleway.databases.ReadReplica("replica",
            instance_id=instance.id,
            private_network={
                "private_network_id": pn.id,
                "service_ip": "192.168.1.254/24",
            })
        ```

        ### Private network with IPAM

        ```python
        import pulumi
        import pulumiverse_scaleway as scaleway

        instance = scaleway.databases.Instance("instance",
            name="rdb_instance",
            node_type="db-dev-s",
            engine="PostgreSQL-14",
            is_ha_cluster=False,
            disable_backup=True,
            user_name="my_initial_user",
            password="thiZ_is_v&ry_s3cret")
        pn = scaleway.network.PrivateNetwork("pn")
        replica = scaleway.databases.ReadReplica("replica",
            instance_id=instance.id,
            private_network={
                "private_network_id": pn.id,
                "enable_ipam": True,
            })
        ```

        ## Import

        Read Replicas can be imported using the `{region}/{id}`, e.g.

        bash

        ```sh
        $ pulumi import scaleway:databases/readReplica:ReadReplica rr fr-par/11111111-1111-1111-1111-111111111111
        ```

        :param str resource_name: The name of the resource.
        :param ReadReplicaArgs 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(ReadReplicaArgs, 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,
                 direct_access: Optional[pulumi.Input[Union['ReadReplicaDirectAccessArgs', 'ReadReplicaDirectAccessArgsDict']]] = None,
                 instance_id: Optional[pulumi.Input[_builtins.str]] = None,
                 private_network: Optional[pulumi.Input[Union['ReadReplicaPrivateNetworkArgs', 'ReadReplicaPrivateNetworkArgsDict']]] = None,
                 region: Optional[pulumi.Input[_builtins.str]] = None,
                 same_zone: Optional[pulumi.Input[_builtins.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__ = ReadReplicaArgs.__new__(ReadReplicaArgs)

            __props__.__dict__["direct_access"] = direct_access
            if instance_id is None and not opts.urn:
                raise TypeError("Missing required property 'instance_id'")
            __props__.__dict__["instance_id"] = instance_id
            __props__.__dict__["private_network"] = private_network
            __props__.__dict__["region"] = region
            __props__.__dict__["same_zone"] = same_zone
        alias_opts = pulumi.ResourceOptions(aliases=[pulumi.Alias(type_="scaleway:index/databaseReadReplica:DatabaseReadReplica")])
        opts = pulumi.ResourceOptions.merge(opts, alias_opts)
        super(ReadReplica, __self__).__init__(
            'scaleway:databases/readReplica:ReadReplica',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name: str,
            id: pulumi.Input[str],
            opts: Optional[pulumi.ResourceOptions] = None,
            direct_access: Optional[pulumi.Input[Union['ReadReplicaDirectAccessArgs', 'ReadReplicaDirectAccessArgsDict']]] = None,
            instance_id: Optional[pulumi.Input[_builtins.str]] = None,
            private_network: Optional[pulumi.Input[Union['ReadReplicaPrivateNetworkArgs', 'ReadReplicaPrivateNetworkArgsDict']]] = None,
            region: Optional[pulumi.Input[_builtins.str]] = None,
            same_zone: Optional[pulumi.Input[_builtins.bool]] = None) -> 'ReadReplica':
        """
        Get an existing ReadReplica 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[Union['ReadReplicaDirectAccessArgs', 'ReadReplicaDirectAccessArgsDict']] direct_access: Creates a direct access endpoint to rdb replica.
        :param pulumi.Input[_builtins.str] instance_id: UUID of the rdb instance.
               
               > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        :param pulumi.Input[Union['ReadReplicaPrivateNetworkArgs', 'ReadReplicaPrivateNetworkArgsDict']] private_network: Create an endpoint in a Private Netork.
        :param pulumi.Input[_builtins.str] region: `region`) The region
               in which the Read Replica should be created.
        :param pulumi.Input[_builtins.bool] same_zone: Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = _ReadReplicaState.__new__(_ReadReplicaState)

        __props__.__dict__["direct_access"] = direct_access
        __props__.__dict__["instance_id"] = instance_id
        __props__.__dict__["private_network"] = private_network
        __props__.__dict__["region"] = region
        __props__.__dict__["same_zone"] = same_zone
        return ReadReplica(resource_name, opts=opts, __props__=__props__)

    @_builtins.property
    @pulumi.getter(name="directAccess")
    def direct_access(self) -> pulumi.Output[Optional['outputs.ReadReplicaDirectAccess']]:
        """
        Creates a direct access endpoint to rdb replica.
        """
        return pulumi.get(self, "direct_access")

    @_builtins.property
    @pulumi.getter(name="instanceId")
    def instance_id(self) -> pulumi.Output[_builtins.str]:
        """
        UUID of the rdb instance.

        > **Important:** The replica musts contains at least one `direct_access` or `private_network`. It can contain both.
        """
        return pulumi.get(self, "instance_id")

    @_builtins.property
    @pulumi.getter(name="privateNetwork")
    def private_network(self) -> pulumi.Output[Optional['outputs.ReadReplicaPrivateNetwork']]:
        """
        Create an endpoint in a Private Netork.
        """
        return pulumi.get(self, "private_network")

    @_builtins.property
    @pulumi.getter
    def region(self) -> pulumi.Output[Optional[_builtins.str]]:
        """
        `region`) The region
        in which the Read Replica should be created.
        """
        return pulumi.get(self, "region")

    @_builtins.property
    @pulumi.getter(name="sameZone")
    def same_zone(self) -> pulumi.Output[Optional[_builtins.bool]]:
        """
        Defines whether to create the replica in the same availability zone as the main instance nodes or not.
        """
        return pulumi.get(self, "same_zone")

