A FastAPI blog application demonstrating how to use Terraform as a one-shot initialization container in Docker Compose. This eliminates "works on my machine" problems by ensuring identical infrastructure setup across local development, CI, and production environments.
- Deterministic infrastructure setup - Terraform runs automatically before your app starts
- Local ↔ CI parity - Same containers, same flow everywhere
- Real integration tests - Tests run against actual Elasticsearch, not mocks
- No manual setup steps -
docker compose upcreates everything you need
- Clone and start the stack:
git clone https://github.com/u11d-com/blog_test-stack-in-gh-actions
cd blog_test-stack-in-gh-actions
docker compose up -d- Wait for Terraform to finish setup:
# Check that terraform container exited successfully
docker compose ps terraform- Run tests:
uv sync --group dev
uv run pytest -v- Start the API server:
uv run fastapi devThen navigate to http://localhost:8000/docs to explore the API using Swagger UI.
The stack starts services in a specific order:
- MinIO (S3-compatible storage for Terraform state)
- Elasticsearch (document database)
- Terraform (creates indices and API keys, then exits)
- Your app can now start with guaranteed infrastructure
The key insight: infrastructure setup is code that runs automatically, not manual steps in a README.
├── app/ # FastAPI application
│ ├── blogs/ # Blog CRUD endpoints
│ └── main.py # App entry point
├── terraform/ # Infrastructure as code
│ ├── elasticsearch.tf # Index and API key definitions
│ └── local.tfvars # Local environment config
├── tests/ # Integration tests
└── compose.yaml # Complete development stack
Tests run against the real infrastructure stack, not mocks:
- Elasticsearch indices with proper mappings
- Actual API key authentication
- Full CRUD operations with audit logging
- Data validation at the database level
When tests pass, you know the entire system works together.
The same Terraform code deploys to production with different variables:
- Update
terraform/prod.tfvarswith production Elasticsearch URL - Run
terraform apply -var-file=prod.tfvars - Deploy app with production environment variables
No configuration drift, no manual setup, no surprises.
This project accompanies the blog post: "From 'It Worked On My Machine' to Deterministic Confidence"