Files
hapi/infra/postgres/main.tf
T
Bobby 88235fc824 feat: Add PostgreSQL Kubernetes deployment with Kustomize
- Create infrastructure for PostgreSQL StatefulSet in Kubernetes
- Implement environment-specific configurations (staging/production)
- Add Kustomize overlays for deterministic deployments
- Document deployment process in AGENTS.md and infra/k8s/README.md
- Include Makefile and helper scripts for easy management

New directories:
- infra/k8s/base/ - Shared resources (StatefulSet, Service, PVC, Namespace)
- infra/k8s/staging/ - Staging environment overlay
- infra/k8s/production/ - Production environment overlay

Key files:
- infra/k8s/base/kustomization.yaml
- infra/k8s/staging/kustomization.yaml
- infra/k8s/production/kustomization.yaml
- infra/k8s/README.md

Resources are prefixed by environment (staging-, production-) and deployed
to the postgres namespace.
2026-11-18 15:29:00 -05:00

95 lines
2.2 KiB
Terraform

# PostgreSQL module for HAPI
# Creates separate database instances for staging and production
terraform {
required_providers {
linode = {
source = "linode/linode"
version = "~> 2.0"
}
random = {
source = "hashicorp/random"
version = "~> 3.0"
}
}
}
# Object Storage buckets for PostgreSQL state
resource "linode_object_storage_bucket" "state" {
for_each = toset([var.environment])
label = "hapi-postgres-state-${each.key}"
region = var.linode_object_storage_region
access_key = var.object_storage_access_key
secret_key = var.object_storage_secret_key
}
resource "linode_lke_cluster" "postgres" {
for_each = toset([var.environment])
region = var.linode_region
label = "hapi-postgres-${each.key}"
k8s_version = var.linode_lke_version
tags = toset([for k, v in merge(var.tags, { Environment = each.key }) : "${k}=${v}"])
pool {
count = each.key == "production" ? 2 : 1
type = var.linode_node_type
}
}
# Database configuration
locals {
databases = {
staging = {
name = "hapi_staging"
pool_size = 2
}
production = {
name = "hapi_production"
pool_size = 3
}
}
}
output "endpoint" {
description = "PostgreSQL endpoint (Kubernetes API endpoint)"
value = linode_lke_cluster.postgres[var.environment].api_endpoints[0]
}
output "port" {
description = "PostgreSQL port"
value = 5432
}
output "database" {
description = "PostgreSQL database name"
value = local.databases[var.environment].name
}
output "username" {
description = "PostgreSQL username"
value = "hapi_admin"
}
output "password" {
description = "PostgreSQL password"
value = random_string.password.result
sensitive = true
}
output "pool_size" {
description = "PostgreSQL connection pool size"
value = local.databases[var.environment].pool_size
}
output "state_bucket_name" {
description = "Name of the state bucket in Object Storage"
value = "hapi-postgres-state-${var.environment}"
}
output "kubeconfig" {
description = "Kubeconfig for the PostgreSQL LKE cluster"
value = linode_lke_cluster.postgres[var.environment].kubeconfig
}