-
Notifications
You must be signed in to change notification settings - Fork 0
infrastructure
This document provides detailed information about the infrastructure setup for the Semantic Medallion Data Platform. The infrastructure is managed using Terraform and is hosted on Digital Ocean.
The following resources are provisioned on Digital Ocean:
-
Resource Name:
digitalocean_database_cluster.postgres
- Engine: PostgreSQL
- Version: 15
- Size: db-s-1vcpu-1gb (1 vCPU, 1GB RAM)
- Region: Configurable (default: London - lon1)
- Node Count: 1
- Tags: Environment tag (dev, staging, or prod)
-
Resource Name:
digitalocean_database_db.database
- Name: semantic_data_platform
- Cluster: References the PostgreSQL cluster
-
Resource Name:
digitalocean_database_user.user
- Name: semantic_app_user
- Cluster: References the PostgreSQL cluster
infrastructure/terraform/
├── main.tf # Provider configuration
├── database.tf # Database resource definitions
├── variables.tf # Variable definitions
├── outputs.tf # Output definitions
├── terraform.tfvars.example # Example variables file
└── terraform.tfvars # Actual variables file (not in version control)
This file configures the Digital Ocean provider:
terraform {
required_providers {
digitalocean = {
source = "digitalocean/digitalocean"
version = "~> 2.0"
}
}
}
# Configure the DigitalOcean Provider
provider "digitalocean" {
token = var.do_token
}
This file defines the PostgreSQL database resources:
resource "digitalocean_database_cluster" "postgres" {
name = "${var.project_name}-db-${var.environment}"
engine = "pg"
version = "15"
size = "db-s-1vcpu-1gb" # Smallest available size ($15/month)
region = var.region
node_count = 1
tags = [var.environment]
}
# Create a database
resource "digitalocean_database_db" "database" {
cluster_id = digitalocean_database_cluster.postgres.id
name = "semantic_data_platform"
}
# Create a database user
resource "digitalocean_database_user" "user" {
cluster_id = digitalocean_database_cluster.postgres.id
name = "semantic_app_user"
}
This file defines the variables used in the Terraform configuration:
variable "do_token" {
description = "Digital Ocean API Token"
type = string
sensitive = true
}
variable "region" {
description = "Digital Ocean region"
type = string
default = "lon1"
}
variable "project_name" {
description = "Name of the project"
type = string
default = "Semantic Data Platform"
}
variable "environment" {
description = "Deployment environment"
type = string
default = "dev"
validation {
condition = contains(["dev", "staging", "prod"], var.environment)
error_message = "Environment must be one of: dev, staging, prod."
}
}
This file defines the outputs from the Terraform configuration:
output "postgres_host" {
value = digitalocean_database_cluster.postgres.host
sensitive = false
}
output "postgres_port" {
value = digitalocean_database_cluster.postgres.port
sensitive = false
}
output "postgres_user" {
value = digitalocean_database_user.user.name
sensitive = false
}
output "postgres_password" {
value = digitalocean_database_user.user.password
sensitive = true
}
output "postgres_database" {
value = digitalocean_database_db.database.name
sensitive = false
}
output "postgres_uri" {
value = digitalocean_database_cluster.postgres.uri
sensitive = true
}
- Install Terraform (version 1.0.0 or later)
- Create a Digital Ocean account and generate an API token
- Navigate to the Terraform directory:
cd infrastructure/terraform
- Create a
terraform.tfvars
file from the example:cp terraform.tfvars.example terraform.tfvars
- Edit the
terraform.tfvars
file to add your Digital Ocean API token - Initialize Terraform:
terraform init
- Plan the infrastructure changes:
terraform plan -out=tfplan
- Apply the infrastructure changes:
terraform apply tfplan
To update the infrastructure after making changes to the Terraform files:
terraform plan -out=tfplan # Preview changes
terraform apply tfplan # Apply changes
To destroy the infrastructure when no longer needed:
terraform destroy
After the infrastructure is provisioned, Terraform will output the connection details for the PostgreSQL database:
-
Host:
postgres_host
output -
Port:
postgres_port
output -
Database:
postgres_database
output -
Username:
postgres_user
output -
Password:
postgres_password
output (sensitive) -
URI:
postgres_uri
output (sensitive)
You can use these details to connect to the database from your application or from a database client.
- The Digital Ocean API token is sensitive and should not be committed to version control
- Database passwords are also sensitive and should be handled securely
- The database is accessible over the internet, so ensure that your application uses secure connections
The infrastructure provisioned by this Terraform configuration includes:
- PostgreSQL Database Cluster: db-s-1vcpu-1gb ($15/month)
Total estimated cost: $15/month
-
Terraform initialization fails:
- Ensure you have the correct version of Terraform installed
- Check your internet connection
-
Digital Ocean API token issues:
- Verify that your API token is correct and has the necessary permissions
- Ensure the token is properly set in the terraform.tfvars file
-
Database connection issues:
- Check that the database cluster is running
- Verify that you're using the correct connection details
- Ensure your firewall allows connections to the database port
Home | Architecture | Development | Deployment | Infrastructure
© 2025 ByteMeDirk • Report Issues • Last updated: June 10, 2025