# Terraform Environments

Per-environment workspace configuration for the Oshun platform.

## Bootstrap (one-time)

Before `terraform init` succeeds, the state backend must exist:

1. Create the S3 state bucket **per environment**:
   - `oshun-terraform-state-development`
   - `oshun-terraform-state-staging`
   - `oshun-terraform-state-production` With versioning enabled and
     public-access blocked.
2. Create a single DynamoDB table `oshun-terraform-locks` with primary key
   `LockID` (string).
3. Create a KMS CMK aliased `alias/oshun-terraform-state` with key-rotation
   enabled.

The `bootstrap/` directory contains a minimal Terraform config that provisions
these resources using local state. Run it once per AWS account:

```bash
cd bootstrap
terraform init
terraform apply -var="state_bucket_prefix=oshun-terraform-state"
```

## Per-environment workflow

```bash
# development
terraform init -backend-config=environments/development.backend.hcl -reconfigure
terraform plan  -var-file=environments/development.tfvars
terraform apply -var-file=environments/development.tfvars

# staging
terraform init -backend-config=environments/staging.backend.hcl -reconfigure
terraform plan  -var-file=environments/staging.tfvars

# production (with extra guardrails)
terraform init -backend-config=environments/production.backend.hcl -reconfigure
terraform plan  -var-file=environments/production.tfvars -out=prod.tfplan
terraform apply prod.tfplan
```

Do **not** rely on Terraform CLI workspaces (`terraform workspace new`). We use
separate state buckets per environment for hard blast-radius isolation.
