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:
Bobby committed 2026-11-17 23:29:19 -05:00
1 parent 27abc1891b
commit a5047cb72e
17 files changed
+581 -121

No files matched your search

@@ -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)
@@ -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)