01: infra
This commit is contained in:
1 parent
ec9bb74be0
commit
341cd05ac5
71 files changed
+2058
-1
No files matched your search
@@ -0,0 +1,76 @@
|
||||
# PostgreSQL module for HAPI
|
||||
# Creates separate database instances for staging and production
|
||||
|
||||
# Object Storage buckets for PostgreSQL state
|
||||
resource "linode_object_storage_bucket" "state" {
|
||||
for_each = toset(["staging", "production"])
|
||||
|
||||
label = "hapi-postgres-state-${each.key}"
|
||||
cluster = var.linode_object_storage_cluster
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
}
|
||||
|
||||
resource "linode_lke_cluster" "postgres" {
|
||||
for_each = toset(["staging", "production"])
|
||||
|
||||
region = var.linode_region
|
||||
label = "hapi-postgres-${each.key}"
|
||||
k8s_version = var.linode_lke_version
|
||||
tags = merge(var.tags, { Environment = each.key })
|
||||
|
||||
pools {
|
||||
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"
|
||||
value = linode_lke_cluster.postgres[var.environment].hostname
|
||||
}
|
||||
|
||||
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}"
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Random password for PostgreSQL
|
||||
|
||||
resource "random_string" "password" {
|
||||
length = 32
|
||||
upper = true
|
||||
lower = true
|
||||
numeric = true
|
||||
special = false
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# Postgres module variables
|
||||
linode_region = "us-east"
|
||||
linode_lke_version = "1.30"
|
||||
linode_node_type = "g6-standard-4"
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
@@ -0,0 +1,45 @@
|
||||
# Variables for PostgreSQL module
|
||||
|
||||
variable "linode_region" {
|
||||
description = "Linode region for PostgreSQL"
|
||||
type = string
|
||||
default = "us-east"
|
||||
}
|
||||
|
||||
variable "linode_lke_version" {
|
||||
description = "Linode Kubernetes Engine version"
|
||||
type = string
|
||||
default = "1.30"
|
||||
}
|
||||
|
||||
variable "linode_node_type" {
|
||||
description = "Linode node type for PostgreSQL pools"
|
||||
type = string
|
||||
default = "g6-standard-4"
|
||||
}
|
||||
|
||||
variable "linode_object_storage_cluster" {
|
||||
description = "Linode Object Storage cluster"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "object_storage_access_key" {
|
||||
description = "Object Storage access key"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "object_storage_secret_key" {
|
||||
description = "Object Storage secret key"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags for all resources"
|
||||
type = map(string)
|
||||
default = {
|
||||
ManagedBy = "terraform"
|
||||
Project = "hapi"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user