Skip to content

Instantly share code, notes, and snippets.

@holms
Created April 17, 2023 16:35
Show Gist options
  • Save holms/16f699970157a11326499474899295da to your computer and use it in GitHub Desktop.
Save holms/16f699970157a11326499474899295da to your computer and use it in GitHub Desktop.
Terraform Digital Ocean Postgresql Database Cluster
resource "digitalocean_vpc" "myvpc" {
name = "myvpc"
region = "fra1"
ip_range = "10.10.10.0/24"
}
resource "digitalocean_database_cluster" "mycluster" {
name = "mycluster"
engine = "pg"
version = "14"
size = "gd-2vcpu-8gb"
region = "fra1"
node_count = 1
private_network_uuid = digitalocean_vpc.myvpc.id
}
resource "digitalocean_database_user" "mydb" {
cluster_id = digitalocean_database_cluster.mycluster.id
name = "mydb"
}
resource "digitalocean_database_connection_pool" "pool-01" {
cluster_id = digitalocean_database_cluster.mycluster.id
name = "mydb"
mode = "transaction"
size = 20
db_name = digitalocean_database_db.mydb.name
user = digitalocean_database_user.mydb.name
}
output "do_pbs_pg" {
value = {
"database" = digitalocean_database_db.mydb.name
"username" = digitalocean_database_user.mydb.name
"password" = digitalocean_database_connection_pool.pool-01.password
"host" = digitalocean_database_connection_pool.pool-01.host
"port" = digitalocean_database_connection_pool.pool-01.port
}
sensitive = true
description = "digitalocean postgresql database cluster"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment