Terraform Cloud Setup Guide¶
Archived record
This page describes the Firebase-era platform or a migration step that has completed. It is kept as history and is not a current runbook. The current platform is described from the home page.
Last Updated: February 26, 2026 Persona: GPCA + GHE Status: Active ✅
Overview¶
This guide walks you through setting up Terraform Cloud for the HCW platform infrastructure deployment, including configuring all required variables and secrets.
Prerequisites¶
- Terraform Cloud account (app.terraform.io)
- Hostinger API token
- Cloudflare API token and Zone ID
- SSH key pair generated
- Access to all service credentials
Step 1: Create Terraform Cloud Workspace¶
-
Log in to Terraform Cloud: Visit app.terraform.io
-
Create a new workspace:
- Click "New Workspace"
- Select "Version control workflow" (recommended) or "CLI-driven workflow"
- Connect to your GitHub repository:
saulpatinojr/Personal-Site_HCW - Set working directory:
platform/terraform -
Name the workspace:
hcw-infrastructure-prod -
Configure workspace settings:
- Go to Settings → General
- Execution Mode: Remote
- Terraform Version: 1.5+ (latest stable)
- Auto Apply: Disabled (manual approval recommended for production)
Step 2: Configure Terraform Variables¶
Navigate to your workspace → Variables tab.
Variable Types in Terraform Cloud¶
- Terraform Variables: Input variables used in your
.tffiles (fromvariables.tf) - Environment Variables: System-level variables (for provider authentication, CLI tools)
Required Variables Configuration¶
Category: Terraform Variables (marked as Terraform variable)¶
Add each variable with the following settings:
| Variable Name | Value | Sensitive | HCL | Description |
|---|---|---|---|---|
hostinger_api_token |
your-hostinger-token |
✅ Yes | ❌ No | Hostinger API token |
cloudflare_api_token |
your-cloudflare-token |
✅ Yes | ❌ No | Cloudflare API token |
cloudflare_zone_id |
your-zone-id |
❌ No | ❌ No | Cloudflare Zone ID |
ssh_public_key |
ssh-rsa AAAA... |
❌ No | ❌ No | Your SSH public key |
vps_plan |
kvm4 |
❌ No | ❌ No | VPS plan type |
datacenter |
us |
❌ No | ❌ No | Datacenter location |
hostname |
hcw-prod |
❌ No | ❌ No | VPS hostname |
domain |
hybridcloudworks.com |
❌ No | ❌ No | Base domain |
db_password |
generate-secure-password |
✅ Yes | ❌ No | PostgreSQL password |
n8n_encryption_key |
generate-with-openssl |
✅ Yes | ❌ No | n8n encryption key |
n8n_admin_user |
admin |
❌ No | ❌ No | n8n admin username |
n8n_admin_password |
secure-password |
✅ Yes | ❌ No | n8n admin password |
grafana_admin_user |
admin |
❌ No | ❌ No | Grafana admin username |
grafana_admin_password |
secure-password |
✅ Yes | ❌ No | Grafana admin password |
Category: Environment Variables (marked as Environment variable)¶
These are used by Terraform CLI and providers:
| Variable Name | Value | Sensitive | Description |
|---|---|---|---|
TFE_TOKEN |
your-terraform-cloud-token |
✅ Yes | Terraform Cloud API token (if using CLI) |
Step 3: How to Add Variables in Terraform Cloud UI¶
Method 1: Web UI (Recommended for First-Time Setup)¶
- Navigate to Variables:
- Open your workspace
-
Click "Variables" in the left sidebar
-
Add a Variable:
- Click "+ Add variable"
- Choose type: "Terraform variable" or "Environment variable"
- Enter variable name (exact match from table above)
- Enter value
- Check "Sensitive" if marked in table above
- Check "HCL" if the value is HCL code (arrays, objects) - typically ❌ No for your use case
-
Click "Save variable"
-
Repeat for all variables in the tables above
Method 2: Terraform Cloud API (Bulk Upload)¶
If you have many variables, you can use the API:
# Set your Terraform Cloud token
$TFC_TOKEN = "your-terraform-cloud-api-token"
$ORG_NAME = "your-org-name"
$WORKSPACE_NAME = "hcw-infrastructure-prod"
# Get workspace ID
$WORKSPACE_ID = (Invoke-RestMethod -Uri "https://app.terraform.io/api/v2/organizations/$ORG_NAME/workspaces/$WORKSPACE_NAME" -Headers @{"Authorization"="Bearer $TFC_TOKEN"}).data.id
# Create a variable (example)
$body = @{
data = @{
type = "vars"
attributes = @{
key = "hostinger_api_token"
value = "your-actual-token-here"
category = "terraform"
sensitive = $true
}
}
} | ConvertTo-Json -Depth 10
Invoke-RestMethod -Method POST -Uri "https://app.terraform.io/api/v2/workspaces/$WORKSPACE_ID/vars" -Headers @{"Authorization"="Bearer $TFC_TOKEN"; "Content-Type"="application/vnd.api+json"} -Body $body
Method 3: Terraform CLI with Variable Sets¶
Create reusable variable sets for shared values:
- Go to Organization Settings → Variable Sets
- Click "Create variable set"
- Name it (e.g., "HCW Shared Credentials")
- Add variables
- Apply to selected workspaces
Step 4: Generate Missing Secrets¶
SSH Key Pair (if not already generated)¶
# Generate SSH key pair
ssh-keygen -t rsa -b 4096 -C "terraform@hybridcloudworks.com" -f ~/.ssh/hybridcloudworks_deploy
# Display public key (copy this value)
Get-Content ~/.ssh/hybridcloudworks_deploy.pub
n8n Encryption Key¶
Secure Passwords¶
# Generate secure password (PowerShell)
Add-Type -AssemblyName System.Web
[System.Web.Security.Membership]::GeneratePassword(32, 8)
Step 5: Finding Your Values¶
Hostinger API Token¶
- Log in to Hostinger
- Go to VPS → API
- Generate new API token
- Copy token (shown only once)
Cloudflare API Token¶
- Log in to Cloudflare Dashboard
- Go to My Profile → API Tokens
- Click "Create Token"
- Use "Edit zone DNS" template
- Scope to specific zone:
hybridcloudworks.com - Create and copy token
Cloudflare Zone ID¶
- Open Cloudflare Dashboard
- Select domain: hybridcloudworks.com
- Scroll down on Overview page
- Find "Zone ID" in the right sidebar (under API section)
- Copy the value
VPS IPv4 & VPS ID¶
Note: These are outputs from Terraform, not inputs. After your first terraform apply:
- VPS will be created by Terraform
- Check Outputs tab in Terraform Cloud after apply
- Or run:
terraform output vps_ipv4
If you already have a VPS and want to import it:
# Find VPS ID in Hostinger panel
# Import existing resource
terraform import hostinger_vps.main <vps-id>
Step 6: Verify Configuration¶
Pre-flight Checklist¶
Before running Terraform:
- All required variables are set in Terraform Cloud
- Sensitive variables are marked as sensitive
- SSH public key format is correct (
ssh-rsa AAAA...) - Cloudflare API token has DNS edit permissions
- Hostinger API token is valid and not expired
- Generated secrets are stored securely (password manager)
Test Configuration¶
- Navigate to your workspace
- Click "Actions" → "Start new plan"
- Review the plan output
- Check for any missing variables (Terraform will error if required vars are missing)
Step 7: Running Terraform¶
Option A: Terraform Cloud UI¶
- Go to your workspace
- Click "Actions" → "Start new plan"
- Review plan output
- If approved, click "Confirm & Apply"
Option B: Terraform CLI (Local)¶
# Login to Terraform Cloud
terraform login
# Initialize
cd platform/terraform
terraform init
# Plan
terraform plan
# Apply
terraform apply
Variable Management Best Practices¶
Security¶
✅ Do:
- Mark all API tokens, passwords, and keys as Sensitive
- Use variable sets for shared credentials across workspaces
- Rotate credentials regularly (update in Terraform Cloud)
- Store backup of secrets in password manager (1Password, Bitwarden)
❌ Don't:
- Commit
terraform.tfvarsto version control - Share sensitive values in plain text (Slack, email)
- Use production credentials in development workspaces
Organization¶
- Naming Convention: Use exact variable names from
variables.tf - Descriptions: Add descriptions in Terraform Cloud UI for team members
- Variable Sets: Group related variables (e.g., "Cloudflare Credentials", "Database Secrets")
- Workspaces: Separate workspaces for
prod,staging,dev
Troubleshooting¶
Error: "Required variable not set"¶
Solution: Check that variable name in Terraform Cloud exactly matches variables.tf:
- Variable names are case-sensitive
- Check for typos (e.g.,
cloudflare_zone_idvscloudflare_zone_ID)
Error: "Invalid SSH key format"¶
Solution: Ensure you copied the public key (.pub file), not private key:
Error: "Cloudflare authentication failed"¶
Solution: Verify token permissions:
- Token must have Zone:DNS:Edit permission
- Token must be scoped to correct zone
- Check token hasn't expired
Error: "Hostinger API authentication failed"¶
Solution:
- Verify token is valid in Hostinger panel
- Check token hasn't been revoked
- Ensure API access is enabled for your account
Next Steps¶
After Terraform Cloud is configured:
- Run Initial Plan:
terraform planto verify configuration - Review Resources: Check what will be created before applying
- Apply Changes:
terraform applyto provision infrastructure - Configure DNS: Cloudflare DNS records will be created automatically
- Deploy Application: Proceed with deployment workflows
Related Documentation¶
- pipeline-deployment-guide.md - Full deployment pipeline
- architecture-infrastructure-complete.md - Infrastructure overview
- Platform Terraform configuration:
platform/terraform/
Quick Reference Card¶
Essential Commands¶
# Initialize Terraform
terraform init
# Validate configuration
terraform validate
# Plan changes
terraform plan
# Apply changes
terraform apply
# Show outputs
terraform output
# List workspaces
terraform workspace list
# Select workspace
terraform workspace select prod
Terraform Cloud URLs¶
- Dashboard: https://app.terraform.io
- Your Org: https://app.terraform.io/app/YOUR_ORG/workspaces
- API Docs: https://developer.hashicorp.com/terraform/cloud-docs/api-docs
Questions? Issues? Refer to Terraform Cloud Documentation or check the workspace run logs for detailed error messages.