Skip to content

Terraform module for creating PostgreSQL cluster on the DigitalOcean cloud.

License

Notifications You must be signed in to change notification settings

opsd-io/terraform-module-digitalocean-postgresql

Repository files navigation

OPSd - the unique and effortless way of managing cloud infrastructure.

Meet OPSd. The unique and effortless way of managing cloud infrastructure.

terraform-module-template

Introduction

What does the module provide?

Usage

module "postgresql" {
  source  = "https://github.com/opsd-io/terraform-module-digitalocean-postgresql?ref=main"

  cluster_name            = "example-postgresql-cluster"
  postgresql_version      = "16"
  node_size               = "db-s-1vcpu-1gb"
  region                  = "nyc1"
  node_count              = 1
  tags                    = ["postgresql", "production"]
  database_users          = ["Admin", "Mark", "Robert"]
  firewall_rules          = [
    {
      type  = "ip_addr"
      value = "172.168.0.1"
    },
    {
      type  = "tag"
      value = "app"
    }
  ]
  replica_enable          = true
  replica_node_size       = "db-s-1vcpu-1gb"
  replica_cluster_name    = "example-postgresql-replica-cluster"
  replica_region          = "nyc1"
  firewall_rules          = [
    {
      type  = "ip_addr"
      value = "172.168.0.1"
    },
    {
      type  = "tag"
      value = "app"
    }
  ]
}

IMPORTANT: Make sure not to pin to master because there may be breaking changes between releases.

Requirements

Name Version
terraform >= 1.9.5
digitalocean >= 2.41.0

Providers

Name Version
digitalocean >= 2.41.0

Modules

No modules.

Resources

Name Type
digitalocean_database_cluster.main resource
digitalocean_database_firewall.main resource
digitalocean_database_firewall.replica_fw resource
digitalocean_database_postgresql_config.main resource
digitalocean_database_replica.main resource
digitalocean_database_user.main resource

Inputs

Name Description Type Default Required
cluster_name The name of the database cluster. string n/a yes
database_users List of users. set(string) [] no
firewall_rules List of trusted sources associated with the cluster.
list(object({
type = string
value = string
}))
[] no
node_count Number of postgresql nodes that will be created. number 1 no
node_size The postgresql node instance size. string "db-s-1vcpu-1gb" no
postgresql_version Engine version used by the cluster. number 16 no
region DigitalOcean region where the cluster will reside. string n/a yes
replica_cluster_name The name of the replica database cluster. string null no
replica_enable Flag to control the replica creation. bool false no
replica_firewall_rules List of trusted sources associated with the replica cluster.
list(object({
type = string
value = string
}))
[] no
replica_node_size The postgresql replica node instance size. string "db-s-1vcpu-1gb" no
replica_region DigitalOcean replica region where the cluster will reside. string null no
tags A list of tag names to be applied to the database cluster. set(string) [] no
timezone PostgreSQL service timezone string "UTC" no
vpc_uuid The ID of the VPC where the load balancer will be located. string null no

Outputs

Name Description
database_cluster_urn The uniform resource name of the database cluster.
firewall_id A unique identifier for the firewall.
main_default_database Name of the cluster's default database.
main_default_user Username for the cluster's default user.
main_default_user_password Password for the cluster's default user.
main_host Database cluster's hostname.
main_host_id The ID of the database cluster.
main_port Network port that the database cluster is listening on.
main_private_host Same as host, but only accessible from resources within the account and in the same region.
main_private_uri Same as uri, but only accessible from resources within the account and in the same region.
main_uri The full URI for connecting to the database cluster.
replica_id Replica ID.
replica_uuid Replica UUID.
user_ids A unique identifier for database users.
user_password Password for the database user.

Examples of usage

Do you want to see how the module works? See all the usage examples.

Related modules

The list of related modules (if present).

Contributing

If you are interested in contributing to the project, see see our guide.

Support

If you have a problem with the module or want to propose a new feature, you can report it via the project's (Github) issue tracker.

If you want to discuss something in person, you can join our community on Slack.

License

Apache License 2.0