Files
hapi/infra/QUICKSTART.md
T
2026-11-17 14:39:40 -05:00

3.1 KiB

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

cd infra

# Copy the example environment file
cp .env.example .env

# Edit .env with your credentials
vim .env

Or export directly:

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

make init
# or
terraform init

For remote backend (state in Object Storage):

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

make plan
# or
terraform plan -var="environment=staging"

4. Apply Infrastructure

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

make apply ENV=staging
make destroy ENV=staging

Production

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

# Verbose logging
export TF_LOG=DEBUG

# Show detailed plan
terraform plan -detailed-exitcode

# Refresh state
terraform refresh