|
| 1 | +# ============================================================= |
| 2 | +# Supabase — Managed Postgres Database |
| 3 | +# ============================================================= |
| 4 | +# Terraform creates the entire Supabase project (Postgres DB, |
| 5 | +# Auth, Storage, Realtime) via the Supabase Management API. |
| 6 | +# |
| 7 | +# Prerequisites: |
| 8 | +# 1. Create a Personal Access Token at: |
| 9 | +# https://supabase.com/dashboard/account/tokens |
| 10 | +# 2. Find your Organization slug at: |
| 11 | +# Supabase Dashboard → Org Settings → General → Org slug |
| 12 | +# 3. Set supabase_access_token + supabase_org_id in |
| 13 | +# terraform.tfvars (local) or Terraform Cloud variables. |
| 14 | +# ============================================================= |
| 15 | + |
| 16 | +# ───────────────────────────────────────────────────────────── |
| 17 | +# Auto-generate a secure database password |
| 18 | +# ───────────────────────────────────────────────────────────── |
| 19 | +resource "random_password" "db" { |
| 20 | + length = 32 |
| 21 | + special = false |
| 22 | +} |
| 23 | + |
| 24 | +# ───────────────────────────────────────────────────────────── |
| 25 | +# Create the Supabase project |
| 26 | +# ───────────────────────────────────────────────────────────── |
| 27 | +resource "supabase_project" "senzen" { |
| 28 | + organization_id = var.supabase_org_id |
| 29 | + name = var.supabase_project_name |
| 30 | + database_password = random_password.db.result |
| 31 | + region = var.supabase_region |
| 32 | + |
| 33 | + lifecycle { |
| 34 | + # Prevent accidental destruction of the production database |
| 35 | + prevent_destroy = true |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +# ───────────────────────────────────────────────────────────── |
| 40 | +# Fetch API keys for the project (anon + service_role) |
| 41 | +# ───────────────────────────────────────────────────────────── |
| 42 | +data "supabase_apikeys" "senzen" { |
| 43 | + project_ref = supabase_project.senzen.id |
| 44 | +} |
0 commit comments