3.1 KiB
3.1 KiB
Quickstart: HAPI Infrastructure with Terraform
Prerequisites
- Linode Account - Get your API token from the Linode Cloud Manager
- Terraform - Version 1.9.0 or higher
- 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 stringpostgres_port- Database port (5432)postgres_database- Database namepostgres_username/postgres_password- Credentialsobject_storage_endpoint- S3-compatible endpointobject_storage_access_key/object_storage_secret_key- Storage credentialsfirewall_rules- Network access configuration
Next Steps
- Set up CI/CD - Configure Gitea Actions to run Terraform on changes
- Configure Database - Run Alembic migrations on the new PostgreSQL instances
- Set up Object Storage - Configure upload buckets for the API
- Configure Firewall - Ensure API and Adminer can connect
Troubleshooting
Common Issues
- Authentication errors - Verify
LINODE_TOKENhas Object Storage permissions - Bucket not found - Ensure Object Storage cluster matches configuration
- 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