Skip to content

pvlltvk/terraform-digitalocean-database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

terraform-digitalocean-database

Terraform module which creates a DigitalOcean database cluster resource.

Usage

module "database" {
  source                       = "../../"
  cluster_name                 = "postgresql-fra1"
  cluster_engine               = "pg"
  cluster_version              = "13"
  cluster_size                 = "db-s-2vcpu-4gb"
  cluster_region               = "fra1"
  cluster_node_count           = 2
  cluster_private_network_uuid = digitalocean_vpc.foo-bar-vpc.id
  cluster_tags                 = ["foo", "bar"]
  cluster_maintenance = {
    maintenance_hour = "02:00:00"
    maintenance_day  = "saturday"
  }

  databases = ["foo-database", "bar-database"]

  users = [
    {
      name = "foo-user"
    },
    {
      name = "bar-user"
    }
  ]

  create_pools = true
  pools = [
    {
      name    = "foo-pool",
      mode    = "transaction",
      size    = 10,
      db_name = "foo-database",
      user    = "foo-user"
    },
    {
      name    = "bar-pool"
      mode    = "transaction",
      size    = 10,
      db_name = "bar-database",
      user    = "bar-user"
    }
  ]

  create_firewall = true
  firewall_rules = [
    {
      type  = "droplet",
      value = digitalocean_droplet.web.id
    }
  ]
}

Examples

Some complete examples can be found in this repository:

Requirements

Name Version
terraform >= 1.0.10
digitalocean >= 2.16.0

Providers

Name Version
digitalocean >= 2.16.0

Modules

No modules.

Resources

Name Type
digitalocean_database_cluster.cluster resource
digitalocean_database_connection_pool.connection_pool resource
digitalocean_database_db.database resource
digitalocean_database_firewall.firewall resource
digitalocean_database_user.user resource

Inputs

Name Description Type Default Required
cluster_engine Database engine used by the cluster (ex. pg for PostreSQL, mysql for MySQL, redis for Redis, or mongodb for MongoDB) string n/a yes
cluster_maintenance The day and the start hour of the maintenance window policy map(string) null no
cluster_name The name of the cluster string n/a yes
cluster_node_count Number of nodes that will be included in the cluster number n/a yes
cluster_private_network_uuid The ID of the VPC where the database cluster will be located string null no
cluster_region DigitalOcean region where the cluster will reside string n/a yes
cluster_size Database Droplet size associated with the cluster (ex. db-s-1vcpu-1gb) string n/a yes
cluster_tags A list of optional tags to add to the cluster list(string) [] no
cluster_version The version of the cluster string n/a yes
create_firewall Controls if firewall should be created bool false no
create_pools Controls if pools should be created bool false no
databases A list of databases in the cluster list(string) [] no
firewall_rules List of firewall rules associated with the cluster list(map(string)) [] no
mysql_sql_mode A comma separated string specifying the SQL modes for a MySQL cluster. string null no
pools A list of connection pools in the cluster list(map(string)) null no
redis_eviction_policy A string specifying the eviction policy for a Redis cluster. Valid values are: noeviction, allkeys_lru, allkeys_random, volatile_lru, volatile_random, or volatile_ttl string null no
users A list of users in the cluster list(map(string)) null no

Outputs

Name Description
connection_pool_host The hostname used to connect to the database connection pool
connection_pool_id The ID of the database connection pool
connection_pool_password Password for the connection pool's user
connection_pool_port Network port that the database connection pool is listening on
connection_pool_private_host Same as pool host, but only accessible from resources within the account and in the same region
connection_pool_private_uri Same as pool uri, but only accessible from resources within the account and in the same region
connection_pool_uri The full URI for connecting to the database connection pool
database_cluster_default_database Name of the cluster's default database
database_cluster_default_password Password for the cluster's default user
database_cluster_default_user Username for the cluster's default user
database_cluster_host The hostname of the database cluster
database_cluster_id The id of the database cluster
database_cluster_port Network port that the database cluster is listening on
database_cluster_private_host Same as host, but only accessible from resources within the account and in the same region
database_cluster_uri The full URI for connecting to the database cluster
database_cluster_urn The uniform resource name of the database cluster
database_firewall_id A unique identifier for the firewall
database_firewall_rule A map with rule's uuid, type, value and created_at params
db_name The name for the database
user_password Password for the database user
user_role Role for the database user