Skip to content

Instantly share code, notes, and snippets.

@ainsleyclark
Last active March 12, 2025 08:24
Show Gist options
  • Select an option

  • Save ainsleyclark/22a94efbfa8cfe489dd59885564b3599 to your computer and use it in GitHub Desktop.

Select an option

Save ainsleyclark/22a94efbfa8cfe489dd59885564b3599 to your computer and use it in GitHub Desktop.
resource "digitalocean_database_cluster" "postgres" {
name = "db"
engine = "pg"
version = "17"
size = "db-s-1vcpu-1gb"
region = "lon1"
node_count = 1
}
resource "digitalocean_database_user" "postgres_app_user" {
cluster_id = digitalocean_database_cluster.postgres.id
name = "user"
}
resource "digitalocean_database_db" "postgres_app_db" {
cluster_id = digitalocean_database_cluster.postgres.id
name = "db"
}
# resource "digitalocean_database_connection_pool" "postgres_pool" {
# cluster_id = digitalocean_database_cluster.postgres.id
# name = "ss_pool"
# mode = "transaction"
# size = 20
# db_name = digitalocean_database_db.postgres_app_db.name
# user = digitalocean_database_user.postgres_app_user.name
# }
resource "digitalocean_database_firewall" "postgres_firewall" {
cluster_id = digitalocean_database_cluster.postgres.id
}
resource "digitalocean_app" "cms" {
depends_on = [
digitalocean_database_cluster.postgres,
digitalocean_database_user.postgres_app_user,
digitalocean_spaces_bucket.store,
]
spec {
name = "${var.project_name}-cms"
region = "lon"
database {
name = "postgres"
cluster_name = digitalocean_database_cluster.postgres.name
engine = "PG"
production = true
version = "17"
db_name = digitalocean_database_db.postgres_app_db.name
db_user = digitalocean_database_user.postgres_app_user.name
}
alert { rule = "DEPLOYMENT_FAILED" }
alert { rule = "DEPLOYMENT_LIVE" }
domain {
name = "cms.${var.url}"
type = "PRIMARY"
zone = var.url
}
service {
name = "payload"
dockerfile_path = "cms/Dockerfile"
source_dir = "cms"
instance_size_slug = "basic-s"
instance_count = 1
http_port = 3000
github {
branch = "main"
deploy_on_push = true
repo = var.repo_name
}
health_check {
http_path = "/admin"
failure_threshold = 20
initial_delay_seconds = 90
}
env {
key = "PORT"
scope = "RUN_TIME"
value = "3000"
}
env {
key = "DATABASE_URL"
scope = "RUN_AND_BUILD_TIME"
value = "$${postgres.DATABASE_URL}"
type = "SECRET"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment