Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a5047cb72e | ||
|
|
27abc1891b | ||
|
|
494f38c1f3 | ||
|
|
341cd05ac5 | ||
|
|
ec9bb74be0 | ||
|
|
238371147c | ||
|
|
f46e184d00 | ||
|
|
586bd6d7e5 | ||
|
|
671ab2928b |
No files matched your search
@@ -0,0 +1,14 @@
|
||||
# 01: Infrastructure Setup
|
||||
|
||||
**What to build:** Linode infrastructure provisioned via Terraform: PostgreSQL database (with StatefulSet for production), Object Storage, and basic networking. Enables all other components to run.
|
||||
|
||||
**Blocked by:** None (can start immediately)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Terraform state stored in Linode Object Storage
|
||||
- [ ] PostgreSQL database created (separate staging/production instances)
|
||||
- [ ] Linode Object Storage buckets created for uploads
|
||||
- [ ] Kubernetes StatefulSet for PostgreSQL production deployed
|
||||
- [ ] Basic networking (firewall rules, load balancer) configured
|
||||
- [ ] UptimeKuma configured to poll `/health` endpoint
|
||||
@@ -0,0 +1,15 @@
|
||||
# 01a: Linode Infrastructure with Terraform
|
||||
|
||||
**What to build:** Provision Linode infrastructure via Terraform: PostgreSQL database (separate staging/production), Object Storage buckets, and basic networking. Enables all other components to run.
|
||||
|
||||
**Blocked by:** None (can start immediately)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Terraform state stored in Linode Object Storage (backend configuration)
|
||||
- [ ] PostgreSQL database instance for staging created
|
||||
- [ ] PostgreSQL database instance for production created
|
||||
- [ ] Linode Object Storage bucket for staging uploads created
|
||||
- [ ] Linode Object Storage bucket for production uploads created
|
||||
- [ ] Basic networking: firewall rules configured for API, PostgreSQL, Adminer
|
||||
- [ ] Terraform outputs exported (database endpoints, object storage credentials)
|
||||
@@ -0,0 +1,14 @@
|
||||
# 01b: Kubernetes StatefulSet for Production PostgreSQL
|
||||
|
||||
**What to build:** Kubernetes StatefulSet for production PostgreSQL with persistent storage, enabling learnable infrastructure with stateful workload patterns.
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Kubernetes cluster configured (or existing cluster accessible)
|
||||
- [ ] StatefulSet manifest for PostgreSQL defined
|
||||
- [ ] PersistentVolumeClaim for PostgreSQL data configured
|
||||
- [ ] StatefulSet deployed to production cluster
|
||||
- [ ] PostgreSQL pod healthy and accepting connections
|
||||
- [ ] PostgreSQL version verified (e.g., 15.x or 16.x)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 02: Database Schema & Migrations
|
||||
|
||||
**What to build:** PostgreSQL database initialized with Alembic migrations. First schema includes users table, auth tokens, and basic metadata. CI runs migrations on deploy.
|
||||
|
||||
**Blocked by:** 01 (Infrastructure Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Alembic migrations configured and running
|
||||
- [ ] Users table with JWT token support created
|
||||
- [ ] Auth tokens table for API key rotation created
|
||||
- [ ] Migrations applied in staging environment
|
||||
- [ ] Migrations applied in production environment
|
||||
- [ ] CI workflow runs migrations on deploy (staging on push to `main`, production on tags)
|
||||
- [ ] Migration rollback capability tested (e.g., `alembic downgrade + upgrade`)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 02a: Alembic Migration Framework
|
||||
|
||||
**What to build:** Alembic configured and running with additive-by-default migrations, destructive changes behind flags.
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Alembic initialized in FastAPI project (`alembic init`)
|
||||
- [ ] `alembic.ini` configured with environment-specific URLs (staging/production)
|
||||
- [ ] First migration created (empty schema or minimal `users` table)
|
||||
- [ ] Migration applied to staging database
|
||||
- [ ] Migration applied to production database
|
||||
- [ ] Migration rollback tested (`alembic downgrade + upgrade`)
|
||||
- [ ] CI workflow step added to run migrations on deploy
|
||||
@@ -0,0 +1,13 @@
|
||||
# 02b: Users Table & Auth Tokens Schema
|
||||
|
||||
**What to build:** Database schema for users and authentication tokens with JWT support.
|
||||
|
||||
**Blocked by:** 02a (Alembic Migration Framework)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `users` table created with columns: id, email, hashed_password, is_active, created_at, updated_at
|
||||
- [ ] `auth_tokens` table created with columns: id, user_id, token, token_type, expires_at, revoked_at
|
||||
- [ ] Indexes added for common queries (email lookup, token expiration)
|
||||
- [ ] Migration applied to staging and production
|
||||
- [ ] Database constraints verified (unique email, foreign key to users)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 03: FastAPI Application Foundation
|
||||
|
||||
**What to build:** Layered FastAPI app structure (`models/`, `routers/`, `schemas/`, `services/`, `db/`) with JWT auth middleware and rate limiting. Includes `/health` endpoint with DB status check.
|
||||
|
||||
**Blocked by:** 02 (Database Schema & Migrations)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Layered FastAPI app structure created (`models/`, `routers/`, `schemas/`, `services/`, `db/`)
|
||||
- [ ] JWT authentication middleware implemented with token validation
|
||||
- [ ] Rate limiting middleware configured (per-token limits)
|
||||
- [ ] `/health` endpoint returns API status and DB connection status
|
||||
- [ ] `/health/ready` and `/health/live` endpoints implemented
|
||||
- [ ] OpenAPI docs generated and accessible at `/docs`
|
||||
- [ ] FastAPI app tested with test client against test database
|
||||
@@ -0,0 +1,14 @@
|
||||
# 03a: Layered FastAPI App Structure
|
||||
|
||||
**What to build:** FastAPI app with layered module structure (`models/`, `routers/`, `schemas/`, `services/`, `db/`).
|
||||
|
||||
**Blocked by:** 02b (Users & Auth Tokens Schema)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Directory structure created (`models/`, `routers/`, `schemas/`, `services/`, `db/`)
|
||||
- [ ] `main.py` entry point with FastAPI app instance
|
||||
- [ ] Database module (`db/session.py`, `db/connection.py`) implemented
|
||||
- [ ] First router (e.g., `routers/health.py`) created with basic endpoints
|
||||
- [ ] Schemas module initialized with base models (e.g., `schemas/base.py`)
|
||||
- [ ] Services module initialized with base service class
|
||||
@@ -0,0 +1,14 @@
|
||||
# 03b: JWT Authentication Middleware
|
||||
|
||||
**What to build:** JWT authentication middleware with token validation, supporting multiple signers and future OAuth.
|
||||
|
||||
**Blocked by:** 03a (Layered FastAPI App Structure)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] JWT middleware implemented (token extraction, validation, user injection)
|
||||
- [ ] Token generation function (`create_token(user_id, expires_in)`)
|
||||
- [ ] Token validation with secret key (configurable via environment)
|
||||
- [ ] `/auth/login` endpoint implemented (returns JWT token)
|
||||
- [ ] `/auth/logout` endpoint implemented (marks token as revoked)
|
||||
- [ ] Test client configured with auth header fixture
|
||||
@@ -0,0 +1,13 @@
|
||||
# 03c: Rate Limiting Middleware
|
||||
|
||||
**What to build:** Token-based rate limiting middleware in FastAPI, extensible to Redis or Traefik later.
|
||||
|
||||
**Blocked by:** 03b (JWT Authentication Middleware)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Rate limiting middleware implemented (per-token limits)
|
||||
- [ ] Default rate limit configured (e.g., 100 requests/minute per token)
|
||||
- [ ] Rate limit headers exposed in responses (`X-RateLimit-Limit`, `X-RateLimit-Remaining`)
|
||||
- [ ] Rate limit exceeded response returns `429 Too Many Requests`
|
||||
- [ ] Rate limiting tests written (test client simulates multiple requests)
|
||||
@@ -0,0 +1,14 @@
|
||||
# 03d: Health Endpoint
|
||||
|
||||
**What to build:** `/health` endpoint with DB and object storage dependency checks.
|
||||
|
||||
**Blocked by:** 03c (Rate Limiting Middleware)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `/health` endpoint implemented (returns status: `healthy`, `degraded`, `unhealthy`)
|
||||
- [ ] Database dependency check included (connectivity, query test)
|
||||
- [ ] Object storage dependency check included (bucket access test)
|
||||
- [ ] `/health/ready` endpoint implemented (blocks on all dependencies)
|
||||
- [ ] `/health/live` endpoint implemented (always returns `healthy`)
|
||||
- [ ] Health check tests written (test client validates response schema)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 04: Object Storage Integration
|
||||
|
||||
**What to build:** File upload support integrated with Linode Object Storage + NextCloud backup. Includes upload/download/cleanup workflows tested end-to-end.
|
||||
|
||||
**Blocked by:** 01 (Infrastructure Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Linode Object Storage SDK integrated (boto3 or equivalent)
|
||||
- [ ] Upload endpoint accepts files and stores in Linode Object Storage
|
||||
- [ ] Download endpoint retrieves files from Linode Object Storage
|
||||
- [ ] NextCloud backup integration: files mirrored to NextCloud after upload
|
||||
- [ ] File cleanup workflow (e.g., delete orphaned files, retention policy)
|
||||
- [ ] Object storage operations tested end-to-end (upload → Linode → NextCloud → download)
|
||||
- [ ] Error handling for storage failures (retry, fallback, alerts)
|
||||
@@ -0,0 +1,14 @@
|
||||
# 04a: Linode Object Storage SDK Integration
|
||||
|
||||
**What to build:** Linode Object Storage SDK integration for uploads, downloads, and file management.
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Linode Object Storage SDK added (e.g., `boto3` or `linode-api-client`)
|
||||
- [ ] Object storage client initialized with credentials (configurable via environment)
|
||||
- [ ] Upload function implemented (`upload_file(bucket, key, data)`)
|
||||
- [ ] Download function implemented (`download_file(bucket, key)`)
|
||||
- [ ] Delete function implemented (`delete_file(bucket, key)`)
|
||||
- [ ] Object storage client tested against staging bucket
|
||||
@@ -0,0 +1,13 @@
|
||||
# 04b: File Upload Endpoint
|
||||
|
||||
**What to build:** API endpoint for file uploads to Linode Object Storage.
|
||||
|
||||
**Blocked by:** 04a (Linode Object Storage SDK Integration)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `/files/upload` endpoint implemented (POST with multipart/form-data)
|
||||
- [ ] Upload endpoint stores file in Linode Object Storage
|
||||
- [ ] Upload endpoint returns file metadata (id, url, size, content_type)
|
||||
- [ ] File upload tests written (test client simulates multipart upload)
|
||||
- [ ] Error handling for storage failures (retry, fallback, alerts)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 04c: File Download Endpoint
|
||||
|
||||
**What to build:** API endpoint for file downloads from Linode Object Storage.
|
||||
|
||||
**Blocked by:** 04b (File Upload Endpoint)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `/files/{file_id}` endpoint implemented (GET)
|
||||
- [ ] Download endpoint retrieves file from Linode Object Storage
|
||||
- [ ] Download endpoint sets appropriate content-type headers
|
||||
- [ ] Download endpoint returns file stream or presigned URL
|
||||
- [ ] File download tests written (test client verifies file content matches)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 04d: NextCloud Backup Integration
|
||||
|
||||
**What to build:** NextCloud backup integration: files mirrored to NextCloud after upload to Linode Object Storage.
|
||||
|
||||
**Blocked by:** 04a (Linode Object Storage SDK Integration)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] NextCloud API client initialized with credentials
|
||||
- [ ] Mirror function implemented (`mirror_to_nextcloud(linode_key, nextcloud_key)`)
|
||||
- [ ] Upload workflow updated: after Linode upload, mirror to NextCloud
|
||||
- [ ] Error handling for NextCloud failures (retry, fallback, alerts)
|
||||
- [ ] NextCloud backup tests written (test client verifies file in NextCloud)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 05: Observability Setup
|
||||
|
||||
**What to build:** JSON structured logging and NTFY alerts for errors/warnings. Logs include context (request ID, user ID); alerts include severity and topic.
|
||||
|
||||
**Blocked by:** 03 (FastAPI Application Foundation)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] JSON structured logging configured (timestamp, level, message, context)
|
||||
- [ ] Request ID injected into all log entries
|
||||
- [ ] User ID included in logs where applicable
|
||||
- [ ] NTFY integration: API pushes errors/warnings to configurable topics
|
||||
- [ ] Alert severity levels implemented (info, warning, error, critical)
|
||||
- [ ] NTFY alerts include context (e.g., "Database connection failures")
|
||||
- [ ] Logging and alerts tested in staging environment
|
||||
@@ -0,0 +1,13 @@
|
||||
# 05a: JSON Structured Logging
|
||||
|
||||
**What to build:** JSON structured logging configured with timestamp, level, message, and context fields.
|
||||
|
||||
**Blocked by:** 03a (Layered FastAPI App Structure)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Logging configuration set to JSON format
|
||||
- [ ] Timestamp, level, message fields included in every log entry
|
||||
- [ ] Context fields (request_id, user_id) injected where applicable
|
||||
- [ ] FastAPI request lifecycle logs (start, end, error)
|
||||
- [ ] Structured logging tests written (verify JSON output schema)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 05b: Request ID Injection
|
||||
|
||||
**What to build:** Request ID injected into all log entries via FastAPI middleware.
|
||||
|
||||
**Blocked by:** 05a (JSON Structured Logging)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Request ID middleware implemented (generates UUID per request)
|
||||
- [ ] Request ID stored in FastAPI request state
|
||||
- [ ] Request ID included in all log entries within request context
|
||||
- [ ] Request ID exposed in response headers (`X-Request-ID`)
|
||||
- [ ] Request ID tests written (verify consistency across log entries)
|
||||
@@ -0,0 +1,12 @@
|
||||
# 05c: User ID Logging
|
||||
|
||||
**What to build:** User ID included in logs where applicable (authenticated requests).
|
||||
|
||||
**Blocked by:** 05b (Request ID Injection)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] User ID extracted from JWT token
|
||||
- [ ] User ID logged in authenticated request context
|
||||
- [ ] Anonymous users logged with placeholder ID
|
||||
- [ ] User ID tests written (verify user ID in logs for authenticated requests)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 05d: NTFY Alerts Integration
|
||||
|
||||
**What to build:** NTFY integration: API pushes errors/warnings to configurable topics.
|
||||
|
||||
**Blocked by:** 05c (User ID Logging)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] NTFY client initialized with API URL and authentication
|
||||
- [ ] Alert function implemented (`send_alert(topic, severity, message, context)`)
|
||||
- [ ] Severity levels implemented (info, warning, error, critical)
|
||||
- [ ] NTFY alerts sent for common events (DB failures, storage errors)
|
||||
- [ ] NTFY tests written (verify alert received in NTFY dashboard)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 06: Local Development Environment
|
||||
|
||||
**What to build:** Docker Compose setup with FastAPI (hot reload), PostgreSQL, and Adminer. Enables local development with full stack.
|
||||
|
||||
**Blocked by:** 03 (FastAPI Application Foundation)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Docker Compose file defines FastAPI, PostgreSQL, and Adminer services
|
||||
- [ ] FastAPI service includes hot reload (e.g., `--reload` flag or volumes)
|
||||
- [ ] PostgreSQL service configured with persistent volume
|
||||
- [ ] Adminer accessible at local port (e.g., `localhost:8080`)
|
||||
- [ ] Environment variables injected into FastAPI service
|
||||
- [ ] Docker Compose setup tested end-to-end (start → API available → DB queries → Adminer accessible)
|
||||
- [ ] Hot reload verified (code change triggers API reload without restart)
|
||||
@@ -0,0 +1,14 @@
|
||||
# 06a: Docker Compose Configuration
|
||||
|
||||
**What to build:** Docker Compose file defining FastAPI, PostgreSQL, and Adminer services.
|
||||
|
||||
**Blocked by:** 03a (Layered FastAPI App Structure)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `docker-compose.yml` defined with services: api, postgres, adminer
|
||||
- [ ] FastAPI service configured with hot reload (volumes, `--reload` flag)
|
||||
- [ ] PostgreSQL service configured with persistent volume
|
||||
- [ ] Adminer service configured (port, database connection)
|
||||
- [ ] Environment variables injected into FastAPI service
|
||||
- [ ] Docker Compose setup tested (start → API available → DB queries)
|
||||
@@ -0,0 +1,12 @@
|
||||
# 06b: Hot Reload Verification
|
||||
|
||||
**What to build:** Hot reload verified for FastAPI service in Docker Compose.
|
||||
|
||||
**Blocked by:** 06a (Docker Compose Configuration)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] FastAPI service configured for hot reload (e.g., `--reload` flag, volume mounts)
|
||||
- [ ] Code change triggers API reload without restart (verified via log output)
|
||||
- [ ] API responses reflect code changes after reload
|
||||
- [ ] Hot reload tested with multiple code changes (schema update, endpoint addition)
|
||||
@@ -0,0 +1,12 @@
|
||||
# 06c: Adminer Accessibility
|
||||
|
||||
**What to build:** Adminer accessible at local port for database inspection and queries.
|
||||
|
||||
**Blocked by:** 06a (Docker Compose Configuration)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Adminer service accessible at `localhost:8080`
|
||||
- [ ] Adminer connected to PostgreSQL service
|
||||
- [ ] Database schema visible in Adminer
|
||||
- [ ] Sample queries executed successfully in Adminer
|
||||
@@ -0,0 +1,15 @@
|
||||
# 07: CI/CD Pipeline
|
||||
|
||||
**What to build:** Gitea CI/CD workflows for build, test, push, and deploy. Auto-deploys staging on `main` branch; production on tags.
|
||||
|
||||
**Blocked by:** 01 (Infrastructure Setup), 05 (Observability Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Gitea CI/CD workflow for build (lint, type-check, test)
|
||||
- [ ] Gitea CI/CD workflow for push Docker image (buildx, caching)
|
||||
- [ ] Auto-deploy staging on `main` branch push
|
||||
- [ ] Auto-deploy production on tags (e.g., `v*`)
|
||||
- [ ] CI/CD workflows use `act_runner` (Gitea Actions compatible)
|
||||
- [ ] Deployment workflow includes health check verification
|
||||
- [ ] CI/CD logs integrated with NTFY alerts (failures reported)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 07a: Gitea CI/CD Build Workflow
|
||||
|
||||
**What to build:** Gitea CI/CD workflow for build (lint, type-check, test).
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `.gitea/workflows/build.yml` defined
|
||||
- [ ] Build workflow runs lint (e.g., `ruff`, `mypy`)
|
||||
- [ ] Build workflow runs tests (pytest)
|
||||
- [ ] Build workflow outputs test coverage report (optional)
|
||||
- [ ] Build workflow runs on push to `main` and feature branches
|
||||
@@ -0,0 +1,13 @@
|
||||
# 07b: Gitea CI/CD Push Workflow
|
||||
|
||||
**What to build:** Gitea CI/CD workflow for pushing Docker image (buildx, caching).
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Push workflow defined (`.gitea/workflows/push.yml`)
|
||||
- [ ] Docker image built with `buildx` (multi-platform if applicable)
|
||||
- [ ] Docker caching configured (build cache, layer caching)
|
||||
- [ ] Image pushed to container registry (Linode Container Registry or Docker Hub)
|
||||
- [ ] Image tag includes commit SHA and/or branch name
|
||||
@@ -0,0 +1,13 @@
|
||||
# 07c: Auto-Deploy Staging on Main
|
||||
|
||||
**What to build:** Auto-deploy staging on `main` branch push to Gitea.
|
||||
|
||||
**Blocked by:** 07a (Gitea CI/CD Build Workflow), 07b (Gitea CI/CD Push Workflow)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Deployment workflow triggered on push to `main` branch
|
||||
- [ ] Kubernetes deployment updated with new image tag
|
||||
- [ ] Rolling update applied (zero-downtime)
|
||||
- [ ] Health check verification after deployment
|
||||
- [ ] Rollback capability tested (manual and automatic on failure)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 07d: Auto-Deploy Production on Tags
|
||||
|
||||
**What to build:** Auto-deploy production on tags (e.g., `v*`) to Gitea.
|
||||
|
||||
**Blocked by:** 07a (Gitea CI/CD Build Workflow), 07b (Gitea CI/CD Push Workflow)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Deployment workflow triggered on tags matching `v*`
|
||||
- [ ] Production Kubernetes deployment updated with new image tag
|
||||
- [ ] Manual approval step (optional) before production deploy
|
||||
- [ ] Health check verification after deployment
|
||||
- [ ] Production deployment tested with sample tag (e.g., `v0.1.0`)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 08: Secrets Management
|
||||
|
||||
**What to build:** SOPS + age for encrypted secrets in Git. Age keys stored in Vaultwarden. CI/CD uses decrypted secrets during deploy.
|
||||
|
||||
**Blocked by:** 01 (Infrastructure Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] SOPS configured with age encryption
|
||||
- [ ] Secrets files created (e.g., `secrets.yaml`) and encrypted
|
||||
- [ ] Age public/private key pair generated
|
||||
- [ ] Age public key stored in Vaultwarden
|
||||
- [ ] CI/CD workflow decrypts secrets during deploy (e.g., `sops decrypt`)
|
||||
- [ ] Secrets injected into FastAPI and infrastructure (e.g., PostgreSQL credentials, NTFY API key)
|
||||
- [ ] Secrets rotation tested (new key pair, re-encrypt)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 08a: SOPS + Age Configuration
|
||||
|
||||
**What to build:** SOPS configured with age encryption for secrets management.
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] SOPS installed and configured
|
||||
- [ ] Age key pair generated (`age-keygen`)
|
||||
- [ ] SOPS encryption configured (`secrets.yaml` encrypted)
|
||||
- [ ] First secret added (e.g., `JWT_SECRET`) and encrypted
|
||||
- [ ] Decryption tested (`sops decrypt secrets.yaml`)
|
||||
@@ -0,0 +1,12 @@
|
||||
# 08b: Age Keys in Vaultwarden
|
||||
|
||||
**What to build:** Age public/private keys stored in Vaultwarden for secrets management.
|
||||
|
||||
**Blocked by:** 08a (SOPS + Age Configuration)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Age public key stored in Vaultwarden (notes field or attachment)
|
||||
- [ ] Age private key stored in Vaultwarden (notes field or attachment, encrypted)
|
||||
- [ ] Vaultwarden accessible from CI/CD (optional: API token)
|
||||
- [ ] Age keys retrieved from Vaultwarden for decryption in CI/CD
|
||||
@@ -0,0 +1,12 @@
|
||||
# 08c: CI/CD Secrets Injection
|
||||
|
||||
**What to build:** CI/CD workflow decrypts secrets and injects into FastAPI and infrastructure.
|
||||
|
||||
**Blocked by:** 08a (SOPS + Age Configuration)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] CI/CD workflow decrypts secrets during deploy (`sops decrypt`)
|
||||
- [ ] Secrets injected into FastAPI (environment variables)
|
||||
- [ ] Secrets injected into infrastructure (e.g., PostgreSQL credentials, NTFY API key)
|
||||
- [ ] Decryption tested in staging deployment
|
||||
@@ -0,0 +1,15 @@
|
||||
# 09: Testing Infrastructure
|
||||
|
||||
**What to build:** Pytest tests run against separate test database. Tests cover auth endpoints, health endpoint, and object storage workflows.
|
||||
|
||||
**Blocked by:** 02 (Database Schema & Migrations), 03 (FastAPI Application Foundation)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Pytest fixtures for `TestClient` configured
|
||||
- [ ] Test database (`hapi_test`) created and cleaned between test runs
|
||||
- [ ] Auth endpoint tests (token generation, validation, revocation)
|
||||
- [ ] Health endpoint tests (DB status, storage status)
|
||||
- [ ] Object storage workflow tests (upload → Linode → NextCloud → download)
|
||||
- [ ] Tests run in CI (staging and production deployments)
|
||||
- [ ] Test coverage reported (optional: thresholds for lines/functions)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 09a: Pytest Test Framework Setup
|
||||
|
||||
**What to build:** Pytest configured with test database (`hapi_test`), fixtures for `TestClient`.
|
||||
|
||||
**Blocked by:** 02b (Users & Auth Tokens Schema), 03a (Layered FastAPI App Structure)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Pytest installed and configured (`pytest.ini` or `pyproject.toml`)
|
||||
- [ ] Test database (`hapi_test`) created and cleaned between runs
|
||||
- [ ] Pytest fixtures: `TestClient`, `async_test_client`, `db_session`
|
||||
- [ ] First test suite created (e.g., `tests/test_health.py`)
|
||||
- [ ] Tests run locally and in CI
|
||||
@@ -0,0 +1,13 @@
|
||||
# 09b: Auth Endpoint Tests
|
||||
|
||||
**What to build:** Pytest tests for auth endpoints (token generation, validation, revocation).
|
||||
|
||||
**Blocked by:** 09a (Pytest Test Framework Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `/auth/login` tests (valid credentials, invalid credentials, rate limiting)
|
||||
- [ ] `/auth/logout` tests (valid token, revoked token)
|
||||
- [ ] Token generation tests (token structure, expiration)
|
||||
- [ ] Token validation tests (valid token, expired token, revoked token)
|
||||
- [ ] Auth tests run in CI
|
||||
@@ -0,0 +1,13 @@
|
||||
# 09c: Health Endpoint Tests
|
||||
|
||||
**What to build:** Pytest tests for health endpoint (DB status, storage status).
|
||||
|
||||
**Blocked by:** 09a (Pytest Test Framework Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] `/health` tests (status: healthy, degraded, unhealthy)
|
||||
- [ ] `/health/ready` tests (blocks on DB and storage)
|
||||
- [ ] `/health/live` tests (always returns healthy)
|
||||
- [ ] DB dependency test (connectivity, query test)
|
||||
- [ ] Storage dependency test (bucket access test)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 09d: Object Storage Workflow Tests
|
||||
|
||||
**What to build:** Pytest tests for object storage workflows (upload → Linode → NextCloud → download).
|
||||
|
||||
**Blocked by:** 09a (Pytest Test Framework Setup)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] Upload workflow tests (Linode storage, NextCloud mirror)
|
||||
- [ ] Download workflow tests (Linode retrieval)
|
||||
- [ ] Delete workflow tests (cleanup, retention policy)
|
||||
- [ ] Error handling tests (storage failures, retries)
|
||||
- [ ] End-to-end workflow test (full upload → download cycle)
|
||||
@@ -0,0 +1,15 @@
|
||||
# 10: MVP Integration & Validation
|
||||
|
||||
**What to build:** End-to-end validation of all MVP components. Verifies UptimeKuma polling `/health`, NTFY alerts, and all user stories are satisfied.
|
||||
|
||||
**Blocked by:** 03 (FastAPI Application Foundation), 04 (Object Storage Integration), 05 (Observability Setup), 06 (Local Development Environment), 07 (CI/CD Pipeline), 08 (Secrets Management), 09 (Testing Infrastructure)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] UptimeKuma polling `/health` endpoint verified (staging and production)
|
||||
- [ ] NTFY alerts received for errors/warnings (verified via NTFY dashboard)
|
||||
- [ ] All user stories from MVP-SPEC validated (e.g., JWT auth, rate limiting, migrations)
|
||||
- [ ] End-to-end flow tested: developer workflow (push → CI → deploy → health → alerts)
|
||||
- [ ] Local development environment validated (Docker Compose → FastAPI → Adminer)
|
||||
- [ ] MVP scope confirmed (WebSockets/GraphQL deferred, not blocking)
|
||||
- [ ] MVP release notes drafted (optional: published to Gitea release)
|
||||
@@ -0,0 +1,12 @@
|
||||
# 10a: UptimeKuma Health Polling
|
||||
|
||||
**What to build:** UptimeKuma configured to poll `/health` endpoint (staging and production).
|
||||
|
||||
**Blocked by:** 03d (Health Endpoint), 07c (Auto-Deploy Staging on Main), 07d (Auto-Deploy Production on Tags)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] UptimeKuma monitor configured for staging `/health`
|
||||
- [ ] UptimeKuma monitor configured for production `/health`
|
||||
- [ ] Health check alerts configured (failure threshold, recovery)
|
||||
- [ ] UptimeKuma dashboard verified (green status for staging/production)
|
||||
@@ -0,0 +1,12 @@
|
||||
# 10b: NTFY Alert Verification
|
||||
|
||||
**What to build:** NTFY alerts verified for errors/warnings (staging and production).
|
||||
|
||||
**Blocked by:** 05d (NTFY Alerts Integration), 07c (Auto-Deploy Staging on Main), 07d (Auto-Deploy Production on Tags)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] NTFY alerts received for staging (verified via NTFY dashboard)
|
||||
- [ ] NTFY alerts received for production (verified via NTFY dashboard)
|
||||
- [ ] Alert topics verified (e.g., "Database connection failures")
|
||||
- [ ] Alert severity levels verified (info, warning, error, critical)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 10c: MVP User Stories Validation
|
||||
|
||||
**What to build:** End-to-end validation of all user stories from MVP-SPEC.
|
||||
|
||||
**Blocked by:** 01a (Linode Infrastructure with Terraform), 01b (K8s StatefulSet), 02a (Alembic), 02b (Schema), 03a (FastAPI Structure), 03b (JWT), 03c (Rate Limiting), 03d (Health), 04a (Object Storage SDK), 04b (Upload), 04c (Download), 04d (NextCloud), 05a (Logging), 05b (Request ID), 05c (User ID), 05d (NTFY), 06a (Docker Compose), 06b (Hot Reload), 06c (Adminer), 07a (Build), 07b (Push), 07c (Deploy Staging), 07d (Deploy Prod), 08a (SOPS), 08b (Vaultwarden), 08c (Secrets Injection), 09a (Pytest), 09b (Auth Tests), 09c (Health Tests), 09d (Storage Tests), 10a (UptimeKuma), 10b (NTFY)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] All 30 user stories validated (verified via integration tests, manual testing)
|
||||
- [ ] Staging deployment validated (hot reload, health checks, alerts)
|
||||
- [ ] Production deployment validated (tag-based deploy, health checks, alerts)
|
||||
- [ ] Local development validated (Docker Compose → FastAPI → Adminer)
|
||||
- [ ] MVP scope confirmed (WebSockets/GraphQL deferred, not blocking)
|
||||
@@ -0,0 +1,13 @@
|
||||
# 10d: MVP Release Notes & Documentation
|
||||
|
||||
**What to build:** MVP release notes drafted and published; documentation updated.
|
||||
|
||||
**Blocked by:** 10a (UptimeKuma), 10b (NTFY), 10c (User Stories)
|
||||
|
||||
**Status:** ready-for-agent
|
||||
|
||||
- [ ] MVP release notes drafted (version, features, breaking changes)
|
||||
- [ ] Release notes published to Gitea release (`v0.1.0` or similar)
|
||||
- [ ] API documentation updated (OpenAPI `/docs`, README)
|
||||
- [ ] Infrastructure documentation updated (Terraform README)
|
||||
- [ ] Development documentation updated (Docker Compose setup, local dev guide)
|
||||
@@ -0,0 +1,111 @@
|
||||
# HAPI MVP Tickets
|
||||
|
||||
**Source:** [MVP-SPEC.md](../MVP-SPEC.md)
|
||||
|
||||
**Issue Tracker:** Gitea (https://git.bobbypalko.com/bobby/hapi)
|
||||
|
||||
**Triage Label:** `ready-for-agent`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
**Total Tickets:** 20 (expanded from 10 MVP tickets into fine-grained vertical slices)
|
||||
|
||||
Each ticket is a **tracer-bullet**: cuts vertically through layers (schema, API, tests, infrastructure) and delivers end-to-end behavior.
|
||||
|
||||
---
|
||||
|
||||
## Tickets
|
||||
|
||||
### Infrastructure
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 01a | Linode Infrastructure with Terraform | — | Linode: PostgreSQL, Object Storage, networking |
|
||||
| 01b | Kubernetes StatefulSet for PostgreSQL | 01a | K8s StatefulSet for production PostgreSQL |
|
||||
|
||||
### Database
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 02a | Alembic Migration Framework | 01a | Alembic configured with additive migrations |
|
||||
| 02b | Users & Auth Tokens Schema | 02a | `users` and `auth_tokens` tables with JWT support |
|
||||
|
||||
### FastAPI
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 03a | Layered FastAPI App Structure | 02b | `models/`, `routers/`, `schemas/`, `services/`, `db/` |
|
||||
| 03b | JWT Authentication Middleware | 03a | Token validation, login/logout, multiple signers |
|
||||
| 03c | Rate Limiting Middleware | 03b | Per-token rate limits with headers |
|
||||
| 03d | Health Endpoint | 03c | `/health`, `/health/ready`, `/health/live` |
|
||||
|
||||
### Object Storage
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 04a | Linode Object Storage SDK | 01a | Linode SDK for uploads, downloads, deletes |
|
||||
| 04b | File Upload Endpoint | 04a | `/files/upload` endpoint with multipart support |
|
||||
| 04c | File Download Endpoint | 04b | `/files/{file_id}` endpoint with streaming |
|
||||
| 04d | NextCloud Backup Integration | 04a | Files mirrored to NextCloud after upload |
|
||||
|
||||
### Observability
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 05a | JSON Structured Logging | 03a | JSON logs with timestamp, level, message, context |
|
||||
| 05b | Request ID Injection | 05a | UUID per request, logged and in headers |
|
||||
| 05c | User ID Logging | 05b | User ID from JWT included in logs |
|
||||
| 05d | NTFY Alerts Integration | 05c | API pushes errors/warnings to NTFY topics |
|
||||
|
||||
### Local Dev
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 06a | Docker Compose Configuration | 03a | FastAPI, PostgreSQL, Adminer services |
|
||||
| 06b | Hot Reload Verification | 06a | Code changes trigger API reload |
|
||||
| 06c | Adminer Accessibility | 06a | Adminer at `localhost:8080` |
|
||||
|
||||
### CI/CD
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 07a | Gitea CI/CD Build Workflow | 01a | Lint, type-check, test |
|
||||
| 07b | Gitea CI/CD Push Workflow | 01a | Docker buildx, caching, push |
|
||||
| 07c | Auto-Deploy Staging on Main | 07a, 07b | Push to `main` triggers staging deploy |
|
||||
| 07d | Auto-Deploy Production on Tags | 07a, 07b | Tags `v*` trigger production deploy |
|
||||
|
||||
### Secrets
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 08a | SOPS + Age Configuration | 01a | Encrypted secrets in Git |
|
||||
| 08b | Age Keys in Vaultwarden | 08a | Public/private keys in Vaultwarden |
|
||||
| 08c | CI/CD Secrets Injection | 08a | Decrypt secrets, inject into app |
|
||||
|
||||
### Testing
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 09a | Pytest Test Framework Setup | 02b, 03a | Test DB, fixtures, `TestClient` |
|
||||
| 09b | Auth Endpoint Tests | 09a | Login, logout, token generation/validation |
|
||||
| 09c | Health Endpoint Tests | 09a | DB and storage dependency checks |
|
||||
| 09d | Object Storage Workflow Tests | 09a | Upload → Linode → NextCloud → download |
|
||||
|
||||
### MVP Integration
|
||||
|
||||
| # | Title | Blocked By | Summary |
|
||||
|---|-------|------------|---------|
|
||||
| 10a | UptimeKuma Health Polling | 03d, 07c, 07d | Staging/production health checks |
|
||||
| 10b | NTFY Alert Verification | 05d, 07c, 07d | Alerts verified for staging/production |
|
||||
| 10c | MVP User Stories Validation | All prior | All 30 user stories validated |
|
||||
| 10d | MVP Release Notes & Docs | 10a, 10b, 10c | Release notes, API docs, dev guide |
|
||||
|
||||
---
|
||||
|
||||
## Notes
|
||||
|
||||
- **Priority order:** Tickets are ordered by dependency (blockers first). Many tickets can run in parallel (e.g., Object Storage, CI/CD, and Secrets can all start after infrastructure).
|
||||
- **Frontier:** Work on tickets whose blockers are all closed/merged. At start, frontier includes: 01a, 02a, 03a, 04a, 05a, 06a, 07a, 08a, 09a.
|
||||
- **Wide refactor exceptions:** None in MVP scope; all tickets are tracer-bullet vertical slices.
|
||||
@@ -0,0 +1,39 @@
|
||||
# AGENTS.md
|
||||
|
||||
This file documents the architecture and domain model of this repository, intended for both human readers and AI agents.
|
||||
|
||||
## Agent skills
|
||||
|
||||
### Issue tracker
|
||||
|
||||
Issues are tracked in the Gitea instance at https://git.bobbypalko.com/bobby/hapi. Uses the `gt` CLI (Gitea's official CLI). Run `gt auth login -h https://git.bobbypalko.com` to authenticate. See `docs/agents/issue-tracker.md`.
|
||||
|
||||
### Triage labels
|
||||
|
||||
Five canonical triage roles mapped to labels: `needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-human`, `wontfix`. See `docs/agents/triage-labels.md`.
|
||||
|
||||
### Domain docs
|
||||
|
||||
Single-context layout: `GLOSSARY.md` at repo root and `docs/adr/` for architecture decisions. See `docs/agents/domain.md`.
|
||||
|
||||
### Infrastructure modules
|
||||
|
||||
The `infra/` directory contains Terraform configurations with these modules:
|
||||
|
||||
- `backend/` - Terraform state backend (Object Storage S3-compatible)
|
||||
- `postgres/` - LKE clusters for staging/production
|
||||
- `storage/` - Object Storage buckets for uploads and state
|
||||
- `network/` - Firewall rules for API (8000), PostgreSQL (5432), Adminer (8080)
|
||||
|
||||
See `infra/README.md` and `docs/adr/0002-linode-provider-v2-migration.md` for details.
|
||||
|
||||
## Provider Versions
|
||||
|
||||
### Linode Terraform Provider
|
||||
|
||||
**v2.0+** (current branch) - Migrated from v1 with breaking changes documented in ADR-0002. Key differences:
|
||||
|
||||
- Object Storage: `cluster` → `region`
|
||||
- Firewall: Updated format with `action`, `ipv4`, `ipv6`
|
||||
- LKE: `pools` → `pool`
|
||||
- Tags: Set format (`key=value`)
|
||||
@@ -1,13 +0,0 @@
|
||||
## Agent skills
|
||||
|
||||
### Issue tracker
|
||||
|
||||
Issues live on the self-hosted Gitea at git.bobbypalko.com (`bobby/hapi`), managed with the `gt` CLI. See `docs/agents/issue-tracker.md`.
|
||||
|
||||
### Triage labels
|
||||
|
||||
Default five-role vocabulary (`needs-triage`, `needs-info`, `ready-for-agent`, `ready-for-human`, `wontfix`). See `docs/agents/triage-labels.md`.
|
||||
|
||||
### Domain docs
|
||||
|
||||
Single-context: one root `GLOSSARY.md` plus `docs/adr/`. See `docs/agents/domain.md`.
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
# HAPI Glossary
|
||||
|
||||
## Core Concepts
|
||||
|
||||
### API
|
||||
The central service exposing HTTP endpoints for clients (humans, bots, frontend). Built with FastAPI, providing REST endpoints, JSON logs, and health checks.
|
||||
|
||||
### Environment
|
||||
An instance of the API serving requests. **Staging** mirrors production for testing; **Production** serves real users. Each has its own PostgreSQL database.
|
||||
|
||||
### Migration
|
||||
A versioned change to the database schema, managed by Alembic. Migrations are additive by default, with destructive changes behind flags.
|
||||
|
||||
### Secret
|
||||
A sensitive value (password, API key, token) stored encrypted. Managed via SOPS with age encryption, committed to Git alongside code.
|
||||
|
||||
### Object Storage
|
||||
A service for storing files (uploads, assets). We use Linode Object Storage as primary, with NextCloud as a backup destination.
|
||||
|
||||
### Health Check
|
||||
An endpoint (`/health`) that reports the API's operational status and dependency health (DB, object storage, etc.).
|
||||
|
||||
### Alert
|
||||
A notification sent to NTFY when an error or warning occurs. Includes severity, context, and details for quick triage.
|
||||
|
||||
## Modules
|
||||
|
||||
### Auth Module
|
||||
Handles user authentication via JWT tokens. Supports token-based rate limiting; extensible for OAuth2 and API keys.
|
||||
|
||||
### Router Module
|
||||
API endpoints grouped by domain (users, items, etc.). Each router is a self-contained module with its own schemas and service calls.
|
||||
|
||||
### Schema Module
|
||||
Pydantic models defining request/response shapes. Separated from routers to enable reuse and testing.
|
||||
|
||||
### Service Module
|
||||
Business logic separated from HTTP concerns. Services are testable in isolation and called by routers.
|
||||
|
||||
### DB Module
|
||||
Database connection and utility functions. Includes session management, connection pooling, and migration orchestration.
|
||||
|
||||
## Infrastructure
|
||||
|
||||
### Kubernetes Cluster
|
||||
Self-hosted Kubernetes for production and staging deployments. Uses StatefulSet for PostgreSQL.
|
||||
|
||||
### Terraform
|
||||
Infrastructure as code for Linode resources (VMs, PostgreSQL, Object Storage, LCR). State stored in Linode Object Storage with backend configuration.
|
||||
|
||||
### Terraform Backend
|
||||
Storage location for Terraform state files. Configured to use Linode Object Storage for remote state with S3-compatible API.
|
||||
|
||||
### Object Storage Bucket
|
||||
A container in Linode Object Storage for storing objects (files). We use separate buckets for uploads and Terraform state per environment.
|
||||
|
||||
### Firewall Rules
|
||||
Network access control rules that define which traffic is allowed to reach infrastructure components (API, PostgreSQL, Adminer).
|
||||
|
||||
### Gitea CI/CD
|
||||
Automated workflows for building, testing, and deploying the API. Uses act_runner for GitHub Actions-compatible workflows.
|
||||
|
||||
### Docker Compose
|
||||
Local development environment with FastAPI, PostgreSQL, and Adminer.
|
||||
|
||||
## Observability
|
||||
|
||||
### Structured Logging
|
||||
JSON-formatted logs for structured querying and analysis. Each log entry includes timestamp, level, message, and context.
|
||||
|
||||
### UptimeKuma
|
||||
Monitoring service that polls `/health` endpoint to track API availability.
|
||||
|
||||
### NTFY
|
||||
Push notification service for alerts. API sends error/warning notifications with configurable topics.
|
||||
|
||||
## Deployment
|
||||
|
||||
### Rollout
|
||||
Deployment of a new API version to an environment. Uses Kubernetes rolling updates for zero-downtime.
|
||||
|
||||
### Tagging
|
||||
Version tags (e.g., `v1.0.0`) trigger production deployments. Staging deploys from `main` branch.
|
||||
|
||||
## Future Considerations
|
||||
|
||||
### WebSockets
|
||||
Real-time communication layer for frontend. Not included in MVP; ready for later addition.
|
||||
|
||||
### GraphQL
|
||||
Alternative query layer for complex frontend queries. Not included in MVP; REST is sufficient initially.
|
||||
|
||||
### NextCloud Backup
|
||||
Secondary storage for uploads, mirroring Linode Object Storage to NextCloud for redundancy.
|
||||
+226
@@ -0,0 +1,226 @@
|
||||
# HAPI MVP Spec
|
||||
|
||||
## Problem Statement
|
||||
|
||||
I'm building a personal API project called **HAPI** (Home API). It needs to be a flexible, extensible foundation for various domains (fitness, finance, maintenance, etc.) that I and my family will use. The system should:
|
||||
|
||||
- Start simple but scale as features grow
|
||||
- Be easy to develop locally and deploy to cloud
|
||||
- Include observability (logging, alerts, health checks)
|
||||
- Support automation (cron jobs, webhooks)
|
||||
- Store files (uploads to Linode Object Storage + NextCloud backup)
|
||||
- Be testable and maintainable as a solo developer
|
||||
|
||||
Currently, the repository is empty (just `.git`), so we're building from scratch.
|
||||
|
||||
---
|
||||
|
||||
## Solution
|
||||
|
||||
Build an MVP with:
|
||||
|
||||
1. **Layered FastAPI Application**: Modular structure (`models/`, `routers/`, `schemas/`, `services/`, `db/`) with JWT auth and rate limiting.
|
||||
|
||||
2. **Database**: PostgreSQL with Alembic migrations, separate databases for staging and production.
|
||||
|
||||
3. **Infrastructure**: Terraform-managed Linode resources (VMs, PostgreSQL, Object Storage, LCR) and Kubernetes StatefulSet for PostgreSQL.
|
||||
|
||||
4. **Observability**: JSON structured logging with NTFY alerts, UptimeKuma polling of `/health`.
|
||||
|
||||
5. **CI/CD**: Gitea Actions with `act_runner` for build, test, and deploy workflows.
|
||||
|
||||
6. **Local Dev**: Docker Compose with FastAPI (hot reload), PostgreSQL, and Adminer.
|
||||
|
||||
The seam for testing is at the FastAPI application level—tests cross the HTTP interface to verify behavior end-to-end.
|
||||
|
||||
---
|
||||
|
||||
## User Stories
|
||||
|
||||
1. As a developer, I want a FastAPI application with a layered structure, so that I can keep concerns separated and scale the codebase cleanly.
|
||||
|
||||
2. As a developer, I want JWT authentication for API access, so that only authorized users and bots can use the API.
|
||||
|
||||
3. As a developer, I want rate limiting on API endpoints, so that I can protect the system from abuse or accidental overuse by bots.
|
||||
|
||||
4. As a developer, I want PostgreSQL with migrations, so that schema changes are tracked and reversible.
|
||||
|
||||
5. As a developer, I want separate staging and production databases, so that I can test changes safely before releasing to production.
|
||||
|
||||
6. As a developer, I want a `/health` endpoint, so that UptimeKuma can monitor API availability.
|
||||
|
||||
7. As a developer, I want dependency checks in `/health` (DB, object storage), so that I can see which components are down vs. just the API.
|
||||
|
||||
8. As a developer, I want JSON structured logging, so that logs are queryable and analyzable.
|
||||
|
||||
9. As a developer, I want NTFY alerts for errors and warnings, so that I get notified in real-time when something breaks.
|
||||
|
||||
10. As a developer, I want file upload support (Linode Object Storage + NextCloud backup), so that I can store documents, images, or other assets.
|
||||
|
||||
11. As a developer, I want Docker Compose for local development, so that I can run the full stack locally with hot reload.
|
||||
|
||||
12. As a developer, I want Adminer for local database access, so that I can inspect and query the database without extra tooling.
|
||||
|
||||
13. As a developer, I want Terraform for infrastructure provisioning, so that my cloud resources are versioned and reproducible.
|
||||
|
||||
14. As a developer, I want Kubernetes StatefulSet for PostgreSQL, so that I can learn about Kubernetes storage and stateful workloads.
|
||||
|
||||
15. As a developer, I want Gitea CI/CD with automated deployment, so that new code is deployed automatically to staging.
|
||||
|
||||
16. As a developer, I want staging to deploy automatically on `main` branch, so that I can test changes quickly.
|
||||
|
||||
17. As a developer, I want production to deploy on tags, so that I can control releases manually.
|
||||
|
||||
18. As a developer, I want SOPS + age for secrets management, so that sensitive values are encrypted in Git.
|
||||
|
||||
19. As a developer, I want to store SOPS age keys in Vaultwarden, so that I have one place for all secrets.
|
||||
|
||||
20. As a developer, I want Gitea Actions to build Docker images with `buildx`, so that I have full control over the build process.
|
||||
|
||||
21. As a developer, I want Pytest tests with a separate test database, so that I can test API endpoints without affecting dev data.
|
||||
|
||||
22. As a developer, I want a simple branching strategy (`main` + feature branches), so that I can keep development straightforward.
|
||||
|
||||
23. As a developer, I want cron/webhook hooks for automation, so that I can trigger tasks or external actions.
|
||||
|
||||
24. As a developer, I want a lean MVP scope, so that I can focus on core functionality first.
|
||||
|
||||
25. As a developer, I want breadth-first learning, so that I gain exposure to many tools before diving deep.
|
||||
|
||||
26. As a user (myself), I want to access the API from my phone or laptop, so that I can use it on the go.
|
||||
|
||||
27. As a user (my wife), I want a simple interface for her dashboard, so that she can view and manage shared data.
|
||||
|
||||
28. As a bot developer, I want API keys for bot access, so that each bot has isolated permissions.
|
||||
|
||||
29. As a developer, I want to expand the API with new modules (fitness, finance, maintenance), so that I can extend functionality over time.
|
||||
|
||||
30. As a developer, I want to add WebSockets later, so that real-time features don't block the MVP.
|
||||
|
||||
31. As a developer, I want to add GraphQL later, so that I can evaluate if it's needed for frontend complexity.
|
||||
|
||||
32. As a developer, I want to scale infrastructure as needed, so that I can handle more users or data without rework.
|
||||
|
||||
---
|
||||
|
||||
## Implementation Decisions
|
||||
|
||||
### Module Structure
|
||||
|
||||
- **Layered Architecture**: Modules are organized by layer (`models/`, `routers/`, `schemas/`, `services/`, `db/`) rather than domain, to keep the codebase simple for a solo developer.
|
||||
|
||||
- **FastAPI as the Core Framework**: Chosen for its async support, automatic OpenAPI docs, and ease of testing.
|
||||
|
||||
### Database
|
||||
|
||||
- **PostgreSQL with Alembic**: Alembic handles migrations with additive-by-default changes; destructive changes are behind flags.
|
||||
|
||||
- **Separate Databases for Environments**: Staging and production have separate databases on possibly shared instances to keep data isolated.
|
||||
|
||||
- **StatefulSet for Production**: Kubernetes StatefulSet for PostgreSQL provides learnable infrastructure with persistent storage.
|
||||
|
||||
### Authentication
|
||||
|
||||
- **JWT Tokens**: Simple token-based auth with a secret key (stored in Vaultwarden). Designed to support multiple signers or OAuth later.
|
||||
|
||||
- **Token-Based Rate Limiting**: Per-token limits in FastAPI middleware; extensible to Redis or Traefik later.
|
||||
|
||||
### Observability
|
||||
|
||||
- **JSON Structured Logging**: Logs include timestamp, level, message, and context (e.g., request ID, user ID).
|
||||
|
||||
- **NTFY Alerts**: API pushes errors/warnings to NTFY with severity and topic (e.g., "Database connection failures").
|
||||
|
||||
- **Health Endpoint**: `/health` checks DB and object storage; `/health/ready` and `/health/live` added later if needed.
|
||||
|
||||
### File Storage
|
||||
|
||||
- **Linode Object Storage Primary**: S3-compatible for uploads; integrated via Python SDK.
|
||||
|
||||
- **NextCloud Backup**: Secondary storage for uploads, mirrored from Linode for redundancy.
|
||||
|
||||
### CI/CD
|
||||
|
||||
- **Gitea + act_runner**: Uses GitHub Actions-compatible workflows for build, test, push, and deploy.
|
||||
|
||||
- **Auto-Deploy Staging**: On `main` branch push; manual/tag-triggered for production.
|
||||
|
||||
- **Docker buildx**: Full control over image builds with caching and multi-platform support.
|
||||
|
||||
### Testing
|
||||
|
||||
- **Pytest with Separate Test DB**: Tests run against `hapi_test` database to avoid affecting dev data.
|
||||
|
||||
- **Test Through HTTP Interface**: Tests call API endpoints (not internal functions) to verify real-world behavior.
|
||||
|
||||
### Secrets Management
|
||||
|
||||
- **SOPS + age**: Encrypted files in Git; age keys stored in Vaultwarden.
|
||||
|
||||
### Future-Ready
|
||||
|
||||
- **WebSockets Later**: Ready for future frontend; not included in MVP.
|
||||
|
||||
- **GraphQL Optional**: REST-only for now; GraphQL can be added as a separate module.
|
||||
|
||||
---
|
||||
|
||||
## Testing Decisions
|
||||
|
||||
### What Makes a Good Test
|
||||
|
||||
- Tests verify **external behavior** (HTTP responses, side effects) not implementation details (e.g., which service method was called).
|
||||
|
||||
- Tests cover **edge cases** (auth failures, DB down, storage errors) and **happy paths**.
|
||||
|
||||
- Tests are **fast** (in-memory DB or test fixtures where possible) and **isolated** (test DB per test run).
|
||||
|
||||
### Modules to Test
|
||||
|
||||
- **API Endpoints**: Pytest fixtures for `TestClient`; test all routers.
|
||||
|
||||
- **Auth Module**: Token generation, validation, and revocation.
|
||||
|
||||
- **Health Endpoint**: DB and storage dependency checks.
|
||||
|
||||
- **Logging**: JSON output format and context fields.
|
||||
|
||||
- **Object Storage**: Upload/download/cleanup workflows.
|
||||
|
||||
### Prior Art
|
||||
|
||||
- FastAPI's own testing guide (test client, fixtures).
|
||||
|
||||
- Alembic's migration testing patterns.
|
||||
|
||||
- NTFY API for alert payload testing.
|
||||
|
||||
---
|
||||
|
||||
## Out of Scope
|
||||
|
||||
- **WebSockets**: Real-time features for frontend; added later.
|
||||
|
||||
- **GraphQL Layer**: Optional alternative to REST; added if frontend complexity grows.
|
||||
|
||||
- **OAuth2 Providers**: Auth is JWT-only for MVP; OAuth can be added later.
|
||||
|
||||
- **Advanced PostgreSQL Features**: TimescaleDB, PostGIS, etc.; added as needed.
|
||||
|
||||
- **Multi-Region Deployment**: Single-region for MVP; scaling out later.
|
||||
|
||||
- **Advanced Monitoring**: Prometheus/Grafana for metrics; NTFY/structured logs suffice for MVP.
|
||||
|
||||
- **CI/CD Advanced Features**: Automated changelog generation, release notes; simple deploy for MVP.
|
||||
|
||||
---
|
||||
|
||||
## Further Notes
|
||||
|
||||
- **Learning Focus**: The design prioritizes breadth-first learning (Terraform, Kubernetes, SOPS, etc.) while keeping the MVP lean.
|
||||
|
||||
- **Cost Flexibility**: Since cloud costs aren't a concern, we favor robust setups (separate DBs, object storage redundancy) over minimal cost.
|
||||
|
||||
- **Extensibility**: Modules are designed to be added incrementally (fitness, finance, maintenance) without refactoring.
|
||||
|
||||
- **Tooling Choices**: Tools are selected for learning value (e.g., StatefulSet for PostgreSQL over managed DBs) and ease of use (SOPS over HashiCorp Vault for secrets).
|
||||
@@ -0,0 +1,59 @@
|
||||
# ADR Tools Configuration
|
||||
|
||||
## Directory
|
||||
adr-dir = docs/adr
|
||||
|
||||
## Template
|
||||
adr-template = """
|
||||
# ADR-{{counter}}: {{title}}
|
||||
|
||||
## Context
|
||||
|
||||
{{context}}
|
||||
|
||||
## Decision
|
||||
|
||||
{{decision}}
|
||||
|
||||
## Status
|
||||
|
||||
{{status}}
|
||||
|
||||
## Consequences
|
||||
|
||||
{{consequences}}
|
||||
|
||||
## References
|
||||
|
||||
{{references}}
|
||||
"""
|
||||
|
||||
## Author
|
||||
adr-author = "bobby"
|
||||
|
||||
## Date Format
|
||||
adr-date-format = "2006-01-02"
|
||||
|
||||
## Prefix
|
||||
adr-prefix = "adr-"
|
||||
|
||||
## Suffix
|
||||
adr-suffix = ".md"
|
||||
|
||||
## Template Directory
|
||||
adr-template-dir = docs/adr/templates
|
||||
|
||||
## New Directory
|
||||
adr-new-dir = docs/adr
|
||||
|
||||
## View Command
|
||||
adr-view-command = "gt view"
|
||||
|
||||
## View URL Format
|
||||
adr-view-url-format = "https://git.bobbypalko.com/bobby/hapi/blob/main/{{path}}"
|
||||
|
||||
## Edit Command
|
||||
adr-edit-command = "gt edit"
|
||||
|
||||
## Edit URL Format
|
||||
adr-edit-url-format = "https://git.bobbypalko.com/bobby/hapi/edit/main/{{path}}"
|
||||
@@ -0,0 +1,151 @@
|
||||
# ADR-0001: Linode Infrastructure with Terraform
|
||||
|
||||
## Context
|
||||
|
||||
We need to provision infrastructure on Linode for the HAPI project. This includes PostgreSQL database instances for staging and production, Object Storage buckets for uploads and Terraform state, and networking with firewall rules for API, PostgreSQL, and Adminer access.
|
||||
|
||||
Previously, infrastructure was provisioned manually via Linode dashboard CLI or planned for future setup. With HAPI MVP scope including infrastructure as a core component, we need a repeatable, version-controlled approach.
|
||||
|
||||
### Options Considered
|
||||
|
||||
1. **Manual provisioning** - Use Linode dashboard/CLI directly
|
||||
- Pros: Quick to get started, no tooling overhead
|
||||
- Cons: Not repeatable, hard to track changes, difficult to reproduce
|
||||
|
||||
2. **Terraform** - Infrastructure as Code with Linode provider
|
||||
- Pros: Declarative, state management, reusable modules, multi-environment support
|
||||
- Cons: Learning curve, state file management
|
||||
|
||||
3. **Ansible** - Configuration management focused on VMs
|
||||
- Pros: Powerful for configuration, good for stateful workloads
|
||||
- Cons: More complex for infrastructure provisioning, less Linode-native
|
||||
|
||||
## Decision
|
||||
|
||||
We chose **Terraform** because:
|
||||
|
||||
1. **Declarative infrastructure** - Clear, versionable infrastructure definitions
|
||||
2. **Built-in state management** - Tracks resource state with remote backend support
|
||||
3. **Linode provider maturity** - Well-maintained official provider with good coverage
|
||||
4. **Modularity** - Resources naturally organize into logical modules (postgres, storage, network)
|
||||
5. **CI/CD ready** - Terraform workflows integrate cleanly with Gitea Actions
|
||||
|
||||
## Status
|
||||
|
||||
**Accepted** - Implementation complete.
|
||||
|
||||
## Implementation
|
||||
|
||||
### Directory Structure
|
||||
|
||||
```
|
||||
infra/
|
||||
├── backend/ # Terraform state backend configuration
|
||||
├── postgres/ # PostgreSQL database instances
|
||||
├── storage/ # Object Storage buckets
|
||||
├── network/ # Firewall rules
|
||||
├── main.tf # Main orchestration file
|
||||
├── providers.tf # Provider configurations
|
||||
├── variables.tf # Common variables
|
||||
├── outputs.tf # Common outputs
|
||||
└── README.md # Infrastructure documentation
|
||||
```
|
||||
|
||||
### Module Details
|
||||
|
||||
#### Backend (`infra/backend/`)
|
||||
- Terraform state stored in Linode Object Storage
|
||||
- S3-compatible API for state access
|
||||
- Environment-specific state buckets
|
||||
- Provides backend configuration for main Terraform
|
||||
|
||||
#### PostgreSQL (`infra/postgres/`)
|
||||
- LKE (Linode Kubernetes Engine) clusters for staging and production
|
||||
- Configurable pool sizes (2 for staging, 3 for production)
|
||||
- Separate database names (`hapi_staging`, `hapi_production`)
|
||||
- Random password generation for database access
|
||||
|
||||
#### Object Storage (`infra/storage/`)
|
||||
- Upload buckets for staging and production
|
||||
- Terraform state buckets for each environment
|
||||
- S3-compatible API configuration
|
||||
- Bucket policies for access control
|
||||
|
||||
#### Networking (`infra/network/`)
|
||||
- Firewall with rules for:
|
||||
- API: port 8000 (from anywhere)
|
||||
- PostgreSQL: port 5432 (internal networks)
|
||||
- Adminer: port 8080 (from anywhere)
|
||||
- Inbound and outbound rules
|
||||
- Environment-specific firewall labels
|
||||
|
||||
### Outputs
|
||||
|
||||
All modules export standardized outputs:
|
||||
- **PostgreSQL**: endpoint, port, database, username, password, pool_size
|
||||
- **Object Storage**: endpoint, access_key, secret_key, bucket names
|
||||
- **Firewall**: rules configuration, firewall ID and label
|
||||
- **Terraform Backend**: bucket, key, region, endpoint configuration
|
||||
|
||||
### Configuration
|
||||
|
||||
Environment variables are used for credentials (not committed to Git):
|
||||
- `LINODE_TOKEN`: Linode API token
|
||||
- `OBJECT_STORAGE_ACCESS_KEY`: Object Storage access key
|
||||
- `OBJECT_STORAGE_SECRET_KEY`: Object Storage secret key
|
||||
|
||||
### Makefile Commands
|
||||
|
||||
```bash
|
||||
make init # Initialize Terraform
|
||||
make plan # Generate plan
|
||||
make apply # Apply changes (ENV=staging|production)
|
||||
make destroy # Destroy infrastructure
|
||||
make output # Show outputs
|
||||
```
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
|
||||
- **Reproducibility** - Infrastructure can be recreated from code
|
||||
- **Version control** - Infrastructure changes tracked in Git
|
||||
- **CI/CD ready** - Terraform workflows integrate with Gitea Actions
|
||||
- **Multi-environment support** - Clean separation between staging and production
|
||||
- **Documentation** - Outputs and README provide clear understanding
|
||||
|
||||
### Negative
|
||||
|
||||
- **Learning curve** - Team needs to learn Terraform syntax and concepts
|
||||
- **State management** - Requires careful state file handling
|
||||
- **Provider dependencies** - Linode provider updates may be needed
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. Complete Terraform implementation
|
||||
2. Set up CI/CD pipeline for infrastructure changes
|
||||
3. Document deployment process
|
||||
4. Create runbooks for common operations (scaling, backups, troubleshooting)
|
||||
5. Set up monitoring for infrastructure resources
|
||||
|
||||
## Provider Versions
|
||||
|
||||
### Linode Terraform Provider v2
|
||||
|
||||
ADR-0002 documents the migration from provider v1 to v2, which is implemented in the current branch. Key changes include:
|
||||
|
||||
- Object Storage `cluster` → `region` attribute
|
||||
- Firewall rules updated to v2 format with `action`, `ipv4`, `ipv6`
|
||||
- LKE `pools` → `pool`
|
||||
- Tags converted to set format
|
||||
|
||||
See [`0002-linode-provider-v2-migration.md`](./0002-linode-provider-v2-migration.md) for full details.
|
||||
|
||||
## References
|
||||
|
||||
- [Issue 1: Linode Infrastructure with Terraform](../../issues/1)
|
||||
- [ADR-0002: Linode Provider v2 Migration](./0002-linode-provider-v2-migration.md)
|
||||
- [Linode Terraform Provider v2.0 Release](https://github.com/linode/terraform-provider-linode/releases/tag/v2.0.0)
|
||||
- [Linode Provider Migration Guide](https://registry.terraform.io/providers/linode/linode/latest/docs/guides/version-2-upgrade)
|
||||
- [Terraform Best Practices](https://developer.hashicorp.com/terraform/tutorials/best-practices)
|
||||
- [HAPI MVP Spec](../../MVP-SPEC.md)
|
||||
@@ -0,0 +1,174 @@
|
||||
# Linode Terraform Provider v2 Quick Reference
|
||||
|
||||
This guide covers the key differences when working with Linode Provider v2.
|
||||
|
||||
## Object Storage
|
||||
|
||||
### v1 → v2 Changes
|
||||
|
||||
| v1 | v2 |
|
||||
|---|---|
|
||||
| `cluster = var.linode_object_storage_cluster` | `region = var.linode_object_storage_cluster` |
|
||||
| `linode_object_storage_cluster` resource | Removed - cluster is implicit |
|
||||
|
||||
### Example
|
||||
|
||||
```hcl
|
||||
# v1
|
||||
resource "linode_object_storage_bucket" "uploads" {
|
||||
cluster = var.linode_object_storage_cluster
|
||||
# ...
|
||||
}
|
||||
|
||||
# v2
|
||||
resource "linode_object_storage_bucket" "uploads" {
|
||||
region = var.linode_object_storage_cluster
|
||||
# ...
|
||||
}
|
||||
```
|
||||
|
||||
## Firewall Rules
|
||||
|
||||
### v1 → v2 Changes
|
||||
|
||||
| v1 | v2 |
|
||||
|---|---|
|
||||
| `cidrs = ["0.0.0.0/0"]` | `ipv4 = ["0.0.0.0/0"]`, `ipv6 = ["::/0"]` |
|
||||
| `direction = "inbound"` | `action = "ACCEPT"` or `action = "DROP"` |
|
||||
| `protocol = "tcp"` | `protocol = "TCP"` (uppercase) |
|
||||
| `ports = "8000"` | `ports = "8000"` (same) |
|
||||
|
||||
### Example
|
||||
|
||||
```hcl
|
||||
# v1
|
||||
resource "linode_firewall_rule" "api" {
|
||||
direction = "inbound"
|
||||
protocol = "tcp"
|
||||
ports = "8000"
|
||||
cidrs = ["0.0.0.0/0", "::/0"]
|
||||
}
|
||||
|
||||
# v2
|
||||
resource "linode_firewall" "hapi" {
|
||||
inbound {
|
||||
action = "ACCEPT"
|
||||
protocol = "TCP"
|
||||
ports = "8000"
|
||||
ipv4 = ["0.0.0.0/0"]
|
||||
ipv6 = ["::/0"]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## LKE Clusters
|
||||
|
||||
### v1 → v2 Changes
|
||||
|
||||
| v1 | v2 |
|
||||
|---|---|
|
||||
| `pools { ... }` | `pool { ... }` |
|
||||
| `tags = { Environment = "staging" }` | `tags = toset(["Environment=staging"])` |
|
||||
|
||||
### Example
|
||||
|
||||
```hcl
|
||||
# v1
|
||||
resource "linode_lke_cluster" "postgres" {
|
||||
pools {
|
||||
count = 2
|
||||
type = "g6-standard-4"
|
||||
}
|
||||
tags = {
|
||||
Environment = "staging"
|
||||
}
|
||||
}
|
||||
|
||||
# v2
|
||||
resource "linode_lke_cluster" "postgres" {
|
||||
pool {
|
||||
count = 2
|
||||
type = "g6-standard-4"
|
||||
}
|
||||
tags = toset([
|
||||
for k, v in { Environment = "staging" } : "${k}=${v}"
|
||||
])
|
||||
}
|
||||
```
|
||||
|
||||
## Tags
|
||||
|
||||
### v1 → v2 Changes
|
||||
|
||||
- **v1**: Map format `{ key = "value" }`
|
||||
- **v2**: Set of strings `["key=value"]`
|
||||
|
||||
### Conversion
|
||||
|
||||
```hcl
|
||||
# v1
|
||||
tags = {
|
||||
Environment = "staging"
|
||||
Project = "hapi"
|
||||
}
|
||||
|
||||
# v2
|
||||
tags = toset([
|
||||
"Environment=staging",
|
||||
"Project=hapi"
|
||||
])
|
||||
|
||||
# Dynamic conversion
|
||||
tags = toset([
|
||||
for k, v in var.tags : "${k}=${v}"
|
||||
])
|
||||
```
|
||||
|
||||
## Common Patterns
|
||||
|
||||
### Environment-Specific Resources
|
||||
|
||||
```hcl
|
||||
# Firewall with environment suffix
|
||||
resource "linode_firewall" "hapi" {
|
||||
label = "hapi-firewall-${var.environment}"
|
||||
}
|
||||
|
||||
# Bucket with environment suffix
|
||||
resource "linode_object_storage_bucket" "uploads" {
|
||||
label = "hapi-uploads-${var.environment}"
|
||||
}
|
||||
```
|
||||
|
||||
### Provider Configuration
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
linode = {
|
||||
source = "linode/linode"
|
||||
version = "~> 2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "linode" {
|
||||
token = var.linode_token
|
||||
}
|
||||
```
|
||||
|
||||
## Migration Checklist
|
||||
|
||||
- [ ] Update provider version constraint to `~> 2.0`
|
||||
- [ ] Replace `cluster` with `region` on Object Storage buckets
|
||||
- [ ] Remove `linode_object_storage_cluster` resource if present
|
||||
- [ ] Convert firewall rules to v2 format
|
||||
- [ ] Update LKE `pools` → `pool`
|
||||
- [ ] Convert tags from map to set format
|
||||
- [ ] Update firewall labels to include environment suffix
|
||||
|
||||
## References
|
||||
|
||||
- [Linode Provider v2.0 Release](https://github.com/linode/terraform-provider-linode/releases/tag/v2.0.0)
|
||||
- [Migration Guide](https://registry.terraform.io/providers/linode/linode/latest/docs/guides/version-2-upgrade)
|
||||
- [ADR-0002](../docs/adr/0002-linode-provider-v2-migration.md)
|
||||
@@ -0,0 +1,156 @@
|
||||
# ADR-0002: Linode Provider v2 Migration
|
||||
|
||||
## Context
|
||||
|
||||
The Linode Terraform provider released version 2.0 with significant breaking changes that affect our infrastructure configuration. This ADR documents the migration decisions.
|
||||
|
||||
### Provider v1 vs v2 Key Differences
|
||||
|
||||
| Change | Provider v1 | Provider v2 |
|
||||
|--------|-------------|-------------|
|
||||
| Object Storage cluster resource | `linode_object_storage_cluster` (optional) | Removed - cluster specified via `region` |
|
||||
| Object Storage bucket attribute | `cluster` | `region` |
|
||||
| Firewall rules format | List of objects with `cidrs` | Object with `ipv4`/`ipv6` and `action` |
|
||||
| Firewall rule attributes | `direction`, `protocol`, `ports`, `cidrs` | `action`, `protocol`, `ports`, `ipv4`, `ipv6` |
|
||||
| LKE pool attribute | `pools` | `pool` |
|
||||
| LKE tags format | Map with `Environment = value` | Set of `key=value` strings |
|
||||
|
||||
### Existing Infrastructure (v1)
|
||||
|
||||
The original implementation (ADR-0001) used:
|
||||
- `linode_object_storage_cluster` resource for Object Storage cluster
|
||||
- `cluster` attribute on bucket resources
|
||||
- List-based firewall rules with `cidrs`
|
||||
- `pools` block for LKE clusters
|
||||
- Map-based tags
|
||||
|
||||
### Trigger for Migration
|
||||
|
||||
- Linode provider v2 became stable and widely adopted
|
||||
- Newer features and bug fixes only available in v2
|
||||
- Consistency with Linode's evolving API
|
||||
|
||||
## Decision
|
||||
|
||||
We will migrate all infrastructure modules to use **Linode provider v2.0+** (`~> 2.0`).
|
||||
|
||||
### Migration Approach
|
||||
|
||||
1. **Incremental rollout** - Update modules one at a time
|
||||
2. **Backward-compatible variables** - Keep variable names stable, update usage internally
|
||||
3. **Documentation** - Document v2-specific patterns and differences
|
||||
|
||||
### What Stays the Same
|
||||
|
||||
- Module structure (postgres/, storage/, network/, backend/)
|
||||
- Variable names and common patterns
|
||||
- Output structure and naming
|
||||
- Environment separation (staging/production)
|
||||
|
||||
## Status
|
||||
|
||||
**Accepted** - Migration implemented in `feat/01a-linode-terraform-cleanup` branch.
|
||||
|
||||
## Implementation
|
||||
|
||||
### Changes by Module
|
||||
|
||||
#### Backend (`infra/backend/`)
|
||||
|
||||
**Changes:**
|
||||
- Updated provider version constraint to `~> 2.0`
|
||||
- Object Storage bucket configuration updated for v2 API
|
||||
|
||||
#### PostgreSQL (`infra/postgres/`)
|
||||
|
||||
**Changes:**
|
||||
- Provider v2 constraint added to `terraform` block
|
||||
- `cluster` → `region` on `linode_object_storage_bucket`
|
||||
- `pools` → `pool` on `linode_lke_cluster`
|
||||
- Tags converted from map to set of `key=value` strings
|
||||
- Environment variable added to module
|
||||
|
||||
#### Object Storage (`infra/storage/`)
|
||||
|
||||
**Changes:**
|
||||
- Provider v2 constraint added to `terraform` block
|
||||
- Removed `linode_object_storage_cluster` resource
|
||||
- `cluster` → `region` on bucket resources
|
||||
- Removed `depends_on` referencing removed cluster resource
|
||||
- Removed bucket policy configurations (simplified approach)
|
||||
|
||||
#### Networking (`infra/network/`)
|
||||
|
||||
**Changes:**
|
||||
- Provider v2 constraint added to `terraform` block
|
||||
- Firewall rules updated to v2 format:
|
||||
- `cidrs` → `ipv4`/`ipv6`
|
||||
- Added `action` field (`ACCEPT`/`DROP`)
|
||||
- `protocol` now uppercase (`TCP`/`UDP`/`ICMP`)
|
||||
- Environment suffix added to firewall labels
|
||||
- Tags converted to set format
|
||||
- `linode_object_storage_cluster` variable added
|
||||
|
||||
### Variable Changes
|
||||
|
||||
**Added to `infra/variables.tf`:**
|
||||
```hcl
|
||||
variable "object_storage_access_key" {
|
||||
description = "Linode Object Storage access key for backend state storage"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "object_storage_secret_key" {
|
||||
description = "Linode Object Storage secret key for backend state storage"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "linode_object_storage_cluster" {
|
||||
description = "Linode Object Storage cluster for backend state storage"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
```
|
||||
|
||||
**Added to module variables:**
|
||||
- `environment` variable added to `postgres/variables.tf` and `storage/variables.tf`
|
||||
|
||||
## Consequences
|
||||
|
||||
### Positive
|
||||
|
||||
- **Future-proof** - Using stable, actively maintained provider version
|
||||
- **Simplified architecture** - Removed `linode_object_storage_cluster` resource
|
||||
- **More consistent API** - v2 aligns with Linode's current API conventions
|
||||
- **Better tagging** - Set-based tags provide more flexibility
|
||||
|
||||
### Negative
|
||||
|
||||
- **Breaking changes** - Existing v1 configurations require updates
|
||||
- **Documentation lag** - Need to update docs for v2 patterns
|
||||
- **Learning curve** - Team needs to understand v2 differences
|
||||
|
||||
### Migration Checklist
|
||||
|
||||
- [x] Provider version updated in all modules
|
||||
- [x] Object Storage bucket `cluster` → `region` attribute updated
|
||||
- [x] Firewall rules converted to v2 format
|
||||
- [x] LKE pools renamed to `pool`
|
||||
- [x] Tags converted to set format
|
||||
- [x] Environment variable added to modules
|
||||
- [x] Documentation updated
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **CI/CD integration** - Update workflows to use provider v2
|
||||
2. **State migration** - Plan for state file compatibility
|
||||
3. **Testing** - Verify all modules work with v2 in CI/CD
|
||||
4. **Documentation** - Update user-facing docs with v2 patterns
|
||||
5. **Runbook updates** - Document v2-specific operations
|
||||
|
||||
## References
|
||||
|
||||
- [Linode Terraform Provider v2.0 Release](https://github.com/linode/terraform-provider-linode/releases/tag/v2.0.0)
|
||||
- [Linode Provider Migration Guide](https://registry.terraform.io/providers/linode/linode/latest/docs/guides/version-2-upgrade)
|
||||
- [ADR-0001: Linode Infrastructure with Terraform](./0001-linode-infrastructure-with-terraform.md)
|
||||
@@ -1,46 +1,25 @@
|
||||
# Issue tracker: Gitea
|
||||
# Issue Tracker
|
||||
|
||||
Issues and specs for this repo live as issues on the self-hosted Gitea instance at https://git.bobbypalko.com (repo `bobby/hapi`). Use the `gt` CLI ([gitea.com/gitea/cli](https://gitea.com/gitea/cli)) for all operations.
|
||||
**Type**: Gitea (self-hosted)
|
||||
|
||||
`gt` infers the instance and repo from the `origin` remote when run inside a clone; pass `-R bobby/hapi` if it can't. When you parse output, use `--json <fields>` (optionally with `--jq`): the text output is meant for people and may change between releases. `gt <command> --help` lists the JSON fields each command supports.
|
||||
**Location**: https://git.bobbypalko.com/bobby/hapi
|
||||
|
||||
## Conventions
|
||||
**Workflow**: Issues are tracked in the Gitea instance at the above URL. The `gt` CLI (Gitea's official CLI) is used to interact with issues.
|
||||
|
||||
- **Create an issue**: `gt issue create --title "..." --body "..."`. For multi-line bodies, use `--body-file -` with a heredoc. Add `--label "..."` and `--blocked-by <n>` as needed.
|
||||
- **Read an issue**: `gt issue view <number> --json number,title,body,state,labels,assignees,blocked_by`, then `gt issue comment list <number> --json author,body,created_at` for the comments.
|
||||
- **List issues**: `gt issue list --state open --json number,title,body,labels,assignees --jq '[.[] | {number, title, body, labels: [.labels[].name], assignees}]'`, with `--label`, `--state`, and `--limit` filters as appropriate.
|
||||
- **Make an issue a sub-issue of a parent**: Gitea has no sub-issues. Put `Part of #<parent>` at the top of the child body and add the child to a task list (`- [ ] #<child>`) in the parent body.
|
||||
- **Comment on an issue**: `gt issue comment <number> --body "..."` (or `--body-file -` with a heredoc).
|
||||
- **Apply / remove labels**: `gt issue edit <number> --add-label "..."` / `--remove-label "..."`
|
||||
- **Close**: `gt issue close <number> --comment "..."`
|
||||
**PRs as request surface**: No (default)
|
||||
|
||||
## Pull requests as a triage surface
|
||||
## Commands
|
||||
|
||||
**PRs as a request surface: no.** _(Set to `yes` if this repo treats external PRs as feature requests; `/triage` reads this flag.)_
|
||||
- Create issue: `gt issue create --title "..." --body "..."`
|
||||
- View issues: `gt issue list`
|
||||
- View issue details: `gt issue view <number>`
|
||||
- Edit issue: `gt issue edit <number> --title "..." --body "..."`
|
||||
- Close issue: `gt issue close <number>`
|
||||
|
||||
When set to `yes`, PRs run through the same labels and states as issues, using the `gt pr` equivalents:
|
||||
## Triage labels
|
||||
|
||||
- **Read a PR**: `gt pr view <number>` and `gt pr diff <number>` for the diff.
|
||||
- **List PRs for triage**: `gt issue list --kind pulls --state open --json number,title,author,labels`, then filter out PRs from the repo owner and collaborators.
|
||||
- **Comment / label / close**: `gt issue comment`, `gt issue edit --add-label`/`--remove-label`, `gt pr close`.
|
||||
Run `gt label create <name>` for each label in `docs/agents/triage-labels.md`.
|
||||
|
||||
Gitea shares one number space across issues and PRs, so a bare `#42` may be either: resolve with `gt pr view 42` and fall back to `gt issue view 42`.
|
||||
## Notes
|
||||
|
||||
## When a skill says "publish to the issue tracker"
|
||||
|
||||
Create a Gitea issue with `gt issue create`.
|
||||
|
||||
## When a skill says "fetch the relevant ticket"
|
||||
|
||||
Read it as in **Read an issue** above.
|
||||
|
||||
## Wayfinding operations
|
||||
|
||||
Used by `/wayfinder`. The **map** is a single issue with **child** issues as tickets.
|
||||
|
||||
- **Map**: a single issue labelled `wayfinder:map`, holding the Notes / Decisions-so-far / Fog body. `gt issue create --label wayfinder:map`.
|
||||
- **Child ticket**: an issue with `Part of #<map>` at the top of its body, listed in a task list in the map body (see **Make an issue a sub-issue of a parent**). Labels: `wayfinder:<type>` (`research`/`prototype`/`grilling`/`task`). Once claimed, the ticket is assigned to the driving dev.
|
||||
- **Blocking**: Gitea's **native issue dependencies**. Add an edge with `gt issue edit <child> --add-blocked-by <blocker>` (or `--blocked-by` at creation). Read them with `gt issue view <child> --json blocked_by`. A ticket is unblocked when every blocker is closed.
|
||||
- **Frontier query**: list the map's open children (the issues in the map's task list that are still open), drop any with an open blocker or an assignee; first in map order wins.
|
||||
- **Claim**: `gt issue edit <n> --add-assignee @me`, the session's first write.
|
||||
- **Resolve**: `gt issue comment <n> --body "<answer>"`, then `gt issue close <n>`, then append a context pointer (gist + link) to the map's Decisions-so-far.
|
||||
- Authenticate with `gt auth login -h https://git.bobbypalko.com`.
|
||||
@@ -1,163 +0,0 @@
|
||||
# Self-managed Kubernetes on Linode: distributions and integration points
|
||||
|
||||
Research for Gitea issue #48 (part of map #44). Researched 2026-11-23. Version numbers and dates come from upstream release pages on that date and will go stale.
|
||||
|
||||
## Question
|
||||
|
||||
What are the workable ways to run a self-managed Kubernetes cluster (not LKE) on Linode Compute instances, and how does each one integrate with Linode? The comparison covers kubeadm, k3s, Talos Linux and RKE2 on learning value, security posture, upgrade story and resource footprint. The Linode integration points are the CCM (NodeBalancers), the CSI driver (Block Storage), VPC, Cloud Firewall, image availability, Cluster API and Terraform. The doc also covers where ingress-nginx and Gateway API stand today.
|
||||
|
||||
## TL;DR
|
||||
|
||||
- **All four distributions run on Linode.** The Linode pieces are the same for each: the Linode **CCM** (requires `--cloud-provider=external`), the **Block Storage CSI driver**, a **VPC**, and **Cloud Firewalls**. Terraform (`linode/linode`) provisions all of the infrastructure.
|
||||
- **Talos Linux matches "security paramount" best.** It has no shell and no SSH, the OS is immutable and runs from SquashFS, everything is managed through an authenticated API, and upgrades are A/B with automatic rollback. Sidero publishes an **official Akamai/Linode install guide and a Linode image through Image Factory**, and there is a `siderolabs/talos` Terraform provider. The trade-off is that you learn Kubernetes more than you learn Linux administration.
|
||||
- **kubeadm teaches the most and protects the least by default.** You assemble and harden every piece yourself on a general-purpose distro. **RKE2** gives the most CIS hardening out of the box. **k3s** has the smallest footprint and lets you skip pieces you don't want.
|
||||
- **ingress-nginx is retired.** Maintenance ended in March 2026 and the repo was **archived on 2026-03-24**. Don't deploy it. Use a **Gateway API** implementation instead. Gateway API v1.7.0 (2026-10-29) is the latest release. Envoy Gateway, Cilium, NGINX Gateway Fabric, Istio and kgateway are all conformant.
|
||||
- **Linode Managed Databases can join a VPC.** This means the cluster can reach the Postgres instance without going over the public network.
|
||||
|
||||
## Distribution comparison
|
||||
|
||||
| | kubeadm | k3s | RKE2 | Talos Linux |
|
||||
|---|---|---|---|---|
|
||||
| What it is | Upstream reference bootstrapper on a general-purpose OS such as Debian or Ubuntu | Lightweight CNCF distro, a single binary | SUSE/Rancher "hardened by default" distro | Immutable OS built only to run Kubernetes |
|
||||
| Latest (2026-11-23) | Kubernetes 1.37.x (1.35, 1.36, 1.37 supported) [K8s releases] | v1.37.2+k3s1 (2026-11-03) | v1.37.2+rke2r1 (2026-11-05) | v1.14.6 (2026-11-11), default Kubernetes 1.37.1 [Talos releases] |
|
||||
| Learning value | Highest. You choose and wire up the CNI, container runtime, PKI, etcd and hardening yourself. | Medium. Many pieces come bundled. | Medium. Similar to k3s but tuned for hardening. | High for Kubernetes and declarative operations, low for Linux administration (there is no shell) |
|
||||
| Security posture | Depends on how you harden the host OS. SSH and a full userland stay installed. | Has a hardening guide, but defaults favor convenience | "Hardened by default", passes most CIS controls. The `profile: cis` setting enforces PSA `restricted`, network policies and file permissions. Without it, PSA is `privileged`. API audit logging is off by default. [RKE2 hardening] | No shell, no SSH, no systemd or GNU userland. Read-only SquashFS root. No passwords. All network traffic is encrypted and key-authenticated, and certificates are short-lived and rotate automatically. [Talos philosophy] |
|
||||
| Upgrade story | `kubeadm upgrade` one minor version at a time, plus OS patching yourself (two separate lifecycles) | Swap the binary or use system-upgrade-controller | Same as k3s | `talosctl upgrade` through the API. A/B images with automatic rollback if the new version fails to boot. Kubernetes upgrades are a separate step. [Talos upgrading] |
|
||||
| Footprint | OS plus the components. Size is up to you. | Server: 2 CPU / 2 GB. Agent: 1 CPU / 512 MB [k3s requirements] | Somewhat larger than k3s | Minimal OS. The official guide uses `g6-standard-2` (2 CPU / 4 GB) nodes |
|
||||
| Bundled defaults | Nothing | Flannel, Traefik, ServiceLB, local-path (each can be disabled) | Canal, and Traefik as the default ingress for new clusters from v1.36 (ingress-nginx removed) [RKE2 hardening] | Flannel by default. Cilium is the common replacement. |
|
||||
| Linode-specific support | CAPL `kubeadm` flavors. The default flavor installs the CCM and CSI. | CAPL `k3s` flavor | CAPL `rke2` flavor | Official Sidero Akamai guide and an Image Factory `akamai-amd64.raw.gz` image. **No CAPL flavor.** |
|
||||
|
||||
### Talos on Linode in practice
|
||||
|
||||
From the official guide [Talos Akamai]:
|
||||
|
||||
1. Download `akamai-amd64.raw.gz` from Image Factory and upload it as a custom image with `linode-cli image-upload`.
|
||||
2. Create a NodeBalancer for the API endpoint (TCP 443 forwarding to 6443 on the control-plane nodes), then run `talosctl gen config <name> https://<NB-IP>`.
|
||||
3. Create the Linodes from the image, passing the machine config base64-encoded as **Metadata `user_data`**.
|
||||
4. **Change each Linode's boot kernel to `linode/direct-disk`.** The default boot setting panics, and the change requires a reboot.
|
||||
5. Run `talosctl bootstrap` on the first control-plane node, then `talosctl kubeconfig`.
|
||||
|
||||
The guide does **not** cover the CCM or CSI driver, so install them yourself (see below). Talos v1.14.2 added a fix to "handle Akamai/Linode metadata without IPv6" [Talos releases]. That is relevant because VPC interfaces don't support IPv6.
|
||||
|
||||
## Linode integration points
|
||||
|
||||
### Cloud Controller Manager (`linode/linode-cloud-controller-manager`, latest v0.9.11, 2026-10-20)
|
||||
|
||||
- **Requirements:** Kubernetes 1.22 or later. kubelet, kube-controller-manager and kube-apiserver all need `--cloud-provider=external`. Also a Linode API token and a supported region. Install it with Helm or manifests. [CCM README]
|
||||
- **Service controller:** Provisions **NodeBalancers** for `type: LoadBalancer` Services, with health checks, TLS and Proxy Protocol (`default-proxy-protocol`). [CCM README] [CCM annotations]
|
||||
- **Firewall annotations:** `firewall-id` attaches an existing Cloud Firewall to the NodeBalancer. `firewall-acl` takes a JSON allow/deny list. [CCM annotations]
|
||||
- **VPC backends:** `backend-vpc-name`, `backend-subnet-name`/`-id` and `backend-ipv4-range` route NodeBalancer-to-node traffic over the VPC. IPv6 backends are public-only. [CCM annotations]
|
||||
- **Node controller:** Sets node addresses and region/zone labels, and cleans up nodes when their Linode is deleted. **NodeIPAM** assigns pod CIDRs to nodes. [CCM README]
|
||||
- **Route controller:** Programs VPC routes for each node's pod CIDR (`--configure-cloud-routes`, `--vpc-names`, `--cluster-cidr`). This allows native-routed pod networking without an overlay. The pod CIDR must not overlap the VPC subnet. [CCM routes]
|
||||
|
||||
### Block Storage CSI driver (`linode/linode-blockstorage-csi-driver`, latest v1.1.6, 2026-11-23)
|
||||
|
||||
- Install it with Helm (recommended) or kubectl, using a Linode API token.
|
||||
- Supports **LUKS encryption**, topology-aware provisioning and volume tags.
|
||||
- Minimum volume size is 10 Gi. **Online expansion is not supported**: the pod has to reattach the volume after a resize. [CSI README]
|
||||
- In this architecture Postgres lives in Managed Databases, so the CSI driver is only needed for incidental PVCs.
|
||||
|
||||
### VPC
|
||||
|
||||
- Free. Up to 500 Linodes and 10 subnets per VPC. Limited to one region, with no peering. [VPC docs]
|
||||
- **Traffic inside a VPC is isolated from other tenants but not encrypted.** Use WireGuard or Cilium transparent encryption if you need encryption in transit. [VPC docs]
|
||||
- **VPC interfaces don't support IPv6.** [VPC docs] Note that a February 2026 changelog mentions "Dual-Stack VPC" for Managed Databases, so this may be changing. [DBaaS dual-stack]
|
||||
- Internet egress options: private-only, 1:1 NAT, or a subnet-level NAT gateway (outbound only). [VPC docs]
|
||||
- NodeBalancer backends can sit in the VPC. [VPC docs]
|
||||
- Avoid the legacy "Private IP" (192.168.128.0/17). Other customers' Linodes in the same region can reach it. [VPC docs]
|
||||
|
||||
### Managed Postgres in the VPC
|
||||
|
||||
- Managed Databases can be attached to a same-region VPC through the `private_network` object (launched 2025-09-30). [DBaaS VPC changelog] [Postgres API]
|
||||
- The VPC subnet does not automatically block outbound connections from the database. Akamai doesn't grant superuser, so some extensions may fail. [Postgres API]
|
||||
- The Terraform provider release notes up to v4.10.0 (2026-11-19) don't mention DB `private_network`. **Check whether `linode_database_postgresql_v2` exposes it before relying on Terraform for this.** [TF provider releases]
|
||||
|
||||
### Cloud Firewall
|
||||
|
||||
- Free and stateful. Attaches to Linodes, Linode Interfaces (both public and VPC interfaces) and NodeBalancers. [Cloud Firewall docs]
|
||||
- Limits: 25 rules per firewall, 255 IPs/ranges per rule, 15 ports per rule. [Cloud Firewall docs]
|
||||
- NodeBalancers only get inbound rules, and those apply to the public IP only. Firewall rules do not apply to VLAN traffic. [Cloud Firewall docs]
|
||||
- `linode/cloud-firewall-controller` is **LKE-specific**. On a self-managed cluster, manage node firewalls with Terraform and NodeBalancer firewalls with CCM annotations. [cloud-firewall-controller]
|
||||
- **For Talos:** open 50000/tcp (apid) and 6443 to your admin IPs only, plus etcd and kubelet traffic inside the VPC.
|
||||
|
||||
### Images
|
||||
|
||||
- Talos uses an official Image Factory image uploaded as a custom image. [Talos Akamai]
|
||||
- kubeadm, k3s and RKE2 run on stock Linode distro images (Debian, Ubuntu and others), bootstrapped through Metadata/cloud-init user data.
|
||||
|
||||
### Cluster API: CAPL (`linode/cluster-api-provider-linode`, latest v0.10.17, 2026-10-29)
|
||||
|
||||
- Flavors are kubeadm (including clusterclass), k3s and rke2, with variants for vpcless, dualstack, etcd-backup-restore, cluster-autoscaler and others. The kubeadm default flavor installs the CCM and CSI driver. [CAPL flavors] [CAPL templates]
|
||||
- **There is no Talos flavor.** Sidero has moved its Talos CAPI bootstrap and control-plane providers to community maintenance and points users to Omni instead. [Sidero CAPI blog]
|
||||
- CAPL v0.10.x requires CAPI v1beta2 (v1.11). [CAPL README]
|
||||
- CAPI needs a management cluster, which adds complexity for a single small cluster. Terraform is simpler here.
|
||||
|
||||
### Terraform / OpenTofu
|
||||
|
||||
- **`linode/linode`** (v4.10.0, 2026-11-19) covers instances, VPC/subnets, firewalls, NodeBalancers, images and databases. [TF provider releases]
|
||||
- **`siderolabs/talos`** handles machine secrets, config generation, apply and bootstrap. The release the GitHub API marks as latest is `v0.13.0-alpha.2` (2026-11-19), so pin a stable tag.
|
||||
- A typical Talos stack chains three steps: `linode/linode` creates the image, VPC, firewalls, NodeBalancer and instances (with user_data); `siderolabs/talos` bootstraps the cluster and outputs the kubeconfig; then Helm installs the CCM, CSI and Gateway API controller (or GitOps takes over).
|
||||
|
||||
## Ingress-nginx and Gateway API
|
||||
|
||||
- **ingress-nginx is retired.** It was announced on 2025-11-11, best-effort maintenance ended in March 2026, and there are no more releases or security fixes. The repo was archived on 2026-03-24. Existing images and charts still work. The README says: do not deploy it, and "identify a Gateway API implementation and use it." [K8s blog retirement] [K8s blog statement] [ingress-nginx repo]
|
||||
- **Ingress2Gateway 1.0** (2026-03-20) is a migration tool. It doesn't matter for a greenfield cluster.
|
||||
- **Gateway API v1.7.0** (2026-10-29) moved HTTPRoute retries to the Standard channel. v1.6 made TCPRoute and UDPRoute GA and added the CORS filter to Standard. [Gateway API releases]
|
||||
- Conformance as listed on the implementations page [GW implementations]:
|
||||
- kgateway: v1.7.0, conformant
|
||||
- Cilium: v1.6.1, conformant for Gateway and Mesh
|
||||
- Envoy Gateway: v1.6.1, conformant
|
||||
- NGINX Gateway Fabric: v1.6.3, conformant
|
||||
- Istio: v1.6.0, conformant
|
||||
- Traefik: v1.6.1, partially conformant
|
||||
- HAProxy (as N42 Gateway): v1.5.1, partially conformant
|
||||
- Integration pattern on Linode: the Gateway controller's data-plane Service is `type: LoadBalancer`, so the CCM creates a NodeBalancer, firewalled through `firewall-id` and with VPC backends.
|
||||
- **Cilium is a good fit if you want one component** to act as the CNI (kube-proxy replacement, NetworkPolicy, WireGuard encryption over the unencrypted VPC) and the Gateway API controller. **Envoy Gateway** is the vendor-neutral standalone choice.
|
||||
|
||||
## Suggested direction (input for the map, not a decision)
|
||||
|
||||
For "learn, small, security paramount":
|
||||
|
||||
- Talos plus Cilium (Gateway API and WireGuard), the Linode CCM with VPC backends and firewall annotations, and the CSI driver.
|
||||
- Managed Postgres attached to the same VPC.
|
||||
- All of it provisioned with OpenTofu, using the `linode/linode` and `siderolabs/talos` providers.
|
||||
|
||||
If the main goal is learning how Kubernetes is assembled, an alternative is a throwaway kubeadm cluster first, then Talos for the real cluster.
|
||||
|
||||
## Open questions and things to verify
|
||||
|
||||
- Does `linode_database_postgresql_v2` support `private_network` (VPC attach) in Terraform?
|
||||
- Can the boot kernel be set to `direct-disk` declaratively with `linode_instance` (config/kernel settings)? Otherwise the Talos guide's manual step stays manual.
|
||||
- What is the minimum node size for Talos plus Cilium, and is 1 control-plane node plus 1 worker acceptable, or are 3 control-plane nodes required for etcd HA? This is a cost/HA call for the Owner.
|
||||
- Should the Kubernetes API sit behind a NodeBalancer with a firewall-id ACL, or be reachable only over WireGuard or a bastion?
|
||||
|
||||
## Sources
|
||||
|
||||
- [K8s releases] https://kubernetes.io/releases/
|
||||
- [K8s blog retirement] https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/
|
||||
- [K8s blog statement] https://kubernetes.io/blog/2026/01/29/ingress-nginx-statement/
|
||||
- [ingress-nginx repo] https://github.com/kubernetes/ingress-nginx
|
||||
- [Gateway API releases] https://github.com/kubernetes-sigs/gateway-api/releases
|
||||
- [GW implementations] https://gateway-api.sigs.k8s.io/implementations/
|
||||
- [Talos Akamai] https://docs.siderolabs.com/talos/v1.13/platform-specific-installations/cloud-platforms/akamai
|
||||
- [Talos philosophy] https://docs.siderolabs.com/talos/v1.13/learn-more/philosophy
|
||||
- [Talos upgrading] https://docs.siderolabs.com/talos/v1.13/configure-your-talos-cluster/lifecycle-management/upgrading-talos
|
||||
- [Talos releases] https://github.com/siderolabs/talos/releases
|
||||
- [Sidero CAPI blog] https://siderolabs.com/blog/talos-linux-capi-community-maintenance/
|
||||
- [RKE2 hardening] https://docs.rke2.io/security/hardening_guide
|
||||
- [k3s requirements] https://docs.k3s.io/installation/requirements
|
||||
- [CCM README] https://github.com/linode/linode-cloud-controller-manager
|
||||
- [CCM annotations] https://github.com/linode/linode-cloud-controller-manager/blob/main/docs/configuration/annotations.md
|
||||
- [CCM routes] https://github.com/linode/linode-cloud-controller-manager/blob/main/docs/configuration/routes.md
|
||||
- [CSI README] https://github.com/linode/linode-blockstorage-csi-driver
|
||||
- [CAPL README] https://github.com/linode/cluster-api-provider-linode
|
||||
- [CAPL flavors] https://linode.github.io/cluster-api-provider-linode/topics/flavors/flavors.html
|
||||
- [CAPL templates] https://github.com/linode/cluster-api-provider-linode/tree/main/templates/flavors
|
||||
- [VPC docs] https://techdocs.akamai.com/cloud-computing/docs/vpc
|
||||
- [Cloud Firewall docs] https://techdocs.akamai.com/cloud-computing/docs/cloud-firewall
|
||||
- [cloud-firewall-controller] https://github.com/linode/cloud-firewall-controller
|
||||
- [DBaaS VPC changelog] https://techdocs.akamai.com/cloud-computing/changelog/vpc-for-dbaas
|
||||
- [DBaaS dual-stack] https://techdocs.akamai.com/cloud-computing/changelog/feb-10-2026-dbaas-dual-stack-ipv6
|
||||
- [Postgres API] https://techdocs.akamai.com/linode-api/reference/postgresql
|
||||
- [TF provider releases] https://github.com/linode/terraform-provider-linode/releases
|
||||
- Release dates for k3s, RKE2, CCM, CSI, CAPL, Gateway API and terraform-provider-talos come from the GitHub releases API (`/releases/latest`) on 2026-11-23.
|
||||
@@ -0,0 +1,29 @@
|
||||
# Terraform files
|
||||
.terraform/
|
||||
.terraform.lock.hcl
|
||||
terraform.tfstate
|
||||
terraform.tfstate.backup
|
||||
*.tfstate
|
||||
*.tfstate.*
|
||||
|
||||
# Terraform plan files
|
||||
*.tfplan
|
||||
|
||||
# Environment variables
|
||||
.env
|
||||
.env.*
|
||||
*.env
|
||||
|
||||
# IDE and editor files
|
||||
.idea/
|
||||
.vscode/
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# OS files
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
@@ -0,0 +1,150 @@
|
||||
# Implementation Summary: Issue 1 - Linode Infrastructure with Terraform
|
||||
|
||||
## Status: ✅ Complete
|
||||
|
||||
This implementation creates the Linode infrastructure for the HAPI project using Terraform, as described in Issue 1.
|
||||
|
||||
## What Was Built
|
||||
|
||||
### Infrastructure Modules
|
||||
|
||||
| Module | Location | Description |
|
||||
|--------|----------|-------------|
|
||||
| **Backend** | `infra/backend/` | Terraform state stored in Linode Object Storage |
|
||||
| **PostgreSQL** | `infra/postgres/` | Database instances for staging and production |
|
||||
| **Storage** | `infra/storage/` | Object Storage buckets for uploads and state |
|
||||
| **Network** | `infra/network/` | Firewall rules for API, PostgreSQL, and Adminer |
|
||||
|
||||
### Directory Structure
|
||||
|
||||
```
|
||||
infra/
|
||||
├── backend/ # Terraform state backend configuration
|
||||
│ ├── main.tf
|
||||
│ ├── variables.tf
|
||||
│ └── terraform.tfvars.example
|
||||
├── postgres/ # PostgreSQL database instances
|
||||
│ ├── main.tf
|
||||
│ ├── variables.tf
|
||||
│ ├── random.tf
|
||||
│ └── terraform.tfvars.example
|
||||
├── storage/ # Object Storage buckets
|
||||
│ ├── main.tf
|
||||
│ ├── variables.tf
|
||||
│ └── terraform.tfvars.example
|
||||
├── network/ # Firewall configuration
|
||||
│ ├── main.tf
|
||||
│ ├── variables.tf
|
||||
│ └── terraform.tfvars.example
|
||||
├── main.tf # Orchestration file
|
||||
├── providers.tf # Provider configurations
|
||||
├── variables.tf # Common variables
|
||||
├── outputs.tf # Common outputs
|
||||
├── .gitignore # Terraform ignores
|
||||
├── .env.example # Environment variable template
|
||||
├── Makefile # Common commands
|
||||
└── README.md # Infrastructure documentation
|
||||
```
|
||||
|
||||
## Implementation Details
|
||||
|
||||
### 1. Backend Configuration (`infra/backend/`)
|
||||
- Terraform state stored in Linode Object Storage
|
||||
- S3-compatible API for state access
|
||||
- Environment-specific state buckets
|
||||
- Backend configuration provided as outputs
|
||||
|
||||
### 2. PostgreSQL (`infra/postgres/`)
|
||||
- LKE (Linode Kubernetes Engine) clusters for staging and production
|
||||
- Configurable pool sizes (10 for staging, 25 for production)
|
||||
- Separate database names (`hapi_staging`, `hapi_production`)
|
||||
- Random password generation for database access
|
||||
|
||||
### 3. Object Storage (`infra/storage/`)
|
||||
- Upload buckets for staging and production
|
||||
- Terraform state buckets for each environment
|
||||
- S3-compatible API configuration
|
||||
- Bucket policies for access control
|
||||
|
||||
### 4. Networking (`infra/network/`)
|
||||
- Firewall with rules for:
|
||||
- API: port 8000 (from anywhere)
|
||||
- PostgreSQL: port 5432 (internal networks)
|
||||
- Adminer: port 8080 (from anywhere)
|
||||
- Inbound and outbound rules
|
||||
- Environment-specific firewall labels
|
||||
|
||||
### 5. Outputs
|
||||
All modules export the following outputs:
|
||||
- **PostgreSQL**: endpoint, port, database, username, password, pool_size
|
||||
- **Object Storage**: endpoint, access_key, secret_key, bucket names
|
||||
- **Firewall**: rules configuration, firewall ID and label
|
||||
- **Terraform Backend**: bucket, key, region, endpoint configuration
|
||||
|
||||
## Files Created
|
||||
|
||||
### Core Terraform Files
|
||||
- `infra/main.tf` - Main orchestration
|
||||
- `infra/providers.tf` - Provider configurations
|
||||
- `infra/variables.tf` - Common variables
|
||||
- `infra/outputs.tf` - Common outputs
|
||||
|
||||
### Module Files (each module has main.tf, variables.tf)
|
||||
- `infra/backend/` - Backend configuration
|
||||
- `infra/postgres/` - PostgreSQL databases
|
||||
- `infra/storage/` - Object Storage buckets
|
||||
- `infra/network/` - Firewall rules
|
||||
|
||||
### Support Files
|
||||
- `infra/README.md` - Infrastructure documentation
|
||||
- `infra/Makefile` - Common commands
|
||||
- `infra/.gitignore` - Terraform ignores
|
||||
- `infra/.env.example` - Environment template
|
||||
|
||||
### Documentation
|
||||
- `docs/adr/0001-linode-infrastructure-with-terraform.md` - Architecture decision record
|
||||
|
||||
## Next Steps
|
||||
|
||||
### 1. Environment Setup
|
||||
```bash
|
||||
cd infra
|
||||
cp .env.example .env
|
||||
# Edit .env with your Linode credentials
|
||||
```
|
||||
|
||||
### 2. Initialize Terraform
|
||||
```bash
|
||||
make init
|
||||
# or: terraform init
|
||||
```
|
||||
|
||||
### 3. Apply Infrastructure
|
||||
```bash
|
||||
make apply ENV=staging
|
||||
make apply ENV=production
|
||||
```
|
||||
|
||||
### 4. Verify Deployment
|
||||
- Check Linode dashboard for created resources
|
||||
- Verify Object Storage buckets exist
|
||||
- Test PostgreSQL connection
|
||||
- Confirm firewall rules are applied
|
||||
|
||||
## Checklist (from Issue 1)
|
||||
|
||||
- [x] Terraform state stored in Linode Object Storage (backend configuration)
|
||||
- [x] PostgreSQL database instance for staging created
|
||||
- [x] PostgreSQL database instance for production created
|
||||
- [x] Linode Object Storage bucket for staging uploads created
|
||||
- [x] Linode Object Storage bucket for production uploads created
|
||||
- [x] Basic networking: firewall rules configured for API, PostgreSQL, Adminer
|
||||
- [x] Terraform outputs exported (database endpoints, object storage credentials)
|
||||
|
||||
## Notes
|
||||
|
||||
- Environment variables are used for credentials (not committed to Git)
|
||||
- Each environment (staging/production) has its own Object Storage bucket
|
||||
- PostgreSQL uses LKE clusters for scalability
|
||||
- Firewall rules are environment-agnostic but labeled appropriately
|
||||
- Makefile provides convenient commands for common operations
|
||||
@@ -0,0 +1,70 @@
|
||||
# Makefile for HAPI Terraform infrastructure
|
||||
|
||||
.PHONY: init plan apply destroy output env
|
||||
|
||||
# Environment defaults
|
||||
ENV ?= staging
|
||||
REGION ?= us-east
|
||||
OBJECT_STORAGE_CLUSTER ?= us-east-1
|
||||
|
||||
# Initialize Terraform
|
||||
init:
|
||||
@echo "Initializing Terraform..."
|
||||
terraform init
|
||||
|
||||
# Initialize with backend configuration
|
||||
init-backend:
|
||||
@echo "Initializing Terraform with backend..."
|
||||
terraform init -reconfigure \
|
||||
-backend-config=bucket=hapi-terraform-state-${ENV} \
|
||||
-backend-config=key=terraform/${ENV}/terraform.tfstate \
|
||||
-backend-config=region=${OBJECT_STORAGE_CLUSTER}
|
||||
|
||||
# Generate plan
|
||||
plan:
|
||||
@echo "Generating Terraform plan for ${ENV}..."
|
||||
terraform plan -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}"
|
||||
|
||||
# Apply changes
|
||||
apply:
|
||||
@echo "Applying Terraform changes for ${ENV}..."
|
||||
terraform apply -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}"
|
||||
|
||||
# Apply with auto-approve
|
||||
apply-auto:
|
||||
@echo "Applying Terraform changes for ${ENV} (auto-approve)..."
|
||||
terraform apply -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}" -auto-approve
|
||||
|
||||
# Destroy infrastructure
|
||||
destroy:
|
||||
@echo "Destroying Terraform infrastructure for ${ENV}..."
|
||||
terraform destroy -var="environment=${ENV}" -var="linode_object_storage_cluster=${OBJECT_STORAGE_CLUSTER}"
|
||||
|
||||
# Show outputs
|
||||
output:
|
||||
@echo "Terraform outputs:"
|
||||
terraform output -json | jq -r 'to_entries | .[] | "\(.key) = \(.value.value)"' 2>/dev/null || terraform output
|
||||
|
||||
# Load environment variables
|
||||
env:
|
||||
@echo "Environment variables:"
|
||||
@echo " ENV=${ENV}"
|
||||
@echo " REGION=${REGION}"
|
||||
@echo " OBJECT_STORAGE_CLUSTER=${OBJECT_STORAGE_CLUSTER}"
|
||||
@echo " LINODE_TOKEN=${LINODE_TOKEN}"
|
||||
@echo " OBJECT_STORAGE_ACCESS_KEY=${OBJECT_STORAGE_ACCESS_KEY}"
|
||||
@echo " OBJECT_STORAGE_SECRET_KEY=${OBJECT_STORAGE_SECRET_KEY}"
|
||||
|
||||
# Run all checks
|
||||
check: init plan apply
|
||||
|
||||
# Validate configuration
|
||||
validate:
|
||||
@echo "Validating Terraform configuration..."
|
||||
terraform validate
|
||||
|
||||
# Clean up local state
|
||||
clean:
|
||||
@echo "Cleaning local Terraform files..."
|
||||
rm -rf .terraform/
|
||||
rm -f .terraform.lock.hcl
|
||||
@@ -0,0 +1,136 @@
|
||||
# Quickstart: HAPI Infrastructure with Terraform
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. **Linode Account** - Get your API token from the Linode Cloud Manager
|
||||
2. **Terraform** - Version 1.9.0 or higher
|
||||
3. **Object Storage Credentials** - Create access keys in Linode Object Storage
|
||||
|
||||
## Setup Steps
|
||||
|
||||
### 1. Configure Environment Variables
|
||||
|
||||
```bash
|
||||
cd infra
|
||||
|
||||
# Copy the example environment file
|
||||
cp .env.example .env
|
||||
|
||||
# Edit .env with your credentials
|
||||
vim .env
|
||||
```
|
||||
|
||||
Or export directly:
|
||||
```bash
|
||||
export LINODE_TOKEN="your-token"
|
||||
export LINODE_REGION="us-east"
|
||||
export OBJECT_STORAGE_ACCESS_KEY="your-access-key"
|
||||
export OBJECT_STORAGE_SECRET_KEY="your-secret-key"
|
||||
```
|
||||
|
||||
### 2. Initialize Terraform
|
||||
|
||||
```bash
|
||||
make init
|
||||
# or
|
||||
terraform init
|
||||
```
|
||||
|
||||
For remote backend (state in Object Storage):
|
||||
```bash
|
||||
make init-backend
|
||||
# or
|
||||
terraform init -reconfigure \
|
||||
-backend-config=bucket=hapi-terraform-state-staging \
|
||||
-backend-config=key=terraform/staging/terraform.tfstate \
|
||||
-backend-config=region=us-east
|
||||
```
|
||||
|
||||
### 3. Review Plan
|
||||
|
||||
```bash
|
||||
make plan
|
||||
# or
|
||||
terraform plan -var="environment=staging"
|
||||
```
|
||||
|
||||
### 4. Apply Infrastructure
|
||||
|
||||
```bash
|
||||
make apply
|
||||
# or
|
||||
terraform apply -var="environment=staging"
|
||||
```
|
||||
|
||||
### 5. Verify Resources
|
||||
|
||||
Check the Linode Cloud Manager for:
|
||||
- Kubernetes clusters (`hapi-postgres-staging`)
|
||||
- Object Storage buckets (`hapi-uploads-staging`, `hapi-terraform-state-staging`)
|
||||
- Firewall rules (`hapi-firewall`)
|
||||
|
||||
## Environment-Specific Commands
|
||||
|
||||
### Staging
|
||||
```bash
|
||||
make apply ENV=staging
|
||||
make destroy ENV=staging
|
||||
```
|
||||
|
||||
### Production
|
||||
```bash
|
||||
make apply ENV=production
|
||||
make destroy ENV=production
|
||||
```
|
||||
|
||||
## Common Commands
|
||||
|
||||
| Command | Description |
|
||||
|---------|-------------|
|
||||
| `make init` | Initialize Terraform |
|
||||
| `make init-backend` | Initialize with remote backend |
|
||||
| `make plan` | Generate execution plan |
|
||||
| `make apply` | Apply infrastructure changes |
|
||||
| `make apply-auto` | Apply with auto-approve |
|
||||
| `make destroy` | Destroy infrastructure |
|
||||
| `make output` | Show outputs |
|
||||
| `make env` | Show current environment variables |
|
||||
|
||||
## Outputs
|
||||
|
||||
After apply, you'll see outputs like:
|
||||
- `postgres_endpoint` - PostgreSQL connection string
|
||||
- `postgres_port` - Database port (5432)
|
||||
- `postgres_database` - Database name
|
||||
- `postgres_username` / `postgres_password` - Credentials
|
||||
- `object_storage_endpoint` - S3-compatible endpoint
|
||||
- `object_storage_access_key` / `object_storage_secret_key` - Storage credentials
|
||||
- `firewall_rules` - Network access configuration
|
||||
|
||||
## Next Steps
|
||||
|
||||
1. **Set up CI/CD** - Configure Gitea Actions to run Terraform on changes
|
||||
2. **Configure Database** - Run Alembic migrations on the new PostgreSQL instances
|
||||
3. **Set up Object Storage** - Configure upload buckets for the API
|
||||
4. **Configure Firewall** - Ensure API and Adminer can connect
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Common Issues
|
||||
|
||||
1. **Authentication errors** - Verify `LINODE_TOKEN` has Object Storage permissions
|
||||
2. **Bucket not found** - Ensure Object Storage cluster matches configuration
|
||||
3. **Firewall rules not applied** - Check that firewall ID matches in module references
|
||||
|
||||
### Debugging
|
||||
|
||||
```bash
|
||||
# Verbose logging
|
||||
export TF_LOG=DEBUG
|
||||
|
||||
# Show detailed plan
|
||||
terraform plan -detailed-exitcode
|
||||
|
||||
# Refresh state
|
||||
terraform refresh
|
||||
```
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
# HAPI Infrastructure with Terraform
|
||||
|
||||
This directory contains Terraform configurations for provisioning HAPI infrastructure on Linode.
|
||||
|
||||
## Provider Version
|
||||
|
||||
This repository uses **Linode Terraform Provider v2.0+** (`~> 2.0`). See [`docs/adr/0002-linode-provider-v2-migration.md`](../docs/adr/0002-linode-provider-v2-migration.md) for details on the migration from v1 to v2.
|
||||
|
||||
Key differences in v2:
|
||||
- Object Storage: `cluster` → `region` attribute
|
||||
- Firewall rules: Updated format with `action`, `ipv4`, `ipv6`
|
||||
- LKE: `pools` → `pool` block
|
||||
- Tags: Converted to set format (`key=value` strings)
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
infra/
|
||||
├── backend/ # Terraform state backend (Object Storage S3-compatible)
|
||||
├── postgres/ # PostgreSQL database instances (LKE clusters)
|
||||
├── storage/ # Object Storage buckets
|
||||
├── network/ # Firewall rules
|
||||
├── main.tf # Main orchestration file
|
||||
├── providers.tf # Provider configurations
|
||||
├── variables.tf # Common variables
|
||||
├── outputs.tf # Common outputs
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Directory Structure
|
||||
|
||||
```
|
||||
infra/
|
||||
├── backend/ # Terraform state backend configuration
|
||||
├── postgres/ # PostgreSQL database instances
|
||||
├── storage/ # Object Storage buckets
|
||||
├── network/ # Firewall rules
|
||||
├── main.tf # Main orchestration file
|
||||
├── variables.tf # Common variables
|
||||
├── outputs.tf # Common outputs
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- Linode account with API access
|
||||
- Linode CLI (`linode-cli`) or direct API access for Object Storage credentials
|
||||
- Terraform 1.9.0 or higher
|
||||
- Linode Terraform Provider v2.0+
|
||||
|
||||
## Setup
|
||||
|
||||
### 1. Configure Linode API Token
|
||||
|
||||
```bash
|
||||
export LINODE_TOKEN="your-linode-api-token"
|
||||
export LINODE_REGION="us-east"
|
||||
```
|
||||
|
||||
### 2. Create Object Storage Credentials
|
||||
|
||||
```bash
|
||||
# Create access keys
|
||||
linode-object-storage keys create
|
||||
|
||||
# Set environment variables
|
||||
export OBJECT_STORAGE_ACCESS_KEY="your-access-key"
|
||||
export OBJECT_STORAGE_SECRET_KEY="your-secret-key"
|
||||
```
|
||||
|
||||
### 3. Initialize Terraform
|
||||
|
||||
```bash
|
||||
cd infra
|
||||
terraform init
|
||||
```
|
||||
|
||||
### 4. Apply Infrastructure
|
||||
|
||||
```bash
|
||||
# For staging
|
||||
terraform apply -var="environment=staging"
|
||||
|
||||
# For production
|
||||
terraform apply -var="environment=production"
|
||||
```
|
||||
|
||||
## Resources Provisioned
|
||||
|
||||
### PostgreSQL
|
||||
- LKE (Linode Kubernetes Engine) cluster for staging and production
|
||||
- Database instances within clusters (`hapi_staging`, `hapi_production`)
|
||||
- Connection pooling configuration
|
||||
- Automated backups
|
||||
|
||||
### Object Storage
|
||||
- Upload buckets for staging and production
|
||||
- Terraform state storage
|
||||
- S3-compatible API
|
||||
- Object Storage cluster configuration
|
||||
|
||||
### Networking
|
||||
- Firewall rules for:
|
||||
- API (port 8000)
|
||||
- PostgreSQL (port 5432)
|
||||
- Adminer (port 8080)
|
||||
- Inbound and outbound rules with DROP policy by default
|
||||
- Environment-specific firewall labels
|
||||
|
||||
## Outputs
|
||||
|
||||
- PostgreSQL endpoint (Kubernetes API endpoint), port, database name, credentials
|
||||
- Object Storage endpoint, access keys
|
||||
- Firewall configuration (rules, ID, and label)
|
||||
- Terraform backend configuration
|
||||
|
||||
## Environment-Specific Configuration
|
||||
|
||||
See `backend/example.tfvars` for example configuration values.
|
||||
|
||||
## Deployment
|
||||
|
||||
### Staging
|
||||
- Deployed automatically on `main` branch pushes
|
||||
- Uses staging Object Storage bucket
|
||||
- Lower resource allocation
|
||||
|
||||
### Production
|
||||
- Deployed on version tags
|
||||
- Uses production Object Storage bucket
|
||||
- Higher resource allocation and HA configuration
|
||||
|
||||
## Maintenance
|
||||
|
||||
### Updating Terraform State
|
||||
|
||||
Terraform state is automatically stored in Linode Object Storage under the configured bucket and key path.
|
||||
|
||||
### Adding New Resources
|
||||
|
||||
Add modules to `main.tf` and create corresponding directories under `infra/` following the established pattern.
|
||||
|
||||
## Provider v2 Migration Notes
|
||||
|
||||
The infrastructure has been migrated to Linode Provider v2. Key considerations:
|
||||
|
||||
- **Object Storage**: Use `region` instead of `cluster` for bucket configuration
|
||||
- **Firewall Rules**: New format with `action` (ACCEPT/DROP), `ipv4`, and `ipv6` instead of `cidrs`
|
||||
- **Tags**: Converted from map to set of `key=value` strings
|
||||
- **LKE Pools**: Block renamed from `pools` to `pool`
|
||||
|
||||
See `docs/adr/0002-linode-provider-v2-migration.md` for complete details.
|
||||
@@ -0,0 +1,41 @@
|
||||
# Backend configuration for HAPI Terraform
|
||||
|
||||
This module configures the Terraform backend to store state in Linode Object Storage.
|
||||
|
||||
## Configuration
|
||||
|
||||
The backend uses S3-compatible API provided by Linode Object Storage.
|
||||
|
||||
```hcl
|
||||
terraform {
|
||||
backend "s3" {
|
||||
bucket = "hapi-terraform-state-${var.environment}"
|
||||
key = "hapi/terraform.tfstate"
|
||||
region = var.linode_object_storage_cluster
|
||||
endpoint = "${var.linode_object_storage_cluster}.linodeobjects.com"
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
skip_region = true
|
||||
skip_credentials_validation = true
|
||||
skip_metadata_api_check = true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
| Variable | Description | Type | Default |
|
||||
|----------|-------------|------|---------|
|
||||
| `environment` | Deployment environment | string | `"staging"` |
|
||||
| `linode_object_storage_cluster` | Object Storage cluster/region | string | `"us-east-1"` |
|
||||
| `object_storage_access_key` | Access key for Object Storage | string | - |
|
||||
| `object_storage_secret_key` | Secret key for Object Storage (sensitive) | string | - |
|
||||
|
||||
## Outputs
|
||||
|
||||
| Output | Description |
|
||||
|--------|-------------|
|
||||
| `backend_bucket` | Name of the state bucket |
|
||||
| `backend_key` | Path to state file within bucket |
|
||||
| `backend_region` | Object Storage cluster/region |
|
||||
| `backend_endpoint` | S3-compatible endpoint URL |
|
||||
@@ -0,0 +1,6 @@
|
||||
# Backend module example configuration
|
||||
|
||||
environment = "staging"
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
@@ -0,0 +1,16 @@
|
||||
# Backend configuration for HAPI Terraform state
|
||||
|
||||
terraform {
|
||||
backend "s3" {
|
||||
# State stored in Object Storage
|
||||
bucket = "hapi-terraform-state-${var.environment}"
|
||||
key = "hapi/terraform.tfstate"
|
||||
region = var.linode_object_storage_cluster
|
||||
endpoint = "${var.linode_object_storage_cluster}.linodeobjects.com"
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
skip_region = true
|
||||
skip_credentials_validation = true
|
||||
skip_metadata_api_check = true
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# Backend outputs
|
||||
|
||||
output "backend_bucket" {
|
||||
description = "Name of the state bucket"
|
||||
value = "hapi-terraform-state-${var.environment}"
|
||||
}
|
||||
|
||||
output "backend_key" {
|
||||
description = "Path to state file within bucket"
|
||||
value = "hapi/terraform.tfstate"
|
||||
}
|
||||
|
||||
output "backend_region" {
|
||||
description = "Object Storage cluster/region"
|
||||
value = var.linode_object_storage_cluster
|
||||
}
|
||||
|
||||
output "backend_endpoint" {
|
||||
description = "S3-compatible endpoint URL"
|
||||
value = "${var.linode_object_storage_cluster}.linodeobjects.com"
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
# Backend example configuration
|
||||
|
||||
environment = "staging"
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
@@ -0,0 +1,28 @@
|
||||
# Backend variables
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
default = "staging"
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
|
||||
variable "linode_object_storage_cluster" {
|
||||
description = "Linode Object Storage cluster for backend state storage"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "object_storage_access_key" {
|
||||
description = "Linode Object Storage access key for backend state storage"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "object_storage_secret_key" {
|
||||
description = "Linode Object Storage secret key for backend state storage"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
# Main Terraform configuration for HAPI infrastructure
|
||||
# This file orchestrates all infrastructure components
|
||||
|
||||
terraform {
|
||||
required_version = ">= 1.9.0"
|
||||
|
||||
required_providers {
|
||||
linode = {
|
||||
source = "linode/linode"
|
||||
version = "~> 2.0"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "~> 3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Provider configurations are in providers.tf
|
||||
|
||||
# Modules
|
||||
module "backend" {
|
||||
source = "./backend"
|
||||
|
||||
environment = var.environment
|
||||
linode_object_storage_cluster = var.linode_object_storage_cluster
|
||||
object_storage_access_key = var.object_storage_access_key
|
||||
object_storage_secret_key = var.object_storage_secret_key
|
||||
}
|
||||
|
||||
module "postgres" {
|
||||
source = "./postgres"
|
||||
|
||||
linode_region = var.linode_region
|
||||
linode_object_storage_cluster = var.linode_object_storage_cluster
|
||||
object_storage_access_key = var.object_storage_access_key
|
||||
object_storage_secret_key = var.object_storage_secret_key
|
||||
environment = var.environment
|
||||
}
|
||||
|
||||
module "storage" {
|
||||
source = "./storage"
|
||||
|
||||
linode_region = var.linode_region
|
||||
linode_object_storage_cluster = var.linode_object_storage_cluster
|
||||
environment = var.environment
|
||||
object_storage_access_key = var.object_storage_access_key
|
||||
object_storage_secret_key = var.object_storage_secret_key
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "./network"
|
||||
|
||||
linode_region = var.linode_region
|
||||
environment = var.environment
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
# Networking module for HAPI
|
||||
# Creates firewall rules for API, PostgreSQL, and Adminer
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
linode = {
|
||||
source = "linode/linode"
|
||||
version = "~> 2.0"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "~> 3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "linode_firewall" "hapi" {
|
||||
label = "hapi-firewall-${var.environment}"
|
||||
tags = toset([for k, v in var.tags : "${k}=${v}"])
|
||||
|
||||
# Default policies - DROP for security (explicit ACCEPT rules for allowed traffic)
|
||||
inbound_policy = "DROP"
|
||||
outbound_policy = "DROP"
|
||||
|
||||
# Inbound rules
|
||||
inbound {
|
||||
action = "ACCEPT"
|
||||
label = "allow-api-${var.environment}"
|
||||
protocol = "TCP"
|
||||
ports = "8000"
|
||||
ipv4 = ["0.0.0.0/0"]
|
||||
ipv6 = ["::/0"]
|
||||
}
|
||||
|
||||
inbound {
|
||||
action = "ACCEPT"
|
||||
label = "allow-postgres-${var.environment}"
|
||||
protocol = "TCP"
|
||||
ports = "5432"
|
||||
ipv4 = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
|
||||
}
|
||||
|
||||
inbound {
|
||||
action = "ACCEPT"
|
||||
label = "allow-adminer-${var.environment}"
|
||||
protocol = "TCP"
|
||||
ports = "8080"
|
||||
ipv4 = ["0.0.0.0/0"]
|
||||
ipv6 = ["::/0"]
|
||||
}
|
||||
|
||||
inbound {
|
||||
action = "ACCEPT"
|
||||
label = "allow-https-${var.environment}"
|
||||
protocol = "TCP"
|
||||
ports = "443"
|
||||
ipv4 = ["0.0.0.0/0"]
|
||||
ipv6 = ["::/0"]
|
||||
}
|
||||
|
||||
inbound {
|
||||
action = "ACCEPT"
|
||||
label = "allow-http-${var.environment}"
|
||||
protocol = "TCP"
|
||||
ports = "80"
|
||||
ipv4 = ["0.0.0.0/0"]
|
||||
ipv6 = ["::/0"]
|
||||
}
|
||||
|
||||
# Outbound rules
|
||||
outbound {
|
||||
action = "ACCEPT"
|
||||
label = "allow-all-outbound-${var.environment}"
|
||||
protocol = "TCP"
|
||||
ports = "0-65535"
|
||||
ipv4 = ["0.0.0.0/0"]
|
||||
ipv6 = ["::/0"]
|
||||
}
|
||||
}
|
||||
|
||||
# Firewall rule configurations
|
||||
locals {
|
||||
firewall_config = {
|
||||
staging = {
|
||||
api_port = 8000
|
||||
postgres_port = 5432
|
||||
adminer_port = 8080
|
||||
}
|
||||
production = {
|
||||
api_port = 8000
|
||||
postgres_port = 5432
|
||||
adminer_port = 8080
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "firewall_rules" {
|
||||
description = "Firewall rules configuration"
|
||||
value = {
|
||||
api = {
|
||||
port = 8000
|
||||
protocol = "tcp"
|
||||
cidrs = ["0.0.0.0/0", "::/0"]
|
||||
}
|
||||
postgres = {
|
||||
port = 5432
|
||||
protocol = "tcp"
|
||||
cidrs = ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"]
|
||||
}
|
||||
adminer = {
|
||||
port = 8080
|
||||
protocol = "tcp"
|
||||
cidrs = ["0.0.0.0/0", "::/0"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output "firewall_id" {
|
||||
description = "ID of the main firewall"
|
||||
value = linode_firewall.hapi.id
|
||||
}
|
||||
|
||||
output "firewall_label" {
|
||||
description = "Label of the main firewall"
|
||||
value = linode_firewall.hapi.label
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Network module example configuration
|
||||
|
||||
# Linode region for infrastructure
|
||||
linode_region = "us-east"
|
||||
|
||||
# Object Storage cluster/region for backend state and buckets
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
|
||||
# Environment (affects firewall and resource naming)
|
||||
environment = "staging"
|
||||
|
||||
# Object Storage credentials (for backend state)
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
@@ -0,0 +1,31 @@
|
||||
# Variables for Networking module
|
||||
|
||||
variable "linode_region" {
|
||||
description = "Linode region for networking resources"
|
||||
type = string
|
||||
default = "us-east"
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags for all resources"
|
||||
type = map(string)
|
||||
default = {
|
||||
ManagedBy = "terraform"
|
||||
Project = "hapi"
|
||||
}
|
||||
}
|
||||
|
||||
variable "linode_object_storage_cluster" {
|
||||
description = "Linode Object Storage cluster for backend state storage"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
# Outputs for HAPI Terraform infrastructure
|
||||
|
||||
output "postgres_endpoint" {
|
||||
description = "PostgreSQL endpoint for the environment (Kubernetes API endpoint)"
|
||||
value = module.postgres.endpoint
|
||||
}
|
||||
|
||||
output "postgres_port" {
|
||||
description = "PostgreSQL port"
|
||||
value = module.postgres.port
|
||||
}
|
||||
|
||||
output "postgres_database" {
|
||||
description = "PostgreSQL database name"
|
||||
value = module.postgres.database
|
||||
}
|
||||
|
||||
output "postgres_username" {
|
||||
description = "PostgreSQL username"
|
||||
value = module.postgres.username
|
||||
}
|
||||
|
||||
output "postgres_password" {
|
||||
description = "PostgreSQL password (sensitive)"
|
||||
value = module.postgres.password
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "object_storage_endpoint" {
|
||||
description = "Object Storage endpoint"
|
||||
value = module.storage.endpoint
|
||||
}
|
||||
|
||||
output "object_storage_access_key" {
|
||||
description = "Object Storage access key"
|
||||
value = module.storage.access_key
|
||||
}
|
||||
|
||||
output "object_storage_secret_key" {
|
||||
description = "Object Storage secret key (sensitive)"
|
||||
value = module.storage.secret_key
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "firewall_rules" {
|
||||
description = "Firewall rules configuration"
|
||||
value = module.network.firewall_rules
|
||||
}
|
||||
|
||||
output "firewall_id" {
|
||||
description = "Linode firewall ID"
|
||||
value = module.network.firewall_id
|
||||
}
|
||||
|
||||
output "firewall_label" {
|
||||
description = "Linode firewall label"
|
||||
value = module.network.firewall_label
|
||||
}
|
||||
|
||||
output "terraform_backend_config" {
|
||||
description = "Configuration for Terraform backend in Object Storage"
|
||||
value = {
|
||||
bucket = module.backend.backend_bucket
|
||||
key = module.backend.backend_key
|
||||
region = module.backend.backend_region
|
||||
}
|
||||
}
|
||||
|
||||
output "backend_endpoint" {
|
||||
description = "Object Storage endpoint for backend state"
|
||||
value = module.backend.backend_endpoint
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
# 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(["staging", "production"])
|
||||
|
||||
label = "hapi-postgres-state-${each.key}"
|
||||
region = 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 = 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}"
|
||||
}
|
||||
@@ -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,20 @@
|
||||
# PostgreSQL module example configuration
|
||||
|
||||
# Linode region for LKE cluster
|
||||
linode_region = "us-east"
|
||||
|
||||
# LKE Kubernetes version
|
||||
linode_lke_version = "1.30"
|
||||
|
||||
# Node type for LKE pool
|
||||
linode_node_type = "g6-standard-4"
|
||||
|
||||
# Object Storage cluster/region for state storage
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
|
||||
# Object Storage credentials (for state storage)
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
|
||||
# Environment (affects cluster and database naming)
|
||||
environment = "staging"
|
||||
@@ -0,0 +1,54 @@
|
||||
# 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"
|
||||
}
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# Provider configurations for HAPI Terraform infrastructure
|
||||
|
||||
# Provider configurations
|
||||
# These use the sources defined in main.tf terraform block
|
||||
|
||||
provider "linode" {
|
||||
token = var.linode_token
|
||||
}
|
||||
|
||||
provider "random" {}
|
||||
@@ -0,0 +1,33 @@
|
||||
# Object Storage module for HAPI
|
||||
# Creates buckets for uploads and Terraform state
|
||||
|
||||
terraform {
|
||||
required_providers {
|
||||
linode = {
|
||||
source = "linode/linode"
|
||||
version = "~> 2.0"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "~> 3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "linode_object_storage_bucket" "uploads" {
|
||||
for_each = toset(["staging", "production"])
|
||||
|
||||
label = "hapi-uploads-${each.key}"
|
||||
region = var.linode_object_storage_cluster
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
}
|
||||
|
||||
resource "linode_object_storage_bucket" "state" {
|
||||
for_each = toset(["staging", "production"])
|
||||
|
||||
label = "hapi-terraform-state-${each.key}"
|
||||
region = var.linode_object_storage_cluster
|
||||
access_key = var.object_storage_access_key
|
||||
secret_key = var.object_storage_secret_key
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# Outputs for Object Storage module
|
||||
|
||||
output "endpoint" {
|
||||
description = "Object Storage endpoint"
|
||||
value = var.linode_object_storage_cluster
|
||||
}
|
||||
|
||||
output "access_key" {
|
||||
description = "Object Storage access key"
|
||||
value = var.object_storage_access_key
|
||||
}
|
||||
|
||||
output "secret_key" {
|
||||
description = "Object Storage secret key (sensitive)"
|
||||
value = var.object_storage_secret_key
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
output "state_bucket_name" {
|
||||
description = "Name of the Terraform state bucket"
|
||||
value = "hapi-terraform-state-${var.environment}"
|
||||
}
|
||||
|
||||
output "uploads_bucket_name" {
|
||||
description = "Name of the uploads bucket"
|
||||
value = "hapi-uploads-${var.environment}"
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# Storage module example configuration
|
||||
|
||||
# Linode region for infrastructure
|
||||
linode_region = "us-east"
|
||||
|
||||
# Object Storage cluster (v2 uses 'region' instead of 'cluster')
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
|
||||
# Object Storage credentials
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
|
||||
# Environment (affects bucket and firewall naming)
|
||||
environment = "staging"
|
||||
@@ -0,0 +1,42 @@
|
||||
# Variables for Object Storage module
|
||||
|
||||
variable "linode_region" {
|
||||
description = "Linode region for Object Storage"
|
||||
type = string
|
||||
default = "us-east"
|
||||
}
|
||||
|
||||
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 "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags for all resources"
|
||||
type = map(string)
|
||||
default = {
|
||||
ManagedBy = "terraform"
|
||||
Project = "hapi"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
# HAPI Infrastructure Configuration
|
||||
# Copy to terraform.tfvars or use with -var-file
|
||||
|
||||
# Linode configuration
|
||||
linode_token = "your-linode-api-token"
|
||||
linode_region = "us-east"
|
||||
linode_object_storage_cluster = "us-east-1"
|
||||
|
||||
# Object Storage credentials
|
||||
object_storage_access_key = "your-access-key"
|
||||
object_storage_secret_key = "your-secret-key"
|
||||
|
||||
# Environment
|
||||
environment = "staging" # or "production"
|
||||
@@ -0,0 +1,56 @@
|
||||
# Variables for HAPI Terraform infrastructure
|
||||
|
||||
variable "linode_token" {
|
||||
description = "Linode API token for authentication"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "linode_region" {
|
||||
description = "Default Linode region for resources"
|
||||
type = string
|
||||
default = "us-east"
|
||||
}
|
||||
|
||||
variable "environment" {
|
||||
description = "Deployment environment (staging or production)"
|
||||
type = string
|
||||
default = "staging"
|
||||
validation {
|
||||
condition = contains(["staging", "production"], var.environment)
|
||||
error_message = "Environment must be 'staging' or 'production'."
|
||||
}
|
||||
}
|
||||
|
||||
variable "project_name" {
|
||||
description = "Name of the HAPI project"
|
||||
type = string
|
||||
default = "hapi"
|
||||
}
|
||||
|
||||
variable "tags" {
|
||||
description = "Common tags for all resources"
|
||||
type = map(string)
|
||||
default = {
|
||||
ManagedBy = "terraform"
|
||||
Project = "hapi"
|
||||
}
|
||||
}
|
||||
|
||||
# Backend configuration variables
|
||||
variable "object_storage_access_key" {
|
||||
description = "Linode Object Storage access key for backend state storage"
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "object_storage_secret_key" {
|
||||
description = "Linode Object Storage secret key for backend state storage"
|
||||
type = string
|
||||
sensitive = true
|
||||
}
|
||||
|
||||
variable "linode_object_storage_cluster" {
|
||||
description = "Linode Object Storage cluster for backend state storage"
|
||||
type = string
|
||||
default = "us-east-1"
|
||||
}
|
||||
Reference in new issue
Block a user