From a5047cb72e2305b6204e6792c578e7c8237abd0f Mon Sep 17 00:00:00 2001 From: Bobby Date: Tue, 17 Nov 2026 23:29:19 -0500 Subject: [PATCH] feat: Linode Provider v2 migration and backend module MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Documented Linode Terraform Provider v2 migration in ADR-0002 - Created dedicated backend module for state storage - Updated all modules for v2 patterns (cluster→region, pools→pool, tags) - Added firewall outputs and backend outputs - Updated example tfvars files with v2 configurations - Updated AGENTS.md, README.md, and documentation --- AGENTS.md | 22 +++ ...01-linode-infrastructure-with-terraform.md | 17 +- ...-linode-provider-v2-migration-quick-ref.md | 174 ++++++++++++++++++ docs/adr/0002-linode-provider-v2-migration.md | 156 ++++++++++++++++ infra/README.md | 48 ++++- infra/backend/README.md | 41 +++++ infra/backend/example.tfvars | 18 +- infra/backend/main.tf | 63 ++----- infra/backend/outputs.tf | 21 +++ infra/backend/terraform.tfvars.example | 9 +- infra/backend/variables.tf | 48 ++--- infra/main.tf | 21 +-- infra/network/terraform.tfvars.example | 9 + infra/outputs.tf | 23 ++- infra/postgres/terraform.tfvars.example | 11 ++ infra/storage/terraform.tfvars.example | 7 + infra/terraform.tfvars.example | 14 ++ 17 files changed, 581 insertions(+), 121 deletions(-) create mode 100644 docs/adr/0002-linode-provider-v2-migration-quick-ref.md create mode 100644 docs/adr/0002-linode-provider-v2-migration.md create mode 100644 infra/backend/README.md create mode 100644 infra/backend/outputs.tf create mode 100644 infra/terraform.tfvars.example diff --git a/AGENTS.md b/AGENTS.md index b4fb98b..d04f01c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -15,3 +15,25 @@ Five canonical triage roles mapped to labels: `needs-triage`, `needs-info`, `rea ### 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`) diff --git a/docs/adr/0001-linode-infrastructure-with-terraform.md b/docs/adr/0001-linode-infrastructure-with-terraform.md index b98ada5..a694685 100644 --- a/docs/adr/0001-linode-infrastructure-with-terraform.md +++ b/docs/adr/0001-linode-infrastructure-with-terraform.md @@ -128,9 +128,24 @@ make output # Show outputs 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) -- [Linode Terraform Provider](https://registry.terraform.io/providers/linode/linode/latest/docs) +- [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) diff --git a/docs/adr/0002-linode-provider-v2-migration-quick-ref.md b/docs/adr/0002-linode-provider-v2-migration-quick-ref.md new file mode 100644 index 0000000..9c33721 --- /dev/null +++ b/docs/adr/0002-linode-provider-v2-migration-quick-ref.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) diff --git a/docs/adr/0002-linode-provider-v2-migration.md b/docs/adr/0002-linode-provider-v2-migration.md new file mode 100644 index 0000000..204d443 --- /dev/null +++ b/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) diff --git a/infra/README.md b/infra/README.md index ab0d271..2821ef5 100644 --- a/infra/README.md +++ b/infra/README.md @@ -2,6 +2,31 @@ 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 ``` @@ -21,6 +46,7 @@ infra/ - 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 @@ -62,7 +88,8 @@ terraform apply -var="environment=production" ## Resources Provisioned ### PostgreSQL -- Database instance (staging and production) +- LKE (Linode Kubernetes Engine) cluster for staging and production +- Database instances within clusters (`hapi_staging`, `hapi_production`) - Connection pooling configuration - Automated backups @@ -70,19 +97,21 @@ terraform apply -var="environment=production" - 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 +- Inbound and outbound rules with DROP policy by default +- Environment-specific firewall labels ## Outputs -- PostgreSQL endpoint, port, database name, credentials +- PostgreSQL endpoint (Kubernetes API endpoint), port, database name, credentials - Object Storage endpoint, access keys -- Firewall configuration +- Firewall configuration (rules, ID, and label) - Terraform backend configuration ## Environment-Specific Configuration @@ -110,3 +139,14 @@ Terraform state is automatically stored in Linode Object Storage under the confi ### 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. diff --git a/infra/backend/README.md b/infra/backend/README.md new file mode 100644 index 0000000..ea40056 --- /dev/null +++ b/infra/backend/README.md @@ -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 | diff --git a/infra/backend/example.tfvars b/infra/backend/example.tfvars index ee9a620..6a85076 100644 --- a/infra/backend/example.tfvars +++ b/infra/backend/example.tfvars @@ -1,14 +1,6 @@ -# Terraform Backend Configuration -# Configure this in your main terraform.tfvars or environment variables +# Backend module example configuration -# Linode Object Storage as Terraform backend -# Copy this to your terraform.tfvars or set as environment variables - -linode_token = "" -linode_region = "us-east" -environment = "staging" # or "production" -project_name = "hapi" - -# Object Storage credentials -object_storage_access_key = "" -object_storage_secret_key = "" +environment = "staging" +linode_object_storage_cluster = "us-east-1" +object_storage_access_key = "your-access-key" +object_storage_secret_key = "your-secret-key" diff --git a/infra/backend/main.tf b/infra/backend/main.tf index 297e8f9..de8aa79 100644 --- a/infra/backend/main.tf +++ b/infra/backend/main.tf @@ -1,55 +1,16 @@ -# Backend configuration for Terraform state in Linode Object Storage -# This module provides the configuration needed for remote state storage +# Backend configuration for HAPI Terraform state terraform { - required_providers { - linode = { - source = "linode/linode" - version = "~> 2.0" - } - random = { - source = "hashicorp/random" - version = "~> 3.0" - } + 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 } } - -resource "linode_object_storage_bucket" "terraform_state" { - label = "hapi-terraform-state-${var.environment}" - region = var.linode_object_storage_cluster - access_key = var.object_storage_access_key - secret_key = var.object_storage_secret_key -} - -locals { - backend_config = { - bucket = "hapi-terraform-state-${var.environment}" - key = "terraform/${var.environment}/terraform.tfstate" - region = var.linode_region - endpoint = "https://${var.linode_region}.linodeobjects.com" - encrypt = true - access_key = var.object_storage_access_key - secret_key = var.object_storage_secret_key - skip_region_validation = true - } -} - -output "backend_config" { - description = "Terraform backend configuration" - value = local.backend_config -} - -output "backend_s3_config" { - description = "S3-style backend configuration for Terraform" - value = { - bucket = local.backend_config.bucket - key = local.backend_config.key - region = local.backend_config.region - endpoint = local.backend_config.endpoint - encrypt = local.backend_config.encrypt - access_key = local.backend_config.access_key - secret_key = local.backend_config.secret_key - skip_region_validation = local.backend_config.skip_region_validation - } - sensitive = true -} diff --git a/infra/backend/outputs.tf b/infra/backend/outputs.tf new file mode 100644 index 0000000..b588c39 --- /dev/null +++ b/infra/backend/outputs.tf @@ -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" +} diff --git a/infra/backend/terraform.tfvars.example b/infra/backend/terraform.tfvars.example index 25f654b..000976c 100644 --- a/infra/backend/terraform.tfvars.example +++ b/infra/backend/terraform.tfvars.example @@ -1,7 +1,6 @@ -# Backend module example configuration +# Backend example configuration -linode_region = "us-east" +environment = "staging" linode_object_storage_cluster = "us-east-1" -object_storage_access_key = "your-access-key" -object_storage_secret_key = "your-secret-key" -environment = "staging" +object_storage_access_key = "your-access-key" +object_storage_secret_key = "your-secret-key" diff --git a/infra/backend/variables.tf b/infra/backend/variables.tf index f423a63..10cda1a 100644 --- a/infra/backend/variables.tf +++ b/infra/backend/variables.tf @@ -1,42 +1,28 @@ -# Variables for Backend 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 -} +# 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 "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 "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 } diff --git a/infra/main.tf b/infra/main.tf index 4c7f513..1826773 100644 --- a/infra/main.tf +++ b/infra/main.tf @@ -14,23 +14,20 @@ terraform { version = "~> 3.0" } } - - # Backend configuration for Terraform state using S3-compatible Linode Object Storage - backend "s3" { - bucket = "hapi-terraform-state-${var.environment}" - key = "terraform/${var.environment}/terraform.tfstate" - region = var.linode_region - endpoint = "https://${var.linode_region}.linodeobjects.com" - encrypt = true - access_key = var.object_storage_access_key - secret_key = var.object_storage_secret_key - skip_region_validation = true - } } # 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" diff --git a/infra/network/terraform.tfvars.example b/infra/network/terraform.tfvars.example index 3af7fed..4d0c647 100644 --- a/infra/network/terraform.tfvars.example +++ b/infra/network/terraform.tfvars.example @@ -1,5 +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" diff --git a/infra/outputs.tf b/infra/outputs.tf index eb54bae..15d4902 100644 --- a/infra/outputs.tf +++ b/infra/outputs.tf @@ -1,7 +1,7 @@ # Outputs for HAPI Terraform infrastructure output "postgres_endpoint" { - description = "PostgreSQL endpoint for the environment" + description = "PostgreSQL endpoint for the environment (Kubernetes API endpoint)" value = module.postgres.endpoint } @@ -47,11 +47,26 @@ output "firewall_rules" { 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.storage.state_bucket_name - key = "terraform/${var.environment}/terraform.tfstate" - region = var.linode_region + 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 +} diff --git a/infra/postgres/terraform.tfvars.example b/infra/postgres/terraform.tfvars.example index 82f7c73..c55b852 100644 --- a/infra/postgres/terraform.tfvars.example +++ b/infra/postgres/terraform.tfvars.example @@ -1,9 +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" diff --git a/infra/storage/terraform.tfvars.example b/infra/storage/terraform.tfvars.example index d389fe4..03c9ea0 100644 --- a/infra/storage/terraform.tfvars.example +++ b/infra/storage/terraform.tfvars.example @@ -1,7 +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" diff --git a/infra/terraform.tfvars.example b/infra/terraform.tfvars.example new file mode 100644 index 0000000..de48d84 --- /dev/null +++ b/infra/terraform.tfvars.example @@ -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"