01: infra
This commit is contained in:
1 parent
ec9bb74be0
commit
341cd05ac5
71 files changed
+2058
-1
No files matched your search
@@ -0,0 +1,136 @@
|
||||
# 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
|
||||
|
||||
```bash
|
||||
cd infra
|
||||
|
||||
# Copy the example environment file
|
||||
cp .env.example .env
|
||||
|
||||
# Edit .env with your credentials
|
||||
vim .env
|
||||
```
|
||||
|
||||
Or export directly:
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
make init
|
||||
# or
|
||||
terraform init
|
||||
```
|
||||
|
||||
For remote backend (state in Object Storage):
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
make plan
|
||||
# or
|
||||
terraform plan -var="environment=staging"
|
||||
```
|
||||
|
||||
### 4. Apply Infrastructure
|
||||
|
||||
```bash
|
||||
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
|
||||
```bash
|
||||
make apply ENV=staging
|
||||
make destroy ENV=staging
|
||||
```
|
||||
|
||||
### Production
|
||||
```bash
|
||||
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
|
||||
|
||||
```bash
|
||||
# Verbose logging
|
||||
export TF_LOG=DEBUG
|
||||
|
||||
# Show detailed plan
|
||||
terraform plan -detailed-exitcode
|
||||
|
||||
# Refresh state
|
||||
terraform refresh
|
||||
```
|
||||
Reference in new issue
Block a user