# 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__ = ['DatabaseFirewallArgs', 'DatabaseFirewall']

@pulumi.input_type
class DatabaseFirewallArgs:
    def __init__(__self__, *,
                 cluster_id: pulumi.Input[_builtins.str],
                 rules: pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]]):
        """
        The set of arguments for constructing a DatabaseFirewall resource.
        :param pulumi.Input[_builtins.str] cluster_id: The ID of the target database cluster.
        :param pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]] rules: A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        pulumi.set(__self__, "cluster_id", cluster_id)
        pulumi.set(__self__, "rules", rules)

    @_builtins.property
    @pulumi.getter(name="clusterId")
    def cluster_id(self) -> pulumi.Input[_builtins.str]:
        """
        The ID of the target database cluster.
        """
        return pulumi.get(self, "cluster_id")

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

    @_builtins.property
    @pulumi.getter
    def rules(self) -> pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]]:
        """
        A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        return pulumi.get(self, "rules")

    @rules.setter
    def rules(self, value: pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]]):
        pulumi.set(self, "rules", value)


@pulumi.input_type
class _DatabaseFirewallState:
    def __init__(__self__, *,
                 cluster_id: Optional[pulumi.Input[_builtins.str]] = None,
                 rules: Optional[pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]]] = None):
        """
        Input properties used for looking up and filtering DatabaseFirewall resources.
        :param pulumi.Input[_builtins.str] cluster_id: The ID of the target database cluster.
        :param pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]] rules: A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        if cluster_id is not None:
            pulumi.set(__self__, "cluster_id", cluster_id)
        if rules is not None:
            pulumi.set(__self__, "rules", rules)

    @_builtins.property
    @pulumi.getter(name="clusterId")
    def cluster_id(self) -> Optional[pulumi.Input[_builtins.str]]:
        """
        The ID of the target database cluster.
        """
        return pulumi.get(self, "cluster_id")

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

    @_builtins.property
    @pulumi.getter
    def rules(self) -> Optional[pulumi.Input[Sequence[pulumi.Input['DatabaseFirewallRuleArgs']]]]:
        """
        A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        return pulumi.get(self, "rules")

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


@pulumi.type_token("digitalocean:index/databaseFirewall:DatabaseFirewall")
class DatabaseFirewall(pulumi.CustomResource):
    @overload
    def __init__(__self__,
                 resource_name: str,
                 opts: Optional[pulumi.ResourceOptions] = None,
                 cluster_id: Optional[pulumi.Input[_builtins.str]] = None,
                 rules: Optional[pulumi.Input[Sequence[pulumi.Input[Union['DatabaseFirewallRuleArgs', 'DatabaseFirewallRuleArgsDict']]]]] = None,
                 __props__=None):
        """
        Provides a DigitalOcean database firewall resource allowing you to restrict
        connections to your database to trusted sources. You may limit connections to
        specific Droplets, Kubernetes clusters, or IP addresses.

        ## Example Usage

        ### Create a new database firewall allowing multiple IP addresses

        ```python
        import pulumi
        import pulumi_digitalocean as digitalocean

        postgres_example = digitalocean.DatabaseCluster("postgres-example",
            name="example-postgres-cluster",
            engine="pg",
            version="15",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1,
            node_count=1)
        example_fw = digitalocean.DatabaseFirewall("example-fw",
            cluster_id=postgres_example.id,
            rules=[
                {
                    "type": "ip_addr",
                    "value": "192.168.1.1",
                },
                {
                    "type": "ip_addr",
                    "value": "192.0.2.0",
                },
            ])
        ```

        ### Create a new database firewall allowing a Droplet

        ```python
        import pulumi
        import pulumi_digitalocean as digitalocean

        web = digitalocean.Droplet("web",
            name="web-01",
            size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
            image="ubuntu-22-04-x64",
            region=digitalocean.Region.NYC3)
        postgres_example = digitalocean.DatabaseCluster("postgres-example",
            name="example-postgres-cluster",
            engine="pg",
            version="15",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1,
            node_count=1)
        example_fw = digitalocean.DatabaseFirewall("example-fw",
            cluster_id=postgres_example.id,
            rules=[{
                "type": "droplet",
                "value": web.id,
            }])
        ```

        ### Create a new database firewall for a database replica

        ```python
        import pulumi
        import pulumi_digitalocean as digitalocean

        postgres_example = digitalocean.DatabaseCluster("postgres-example",
            name="example-postgres-cluster",
            engine="pg",
            version="15",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1,
            node_count=1)
        replica_example = digitalocean.DatabaseReplica("replica-example",
            cluster_id=postgres_example.id,
            name="replica-example",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1)
        # Create firewall rule for database replica
        example_fw = digitalocean.DatabaseFirewall("example-fw",
            cluster_id=replica_example.uuid,
            rules=[{
                "type": "ip_addr",
                "value": "192.168.1.1",
            }])
        ```

        ## Import

        Database firewalls can be imported using the `id` of the target database cluster

        For example:

        ```sh
        $ pulumi import digitalocean:index/databaseFirewall:DatabaseFirewall example-fw 5f55c6cd-863b-4907-99b8-7e09b0275d54
        ```

        :param str resource_name: The name of the resource.
        :param pulumi.ResourceOptions opts: Options for the resource.
        :param pulumi.Input[_builtins.str] cluster_id: The ID of the target database cluster.
        :param pulumi.Input[Sequence[pulumi.Input[Union['DatabaseFirewallRuleArgs', 'DatabaseFirewallRuleArgsDict']]]] rules: A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        ...
    @overload
    def __init__(__self__,
                 resource_name: str,
                 args: DatabaseFirewallArgs,
                 opts: Optional[pulumi.ResourceOptions] = None):
        """
        Provides a DigitalOcean database firewall resource allowing you to restrict
        connections to your database to trusted sources. You may limit connections to
        specific Droplets, Kubernetes clusters, or IP addresses.

        ## Example Usage

        ### Create a new database firewall allowing multiple IP addresses

        ```python
        import pulumi
        import pulumi_digitalocean as digitalocean

        postgres_example = digitalocean.DatabaseCluster("postgres-example",
            name="example-postgres-cluster",
            engine="pg",
            version="15",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1,
            node_count=1)
        example_fw = digitalocean.DatabaseFirewall("example-fw",
            cluster_id=postgres_example.id,
            rules=[
                {
                    "type": "ip_addr",
                    "value": "192.168.1.1",
                },
                {
                    "type": "ip_addr",
                    "value": "192.0.2.0",
                },
            ])
        ```

        ### Create a new database firewall allowing a Droplet

        ```python
        import pulumi
        import pulumi_digitalocean as digitalocean

        web = digitalocean.Droplet("web",
            name="web-01",
            size=digitalocean.DropletSlug.DROPLET_S1_VCPU1_GB,
            image="ubuntu-22-04-x64",
            region=digitalocean.Region.NYC3)
        postgres_example = digitalocean.DatabaseCluster("postgres-example",
            name="example-postgres-cluster",
            engine="pg",
            version="15",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1,
            node_count=1)
        example_fw = digitalocean.DatabaseFirewall("example-fw",
            cluster_id=postgres_example.id,
            rules=[{
                "type": "droplet",
                "value": web.id,
            }])
        ```

        ### Create a new database firewall for a database replica

        ```python
        import pulumi
        import pulumi_digitalocean as digitalocean

        postgres_example = digitalocean.DatabaseCluster("postgres-example",
            name="example-postgres-cluster",
            engine="pg",
            version="15",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1,
            node_count=1)
        replica_example = digitalocean.DatabaseReplica("replica-example",
            cluster_id=postgres_example.id,
            name="replica-example",
            size=digitalocean.DatabaseSlug.D_B_1_VPCU1_GB,
            region=digitalocean.Region.NYC1)
        # Create firewall rule for database replica
        example_fw = digitalocean.DatabaseFirewall("example-fw",
            cluster_id=replica_example.uuid,
            rules=[{
                "type": "ip_addr",
                "value": "192.168.1.1",
            }])
        ```

        ## Import

        Database firewalls can be imported using the `id` of the target database cluster

        For example:

        ```sh
        $ pulumi import digitalocean:index/databaseFirewall:DatabaseFirewall example-fw 5f55c6cd-863b-4907-99b8-7e09b0275d54
        ```

        :param str resource_name: The name of the resource.
        :param DatabaseFirewallArgs 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(DatabaseFirewallArgs, 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,
                 cluster_id: Optional[pulumi.Input[_builtins.str]] = None,
                 rules: Optional[pulumi.Input[Sequence[pulumi.Input[Union['DatabaseFirewallRuleArgs', 'DatabaseFirewallRuleArgsDict']]]]] = 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__ = DatabaseFirewallArgs.__new__(DatabaseFirewallArgs)

            if cluster_id is None and not opts.urn:
                raise TypeError("Missing required property 'cluster_id'")
            __props__.__dict__["cluster_id"] = cluster_id
            if rules is None and not opts.urn:
                raise TypeError("Missing required property 'rules'")
            __props__.__dict__["rules"] = rules
        super(DatabaseFirewall, __self__).__init__(
            'digitalocean:index/databaseFirewall:DatabaseFirewall',
            resource_name,
            __props__,
            opts)

    @staticmethod
    def get(resource_name: str,
            id: pulumi.Input[str],
            opts: Optional[pulumi.ResourceOptions] = None,
            cluster_id: Optional[pulumi.Input[_builtins.str]] = None,
            rules: Optional[pulumi.Input[Sequence[pulumi.Input[Union['DatabaseFirewallRuleArgs', 'DatabaseFirewallRuleArgsDict']]]]] = None) -> 'DatabaseFirewall':
        """
        Get an existing DatabaseFirewall 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[_builtins.str] cluster_id: The ID of the target database cluster.
        :param pulumi.Input[Sequence[pulumi.Input[Union['DatabaseFirewallRuleArgs', 'DatabaseFirewallRuleArgsDict']]]] rules: A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        opts = pulumi.ResourceOptions.merge(opts, pulumi.ResourceOptions(id=id))

        __props__ = _DatabaseFirewallState.__new__(_DatabaseFirewallState)

        __props__.__dict__["cluster_id"] = cluster_id
        __props__.__dict__["rules"] = rules
        return DatabaseFirewall(resource_name, opts=opts, __props__=__props__)

    @_builtins.property
    @pulumi.getter(name="clusterId")
    def cluster_id(self) -> pulumi.Output[_builtins.str]:
        """
        The ID of the target database cluster.
        """
        return pulumi.get(self, "cluster_id")

    @_builtins.property
    @pulumi.getter
    def rules(self) -> pulumi.Output[Sequence['outputs.DatabaseFirewallRule']]:
        """
        A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:
        """
        return pulumi.get(self, "rules")

