170 lines
3.9 KiB
HCL
170 lines
3.9 KiB
HCL
provider "google" {
|
|
project = var.project_id
|
|
region = var.region
|
|
zone = var.zone
|
|
}
|
|
|
|
# Get current project information
|
|
data "google_project" "current" {
|
|
project_id = var.project_id
|
|
}
|
|
|
|
# Enable required APIs
|
|
resource "google_project_service" "services" {
|
|
for_each = toset([
|
|
"cloudresourcemanager.googleapis.com",
|
|
"containerregistry.googleapis.com",
|
|
"run.googleapis.com",
|
|
"firestore.googleapis.com",
|
|
"storage.googleapis.com",
|
|
"compute.googleapis.com",
|
|
"cloudfunctions.googleapis.com",
|
|
"cloudbuild.googleapis.com",
|
|
"eventarc.googleapis.com",
|
|
"pubsub.googleapis.com",
|
|
"aiplatform.googleapis.com"
|
|
])
|
|
|
|
project = var.project_id
|
|
service = each.key
|
|
|
|
disable_on_destroy = false
|
|
}
|
|
|
|
# Cloud Storage bucket
|
|
resource "google_storage_bucket" "app_bucket" {
|
|
name = var.storage_bucket_name
|
|
location = var.region
|
|
uniform_bucket_level_access = true
|
|
|
|
depends_on = [google_project_service.services]
|
|
}
|
|
|
|
# Firestore Database
|
|
resource "google_firestore_database" "database" {
|
|
name = var.firestore_db_name
|
|
location_id = var.region
|
|
type = "FIRESTORE_NATIVE"
|
|
|
|
depends_on = [google_project_service.services]
|
|
}
|
|
|
|
# Container Registry - no explicit resource needed, just enable the API
|
|
# You'll push images to gcr.io/${var.project_id}/sereact-api
|
|
|
|
# Cloud Run service
|
|
resource "google_cloud_run_service" "sereact" {
|
|
name = "sereact"
|
|
location = var.region
|
|
|
|
metadata {
|
|
annotations = {
|
|
"run.googleapis.com/ingress" = "all"
|
|
}
|
|
}
|
|
|
|
template {
|
|
metadata {
|
|
annotations = {
|
|
"autoscaling.knative.dev/maxScale" = "10"
|
|
# Force Cloud Run to always pull the latest image
|
|
"run.googleapis.com/execution-environment" = "gen2"
|
|
# Disable CPU throttling for better performance
|
|
"run.googleapis.com/cpu-throttling" = "false"
|
|
}
|
|
}
|
|
|
|
spec {
|
|
containers {
|
|
# Use our optimized image
|
|
image = "gcr.io/${var.project_id}/sereact-api:${var.image_tag}"
|
|
|
|
ports {
|
|
container_port = 8000
|
|
}
|
|
|
|
resources {
|
|
limits = {
|
|
cpu = "1"
|
|
memory = "1Gi"
|
|
}
|
|
}
|
|
|
|
env {
|
|
name = "FIRESTORE_PROJECT_ID"
|
|
value = var.project_id
|
|
}
|
|
|
|
env {
|
|
name = "FIRESTORE_DATABASE_NAME"
|
|
value = var.firestore_db_name
|
|
}
|
|
|
|
env {
|
|
name = "GCS_BUCKET_NAME"
|
|
value = var.storage_bucket_name
|
|
}
|
|
|
|
env {
|
|
name = "VECTOR_DB_ENVIRONMENT"
|
|
value = var.vector_db_environment
|
|
}
|
|
|
|
env {
|
|
name = "VECTOR_DB_INDEX_NAME"
|
|
value = var.vector_db_index_name
|
|
}
|
|
|
|
env {
|
|
name = "QDRANT_HOST"
|
|
value = google_compute_instance.vector_db_vm.network_interface[0].access_config[0].nat_ip
|
|
}
|
|
|
|
env {
|
|
name = "QDRANT_PORT"
|
|
value = "6333"
|
|
}
|
|
|
|
env {
|
|
name = "QDRANT_API_KEY"
|
|
value = var.qdrant_api_key
|
|
}
|
|
|
|
env {
|
|
name = "QDRANT_HTTPS"
|
|
value = "false"
|
|
}
|
|
|
|
env {
|
|
name = "QDRANT_PREFER_GRPC"
|
|
value = "false"
|
|
}
|
|
|
|
env {
|
|
name = "LOG_LEVEL"
|
|
value = "INFO"
|
|
}
|
|
|
|
env {
|
|
name = "API_KEY_SECRET"
|
|
value = "super-secret-key-for-development-only"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
traffic {
|
|
percent = 100
|
|
latest_revision = true
|
|
}
|
|
|
|
depends_on = [google_project_service.services, google_compute_instance.vector_db_vm]
|
|
}
|
|
|
|
# Make the Cloud Run service publicly accessible
|
|
resource "google_cloud_run_service_iam_member" "public_access" {
|
|
service = google_cloud_run_service.sereact.name
|
|
location = google_cloud_run_service.sereact.location
|
|
role = "roles/run.invoker"
|
|
member = "allUsers"
|
|
} |