feat: Linode Provider v2 migration and backend module
- 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
This commit is contained in:
1 parent
27abc1891b
commit
a5047cb72e
17 files changed
+581
-121
No files matched your search
+44
-4
@@ -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.
|
||||
@@ -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 |
|
||||
@@ -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 = "<YOUR_LINODE_API_TOKEN>"
|
||||
linode_region = "us-east"
|
||||
environment = "staging" # or "production"
|
||||
project_name = "hapi"
|
||||
|
||||
# Object Storage credentials
|
||||
object_storage_access_key = "<YOUR_ACCESS_KEY>"
|
||||
object_storage_secret_key = "<YOUR_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"
|
||||
+12
-51
@@ -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
|
||||
}
|
||||
@@ -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"
|
||||
}
|
||||
@@ -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"
|
||||
+17
-31
@@ -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
|
||||
}
|
||||
+9
-12
@@ -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"
|
||||
|
||||
|
||||
@@ -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"
|
||||
+19
-4
@@ -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
|
||||
}
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
@@ -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"
|
||||
Reference in new issue
Block a user