Working in the UI
Developer guide for extending and customizing the Terraform Configuration Web UI.
Architecture Overview
The UI uses a template registry architecture. Templates are registered from external git repositories, cloned on demand, and managed through a SQLite database with drift detection.
ui/
βββ backend/ # FastAPI Python backend
β βββ app/
β β βββ api/ # API routers
β β β βββ templates.py # Template registry CRUD
β β β βββ tfvars_ui.py # Scaffold, export/import, drift
β β β βββ template_terraform.py # Plan/apply/destroy
β β β βββ aws.py # AWS resource discovery
β β β βββ gcp.py # GCP resource discovery
β β βββ services/ # Business logic
β β β βββ git_service.py # Git clone/pull
β β β βββ drift_service.py # Drift detection
β β β βββ file_hash_service.py # SHA-256 file scanning
β β β βββ scaffold_generator.py # tfvars.ui generation
β β β βββ hcl_parser.py # variables.tf parser
β β β βββ tfvars_example_parser.py # Annotation parser
β β βββ db/ # Database layer (SQLite)
β β β βββ crud.py # TemplateDB, FileHashDB
β β β βββ models.py # Pydantic models
β β βββ config.py # App settings
β βββ tests/ # 250+ pytest tests
βββ frontend/ # React/Vite frontend
β βββ src/
β β βββ components/
β β β βββ TerraformConfig.jsx # Main UI
β β β βββ TemplateRegistration.jsx # Register templates
β β β βββ DriftResolution.jsx # Resolve drift
β β βββ services/api.js # API client
β βββ nginx.conf # Production reverse proxy
βββ docker-compose.yml # Container deploymentData Flow
- User registers a template (git repo URL + path)
- Backend clones the repo, scans files, stores hashes in SQLite
- Scaffold generator creates
tfvars.uifromvariables.tf+terraform.tfvars.example - User enriches annotations, imports back
- Drift detection compares stored hashes with current repo state
- Terraform execution streams plan/apply/destroy output (blocks on hard-stop drift)
Starting the UI
First Time Setup
Install dependencies for both backend and frontend:
cd ui
./SETUP.shThis script:
- Creates a Python virtual environment using
uv - Installs Python dependencies (FastAPI, aiosqlite, boto3, etc.)
- Installs Node.js dependencies via
npm install
Running the UI
Use the restart script to start both services:
cd ui
./RESTART.shServices started:
- Backend (FastAPI): http://127.0.0.1:8000
- Frontend (Vite): http://localhost:3000
- API Docs (Swagger): http://127.0.0.1:8000/docs
Manual Startup
For development, you may want to run services separately:
Backend:
cd ui/backend
uv run uvicorn app.main:app --reload --port 8000Frontend:
cd ui/frontend
npm run devContainer Deployment
cd ui
docker compose up --buildThis starts backend (port 8000) and frontend (port 3000) with a shared registry-data volume for the SQLite database and cloned repositories.
Developer Topics
| Topic | Description |
|---|---|
| Annotation Reference | @ui- annotation tags for tfvars.ui and tfvars.example files |
| Registering Templates | How to add templates via the registry |
| Backend APIs | Template registry, tfvars.ui, and terraform execution endpoints |
| Parsers & Services | HCL parser, annotation parser, scaffold generator, drift detection |
| Cloud Provider APIs | Integrating AWS, Azure, GCP APIs |
| Frontend Development | React components, template selector, drift UI |
| Testing | Backend pytest suite (250+ tests) and frontend builds |
| Troubleshooting | Common issues and fixes |