DigitalOcean

Pulumi Official
Package maintained by Pulumi
v4.15.0 published on Tuesday, Aug 16, 2022 by Pulumi

DatabaseFirewall

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

using System.Collections.Generic;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var postgres_example = new DigitalOcean.DatabaseCluster("postgres-example", new()
    {
        Engine = "pg",
        Version = "11",
        Size = "db-s-1vcpu-1gb",
        Region = "nyc1",
        NodeCount = 1,
    });

    var example_fw = new DigitalOcean.DatabaseFirewall("example-fw", new()
    {
        ClusterId = postgres_example.Id,
        Rules = new[]
        {
            new DigitalOcean.Inputs.DatabaseFirewallRuleArgs
            {
                Type = "ip_addr",
                Value = "192.168.1.1",
            },
            new DigitalOcean.Inputs.DatabaseFirewallRuleArgs
            {
                Type = "ip_addr",
                Value = "192.0.2.0",
            },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		_, err := digitalocean.NewDatabaseCluster(ctx, "postgres-example", &digitalocean.DatabaseClusterArgs{
			Engine:    pulumi.String("pg"),
			Version:   pulumi.String("11"),
			Size:      pulumi.String("db-s-1vcpu-1gb"),
			Region:    pulumi.String("nyc1"),
			NodeCount: pulumi.Int(1),
		})
		if err != nil {
			return err
		}
		_, err = digitalocean.NewDatabaseFirewall(ctx, "example-fw", &digitalocean.DatabaseFirewallArgs{
			ClusterId: postgres_example.ID(),
			Rules: DatabaseFirewallRuleArray{
				&DatabaseFirewallRuleArgs{
					Type:  pulumi.String("ip_addr"),
					Value: pulumi.String("192.168.1.1"),
				},
				&DatabaseFirewallRuleArgs{
					Type:  pulumi.String("ip_addr"),
					Value: pulumi.String("192.0.2.0"),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.DatabaseCluster;
import com.pulumi.digitalocean.DatabaseClusterArgs;
import com.pulumi.digitalocean.DatabaseFirewall;
import com.pulumi.digitalocean.DatabaseFirewallArgs;
import com.pulumi.digitalocean.inputs.DatabaseFirewallRuleArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var postgres_example = new DatabaseCluster("postgres-example", DatabaseClusterArgs.builder()        
            .engine("pg")
            .version("11")
            .size("db-s-1vcpu-1gb")
            .region("nyc1")
            .nodeCount(1)
            .build());

        var example_fw = new DatabaseFirewall("example-fw", DatabaseFirewallArgs.builder()        
            .clusterId(postgres_example.id())
            .rules(            
                DatabaseFirewallRuleArgs.builder()
                    .type("ip_addr")
                    .value("192.168.1.1")
                    .build(),
                DatabaseFirewallRuleArgs.builder()
                    .type("ip_addr")
                    .value("192.0.2.0")
                    .build())
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

postgres_example = digitalocean.DatabaseCluster("postgres-example",
    engine="pg",
    version="11",
    size="db-s-1vcpu-1gb",
    region="nyc1",
    node_count=1)
example_fw = digitalocean.DatabaseFirewall("example-fw",
    cluster_id=postgres_example.id,
    rules=[
        digitalocean.DatabaseFirewallRuleArgs(
            type="ip_addr",
            value="192.168.1.1",
        ),
        digitalocean.DatabaseFirewallRuleArgs(
            type="ip_addr",
            value="192.0.2.0",
        ),
    ])
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const postgres_example = new digitalocean.DatabaseCluster("postgres-example", {
    engine: "pg",
    version: "11",
    size: "db-s-1vcpu-1gb",
    region: "nyc1",
    nodeCount: 1,
});
const example_fw = new digitalocean.DatabaseFirewall("example-fw", {
    clusterId: postgres_example.id,
    rules: [
        {
            type: "ip_addr",
            value: "192.168.1.1",
        },
        {
            type: "ip_addr",
            value: "192.0.2.0",
        },
    ],
});
resources:
  example-fw:
    type: digitalocean:DatabaseFirewall
    properties:
      clusterId: ${["postgres-example"].id}
      rules:
        - type: ip_addr
          value: 192.168.1.1
        - type: ip_addr
          value: 192.0.2.0
  postgres-example:
    type: digitalocean:DatabaseCluster
    properties:
      engine: pg
      version: 11
      size: db-s-1vcpu-1gb
      region: nyc1
      nodeCount: 1

Create a new database firewall allowing a Droplet

using System.Collections.Generic;
using Pulumi;
using DigitalOcean = Pulumi.DigitalOcean;

return await Deployment.RunAsync(() => 
{
    var web = new DigitalOcean.Droplet("web", new()
    {
        Size = "s-1vcpu-1gb",
        Image = "ubuntu-22-04-x64",
        Region = "nyc3",
    });

    var postgres_example = new DigitalOcean.DatabaseCluster("postgres-example", new()
    {
        Engine = "pg",
        Version = "11",
        Size = "db-s-1vcpu-1gb",
        Region = "nyc1",
        NodeCount = 1,
    });

    var example_fw = new DigitalOcean.DatabaseFirewall("example-fw", new()
    {
        ClusterId = postgres_example.Id,
        Rules = new[]
        {
            new DigitalOcean.Inputs.DatabaseFirewallRuleArgs
            {
                Type = "droplet",
                Value = web.Id,
            },
        },
    });

});
package main

import (
	"github.com/pulumi/pulumi-digitalocean/sdk/v4/go/digitalocean"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		web, err := digitalocean.NewDroplet(ctx, "web", &digitalocean.DropletArgs{
			Size:   pulumi.String("s-1vcpu-1gb"),
			Image:  pulumi.String("ubuntu-22-04-x64"),
			Region: pulumi.String("nyc3"),
		})
		if err != nil {
			return err
		}
		_, err = digitalocean.NewDatabaseCluster(ctx, "postgres-example", &digitalocean.DatabaseClusterArgs{
			Engine:    pulumi.String("pg"),
			Version:   pulumi.String("11"),
			Size:      pulumi.String("db-s-1vcpu-1gb"),
			Region:    pulumi.String("nyc1"),
			NodeCount: pulumi.Int(1),
		})
		if err != nil {
			return err
		}
		_, err = digitalocean.NewDatabaseFirewall(ctx, "example-fw", &digitalocean.DatabaseFirewallArgs{
			ClusterId: postgres_example.ID(),
			Rules: DatabaseFirewallRuleArray{
				&DatabaseFirewallRuleArgs{
					Type:  pulumi.String("droplet"),
					Value: web.ID(),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.digitalocean.Droplet;
import com.pulumi.digitalocean.DropletArgs;
import com.pulumi.digitalocean.DatabaseCluster;
import com.pulumi.digitalocean.DatabaseClusterArgs;
import com.pulumi.digitalocean.DatabaseFirewall;
import com.pulumi.digitalocean.DatabaseFirewallArgs;
import com.pulumi.digitalocean.inputs.DatabaseFirewallRuleArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var web = new Droplet("web", DropletArgs.builder()        
            .size("s-1vcpu-1gb")
            .image("ubuntu-22-04-x64")
            .region("nyc3")
            .build());

        var postgres_example = new DatabaseCluster("postgres-example", DatabaseClusterArgs.builder()        
            .engine("pg")
            .version("11")
            .size("db-s-1vcpu-1gb")
            .region("nyc1")
            .nodeCount(1)
            .build());

        var example_fw = new DatabaseFirewall("example-fw", DatabaseFirewallArgs.builder()        
            .clusterId(postgres_example.id())
            .rules(DatabaseFirewallRuleArgs.builder()
                .type("droplet")
                .value(web.id())
                .build())
            .build());

    }
}
import pulumi
import pulumi_digitalocean as digitalocean

web = digitalocean.Droplet("web",
    size="s-1vcpu-1gb",
    image="ubuntu-22-04-x64",
    region="nyc3")
postgres_example = digitalocean.DatabaseCluster("postgres-example",
    engine="pg",
    version="11",
    size="db-s-1vcpu-1gb",
    region="nyc1",
    node_count=1)
example_fw = digitalocean.DatabaseFirewall("example-fw",
    cluster_id=postgres_example.id,
    rules=[digitalocean.DatabaseFirewallRuleArgs(
        type="droplet",
        value=web.id,
    )])
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";

const web = new digitalocean.Droplet("web", {
    size: "s-1vcpu-1gb",
    image: "ubuntu-22-04-x64",
    region: "nyc3",
});
const postgres_example = new digitalocean.DatabaseCluster("postgres-example", {
    engine: "pg",
    version: "11",
    size: "db-s-1vcpu-1gb",
    region: "nyc1",
    nodeCount: 1,
});
const example_fw = new digitalocean.DatabaseFirewall("example-fw", {
    clusterId: postgres_example.id,
    rules: [{
        type: "droplet",
        value: web.id,
    }],
});
resources:
  example-fw:
    type: digitalocean:DatabaseFirewall
    properties:
      clusterId: ${["postgres-example"].id}
      rules:
        - type: droplet
          value: ${web.id}
  web:
    type: digitalocean:Droplet
    properties:
      size: s-1vcpu-1gb
      image: ubuntu-22-04-x64
      region: nyc3
  postgres-example:
    type: digitalocean:DatabaseCluster
    properties:
      engine: pg
      version: 11
      size: db-s-1vcpu-1gb
      region: nyc1
      nodeCount: 1

Create a DatabaseFirewall Resource

new DatabaseFirewall(name: string, args: DatabaseFirewallArgs, opts?: CustomResourceOptions);
@overload
def DatabaseFirewall(resource_name: str,
                     opts: Optional[ResourceOptions] = None,
                     cluster_id: Optional[str] = None,
                     rules: Optional[Sequence[DatabaseFirewallRuleArgs]] = None)
@overload
def DatabaseFirewall(resource_name: str,
                     args: DatabaseFirewallArgs,
                     opts: Optional[ResourceOptions] = None)
func NewDatabaseFirewall(ctx *Context, name string, args DatabaseFirewallArgs, opts ...ResourceOption) (*DatabaseFirewall, error)
public DatabaseFirewall(string name, DatabaseFirewallArgs args, CustomResourceOptions? opts = null)
public DatabaseFirewall(String name, DatabaseFirewallArgs args)
public DatabaseFirewall(String name, DatabaseFirewallArgs args, CustomResourceOptions options)
type: digitalocean:DatabaseFirewall
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

name string
The unique name of the resource.
args DatabaseFirewallArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args DatabaseFirewallArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args DatabaseFirewallArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args DatabaseFirewallArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name String
The unique name of the resource.
args DatabaseFirewallArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

DatabaseFirewall Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The DatabaseFirewall resource accepts the following input properties:

ClusterId string

The ID of the target database cluster.

Rules List<Pulumi.DigitalOcean.Inputs.DatabaseFirewallRuleArgs>

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

ClusterId string

The ID of the target database cluster.

Rules []DatabaseFirewallRuleArgs

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

clusterId String

The ID of the target database cluster.

rules List<DatabaseFirewallRuleArgs>

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

clusterId string

The ID of the target database cluster.

rules DatabaseFirewallRuleArgs[]

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

cluster_id str

The ID of the target database cluster.

rules Sequence[DatabaseFirewallRuleArgs]

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

clusterId String

The ID of the target database cluster.

rules List<Property Map>

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

Outputs

All input properties are implicitly available as output properties. Additionally, the DatabaseFirewall resource produces the following output properties:

Id string

The provider-assigned unique ID for this managed resource.

Id string

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

id string

The provider-assigned unique ID for this managed resource.

id str

The provider-assigned unique ID for this managed resource.

id String

The provider-assigned unique ID for this managed resource.

Look up an Existing DatabaseFirewall Resource

Get an existing DatabaseFirewall resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: DatabaseFirewallState, opts?: CustomResourceOptions): DatabaseFirewall
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        cluster_id: Optional[str] = None,
        rules: Optional[Sequence[DatabaseFirewallRuleArgs]] = None) -> DatabaseFirewall
func GetDatabaseFirewall(ctx *Context, name string, id IDInput, state *DatabaseFirewallState, opts ...ResourceOption) (*DatabaseFirewall, error)
public static DatabaseFirewall Get(string name, Input<string> id, DatabaseFirewallState? state, CustomResourceOptions? opts = null)
public static DatabaseFirewall get(String name, Output<String> id, DatabaseFirewallState state, CustomResourceOptions options)
Resource lookup is not supported in YAML
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
ClusterId string

The ID of the target database cluster.

Rules List<Pulumi.DigitalOcean.Inputs.DatabaseFirewallRuleArgs>

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

ClusterId string

The ID of the target database cluster.

Rules []DatabaseFirewallRuleArgs

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

clusterId String

The ID of the target database cluster.

rules List<DatabaseFirewallRuleArgs>

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

clusterId string

The ID of the target database cluster.

rules DatabaseFirewallRuleArgs[]

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

cluster_id str

The ID of the target database cluster.

rules Sequence[DatabaseFirewallRuleArgs]

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

clusterId String

The ID of the target database cluster.

rules List<Property Map>

A rule specifying a resource allowed to access the database cluster. The following arguments must be specified:

Supporting Types

DatabaseFirewallRule

Type string

The type of resource that the firewall rule allows to access the database cluster. The possible values are: droplet, k8s, ip_addr, tag, or app.

Value string

The ID of the specific resource, the name of a tag applied to a group of resources, or the IP address that the firewall rule allows to access the database cluster.

CreatedAt string

The date and time when the firewall rule was created.

Uuid string

A unique identifier for the firewall rule.

Type string

The type of resource that the firewall rule allows to access the database cluster. The possible values are: droplet, k8s, ip_addr, tag, or app.

Value string

The ID of the specific resource, the name of a tag applied to a group of resources, or the IP address that the firewall rule allows to access the database cluster.

CreatedAt string

The date and time when the firewall rule was created.

Uuid string

A unique identifier for the firewall rule.

type String

The type of resource that the firewall rule allows to access the database cluster. The possible values are: droplet, k8s, ip_addr, tag, or app.

value String

The ID of the specific resource, the name of a tag applied to a group of resources, or the IP address that the firewall rule allows to access the database cluster.

createdAt String

The date and time when the firewall rule was created.

uuid String

A unique identifier for the firewall rule.

type string

The type of resource that the firewall rule allows to access the database cluster. The possible values are: droplet, k8s, ip_addr, tag, or app.

value string

The ID of the specific resource, the name of a tag applied to a group of resources, or the IP address that the firewall rule allows to access the database cluster.

createdAt string

The date and time when the firewall rule was created.

uuid string

A unique identifier for the firewall rule.

type str

The type of resource that the firewall rule allows to access the database cluster. The possible values are: droplet, k8s, ip_addr, tag, or app.

value str

The ID of the specific resource, the name of a tag applied to a group of resources, or the IP address that the firewall rule allows to access the database cluster.

created_at str

The date and time when the firewall rule was created.

uuid str

A unique identifier for the firewall rule.

type String

The type of resource that the firewall rule allows to access the database cluster. The possible values are: droplet, k8s, ip_addr, tag, or app.

value String

The ID of the specific resource, the name of a tag applied to a group of resources, or the IP address that the firewall rule allows to access the database cluster.

createdAt String

The date and time when the firewall rule was created.

uuid String

A unique identifier for the firewall rule.

Import

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

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

Package Details

Repository
https://github.com/pulumi/pulumi-digitalocean
License
Apache-2.0
Notes

This Pulumi package is based on the digitalocean Terraform Provider.