This project implements a custom HTTP backend for Terraform using FastAPI. It provides endpoints for state management and locking, allowing Terraform to store and retrieve state information, as well as implement state locking for concurrent operations.
- Store and retrieve Terraform state
- Implement state locking mechanism
- Compatible with Terraform's HTTP backend
see requirements.txt
- Clone this repository:
git clone git@github.com:mikelv702/simple-terraform-backend.git
- Install the required packages:
uv pip install -r requirements.txt
- Start the FastAPI server:
cd src/
fastapi dev main.py
- Configure Terraform to use this backend:
terraform {
backend "http" {
address = "http://localhost:8000/tfstate/${PROJECT_ID}"
lock_address = "http://localhost:8000/tfstate/${PROJECT_ID}/lock"
unlock_address = "http://localhost:8000/tfstate/${PROJECT_ID}/lock"
}
}
- Use Terraform as normal. The state will be stored and retrieved from your FastAPI backend.
This is a basic implementation and should not be used in production without further security measures and persistent storage solutions.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.