Skip to content

Commit 0da1cf9

Browse files
authored
adds terraform scripts for deploying Bifrost (#1636)
## Summary Add Terraform modules for deploying Bifrost on AWS, GCP, and Azure with a unified interface. This enables infrastructure-as-code deployments across multiple cloud providers and services. ## Changes - Created a unified Terraform module structure with cloud-specific submodules - Implemented deployment options for AWS (ECS, EKS), GCP (GKE, Cloud Run), and Azure (AKS, ACI) - Added configuration handling that supports both file-based and variable-based approaches - Included examples for each cloud provider with documentation - Implemented resource provisioning for networking, compute, storage, and security components ## Type of change - [x] Feature - [x] Documentation ## Affected areas - [x] Docs ## How to test ```sh # AWS ECS Example cd terraform/examples/aws-ecs cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your values terraform init terraform plan terraform apply # GCP GKE Example cd terraform/examples/gcp-gke cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your values terraform init terraform plan terraform apply # Azure AKS Example cd terraform/examples/azure-aks cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your values terraform init terraform plan terraform apply ``` ## Breaking changes - [x] No ## Security considerations The modules handle sensitive configuration through cloud provider secret management services: - AWS: Secrets Manager - GCP: Secret Manager - Azure: Key Vault Configuration can be provided via Terraform variables or files, with proper sensitive marking to prevent exposure in logs. ## Checklist - [x] I updated documentation where needed - [x] I verified builds succeed
2 parents 14ce35f + 9b0360f commit 0da1cf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+6516
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,10 @@ npm-debug.log*
103103

104104
# Playwright
105105
playwright/.cache/
106+
107+
# Terraform
108+
.terraform/
109+
terraform.tfstate
110+
terraform.tfstate.backup
111+
*.tfvars
112+
!*.tfvars.example

docs/deployment-guides/k8s.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ icon: "cloud"
66

77
Deploy Bifrost on Kubernetes using Terraform. This guide breaks down the deployment into individual components for better understanding.
88

9+
<Note>
10+
Bifrost also provides a ready-to-use Terraform module that handles all the infrastructure setup for you.
11+
You can use it directly from GitHub:
12+
```hcl
13+
module "bifrost" {
14+
source = "github.com/maximhq/bifrost//terraform/modules/bifrost?ref=terraform/v0.1.0"
15+
cloud_provider = "aws" # "aws" | "gcp" | "azure" | "kubernetes"
16+
service = "eks" # AWS: "ecs" | "eks", GCP: "gke" | "cloud-run", Azure: "aks" | "aci", K8s: "deployment"
17+
region = "us-east-1"
18+
image_tag = "latest"
19+
}
20+
```
21+
See the [Terraform module README](https://github.com/maximhq/bifrost/tree/main/terraform) for full documentation and examples.
22+
</Note>
23+
924
<Note>
1025
If you are using Postgres/MySQL for config and log store, you can skip the Volume configuration and permission changes sections.
1126
</Note>

terraform/README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Bifrost Terraform Modules
2+
3+
Deploy Bifrost on AWS, GCP, Azure, or any Kubernetes cluster using a single Terraform module.
4+
5+
## Quick Start
6+
7+
Reference the module directly from GitHub. Pin to a specific release tag using `?ref=`:
8+
9+
```hcl
10+
module "bifrost" {
11+
source = "github.com/maximhq/bifrost//terraform/modules/bifrost?ref=terraform/v0.1.0"
12+
cloud_provider = "aws" # "aws" | "gcp" | "azure" | "kubernetes"
13+
service = "ecs" # AWS: "ecs" | "eks", GCP: "gke" | "cloud-run", Azure: "aks" | "aci", K8s: "deployment"
14+
region = "us-east-1"
15+
image_tag = "v1.4.6"
16+
17+
# Option A: Provide a config.json file
18+
config_json_file = "./config.json"
19+
20+
# Option B: Build config from Terraform variables (overrides matching keys from file)
21+
providers_config = {
22+
openai = { keys = [{ value = var.openai_key, weight = 1 }] }
23+
}
24+
config_store = {
25+
enabled = true
26+
type = "postgres"
27+
config = { host = var.db_host, port = "5432", user = "bifrost", password = var.db_password, db_name = "bifrost" }
28+
}
29+
}
30+
```
31+
32+
## Supported Deployments
33+
34+
| Cloud | Service | Description |
35+
|-------|---------|-------------|
36+
| AWS | `ecs` | ECS Fargate with ALB, Secrets Manager, auto-scaling |
37+
| AWS | `eks` | EKS with K8s Deployment, PVC for SQLite, HPA |
38+
| GCP | `gke` | GKE with K8s Deployment, persistent disk, HPA |
39+
| GCP | `cloud-run` | Cloud Run v2 with Secret Manager, auto-scaling |
40+
| Azure | `aks` | AKS with K8s Deployment, managed disk, HPA |
41+
| Azure | `aci` | Azure Container Instances (single instance, dev/test) |
42+
| Kubernetes | `deployment` | Any K8s cluster with Deployment, PVC, HPA, Ingress |
43+
44+
## Configuration
45+
46+
Bifrost config can come from two sources simultaneously. Terraform variables override matching keys from the base file.
47+
48+
1. **File-based**: Set `config_json_file` to a path or `config_json` to a raw JSON string.
49+
2. **Variable-based**: Set individual variables (`config_store`, `logs_store`, `providers_config`, `auth_config`, etc.) corresponding to top-level keys in [config.schema.json](../transports/config.schema.json).
50+
51+
All 16 top-level config properties from the schema are supported as variables:
52+
`encryption_key`, `auth_config`, `client`, `framework`, `providers_config`, `governance`, `mcp`, `vector_store`, `config_store`, `logs_store`, `cluster_config`, `saml_config`, `load_balancer_config`, `guardrails_config`, `plugins`, `audit_logs`.
53+
54+
## Directory Structure
55+
56+
```text
57+
terraform/
58+
modules/bifrost/ # Top-level module (the only thing you call)
59+
aws/ # AWS platform (VPC, SG, IAM, Secrets Manager)
60+
services/ecs/ # ECS Fargate
61+
services/eks/ # EKS + K8s resources
62+
gcp/ # GCP platform (VPC, firewall, Secret Manager, SA)
63+
services/gke/ # GKE + K8s resources
64+
services/cloud-run/ # Cloud Run v2
65+
azure/ # Azure platform (VNet, NSG, Key Vault, identity)
66+
services/aks/ # AKS + K8s resources
67+
services/aci/ # Azure Container Instances
68+
kubernetes/ # Generic K8s (any cluster, no cloud APIs)
69+
examples/
70+
aws-ecs/ # Deploy on ECS Fargate
71+
gcp-gke/ # Deploy on GKE
72+
azure-aks/ # Deploy on AKS
73+
kubernetes/ # Deploy on any K8s cluster
74+
```
75+
76+
## Examples
77+
78+
Each example directory contains `main.tf`, `variables.tf`, `outputs.tf`, `terraform.tfvars.example`, and a `README.md`.
79+
80+
```bash
81+
cd examples/aws-ecs
82+
cp terraform.tfvars.example terraform.tfvars
83+
# Edit terraform.tfvars with your values
84+
terraform init
85+
terraform plan
86+
terraform apply
87+
```
88+
89+
## Key Variables
90+
91+
| Variable | Default | Description |
92+
|----------|---------|-------------|
93+
| `cloud_provider` | (required) | `"aws"`, `"gcp"`, `"azure"`, or `"kubernetes"` |
94+
| `service` | (required) | Service type (see table above) |
95+
| `region` | (required) | Cloud region |
96+
| `image_tag` | `"latest"` | Bifrost Docker image tag |
97+
| `desired_count` | `1` | Number of replicas |
98+
| `cpu` | `512` | CPU units (ECS) or millicores (K8s) |
99+
| `memory` | `1024` | Memory in MB |
100+
| `create_load_balancer` | `false` | Create a load balancer |
101+
| `enable_autoscaling` | `false` | Enable auto-scaling |
102+
| `create_cluster` | `true` | Create new cluster (set `false` to use existing) |
103+
| `storage_class_name` | `"standard"` | K8s StorageClass for PVC (generic K8s only) |
104+
| `ingress_class_name` | `"nginx"` | Ingress controller class (generic K8s only) |
105+
| `ingress_annotations` | `{}` | Ingress annotations (generic K8s only) |
106+
107+
## Outputs
108+
109+
| Output | Description |
110+
|--------|-------------|
111+
| `service_url` | URL to access Bifrost |
112+
| `health_check_url` | Health endpoint URL |

terraform/examples/aws-ecs/.terraform.lock.hcl

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Bifrost on AWS ECS
2+
3+
Deploys Bifrost as an ECS Fargate service with optional ALB and autoscaling.
4+
5+
## Prerequisites
6+
7+
- AWS account with appropriate permissions
8+
- AWS CLI configured (`aws configure`)
9+
- Terraform >= 1.0
10+
11+
## Usage
12+
13+
```bash
14+
# Copy and edit the example variables file
15+
cp terraform.tfvars.example terraform.tfvars
16+
17+
# Deploy
18+
terraform init
19+
terraform plan
20+
terraform apply
21+
```
22+
23+
## Configuration
24+
25+
Two approaches can be combined:
26+
27+
1. **File-based** -- Set `config_json_file` to point to an existing `config.json`.
28+
2. **Variable-based** -- Set individual variables (`config_store`, `logs_store`, `providers_config`). These override matching keys from the file.
29+
30+
See `terraform.tfvars.example` for examples of both.
31+
32+
## Cleanup
33+
34+
```bash
35+
terraform destroy
36+
```

terraform/examples/aws-ecs/main.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
required_providers {
4+
aws = {
5+
source = "hashicorp/aws"
6+
version = "~> 5.0"
7+
}
8+
}
9+
}
10+
11+
provider "aws" {
12+
region = var.region
13+
}
14+
15+
module "bifrost" {
16+
source = "../../modules/bifrost"
17+
cloud_provider = "aws"
18+
service = "ecs"
19+
region = var.region
20+
image_tag = var.image_tag
21+
name_prefix = var.name_prefix
22+
23+
# Config: use a file as base, override with variables
24+
config_json_file = var.config_json_file
25+
26+
# Override specific config sections
27+
config_store = var.config_store
28+
logs_store = var.logs_store
29+
providers_config = var.providers_config
30+
31+
# Compute
32+
desired_count = var.desired_count
33+
cpu = var.cpu
34+
memory = var.memory
35+
create_load_balancer = var.create_load_balancer
36+
37+
# Autoscaling
38+
enable_autoscaling = var.enable_autoscaling
39+
min_capacity = var.min_capacity
40+
max_capacity = var.max_capacity
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "service_url" {
2+
description = "URL to access the Bifrost service."
3+
value = module.bifrost.service_url
4+
}
5+
6+
output "health_check_url" {
7+
description = "URL to the Bifrost health check endpoint."
8+
value = module.bifrost.health_check_url
9+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# =============================================================================
2+
# AWS ECS Example — terraform.tfvars
3+
# WARNING: Do NOT commit this file with real secrets (API keys, passwords).
4+
# Use environment variables, a secrets manager, or .gitignore this file.
5+
# =============================================================================
6+
7+
region = "us-east-1"
8+
image_tag = "latest"
9+
name_prefix = "bifrost"
10+
11+
# -----------------------------------------------------------------------------
12+
# Config approach 1: File-based
13+
# Point to an existing config.json. Variable overrides below will merge on top.
14+
# -----------------------------------------------------------------------------
15+
# config_json_file = "./config.json"
16+
17+
# -----------------------------------------------------------------------------
18+
# Config approach 2: Variable-based
19+
# Define config sections directly. These override matching keys from the file.
20+
# -----------------------------------------------------------------------------
21+
config_store = {
22+
enabled = true
23+
type = "sqlite"
24+
config = {
25+
path = "/app/data/bifrost.db"
26+
}
27+
}
28+
29+
logs_store = {
30+
enabled = true
31+
type = "sqlite"
32+
config = {
33+
path = "/app/data/bifrost-logs.db"
34+
}
35+
}
36+
37+
providers_config = {
38+
openai = {
39+
api_key = "sk-..."
40+
}
41+
anthropic = {
42+
api_key = "sk-ant-..."
43+
}
44+
}
45+
46+
# -----------------------------------------------------------------------------
47+
# Compute
48+
# -----------------------------------------------------------------------------
49+
desired_count = 2
50+
cpu = 512
51+
memory = 1024
52+
create_load_balancer = true
53+
54+
# -----------------------------------------------------------------------------
55+
# Autoscaling
56+
# -----------------------------------------------------------------------------
57+
# NOTE: If you are using OSS version - running multiple nodes has an effect on
58+
# functionality of the system. Please read
59+
# https://docs.getbifrost.ai/deployment-guides/how-to/multinode
60+
enable_autoscaling = true
61+
min_capacity = 1
62+
max_capacity = 5

0 commit comments

Comments
 (0)