From 534ddfdba2e608e6977ea3d18179e618babb8961 Mon Sep 17 00:00:00 2001 From: Yassin Kortam Date: Thu, 9 Jul 2026 21:29:41 +0300 Subject: [PATCH] fix(terraform): guard the backend against a partial billing config too The precondition only sat on the gateway, but the backend receives the billing endpoint as well, because it serves the named-server MCP transport and meters it. A targeted apply of just the backend task or service would therefore skip the guard entirely and provision a component holding a billing endpoint with no credentials to use it, which is the silent never-export failure the guard exists to prevent. Both templates now carry the same precondition on the backend resource. The condition and truth table are unchanged; ca_cert_pem stays optional. terraform fmt -check and terraform validate clean in both directories --- terraform/litellm/aws/ecs.tf | 12 ++++++++++++ terraform/litellm/gcp/cloudrun.tf | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/terraform/litellm/aws/ecs.tf b/terraform/litellm/aws/ecs.tf index 0fe5fe3762a..4df41c278e8 100644 --- a/terraform/litellm/aws/ecs.tf +++ b/terraform/litellm/aws/ecs.tf @@ -317,6 +317,18 @@ resource "aws_ecs_service" "gateway" { # ---------- Backend ---------- resource "aws_ecs_task_definition" "backend" { + # Same guard as the gateway: the backend meters too (it serves the named-server + # MCP transport), and a targeted apply of just this resource must not slip a + # billing endpoint through without the credentials to use it. + lifecycle { + precondition { + condition = var.billing_metrics_endpoint == "" || ( + var.billing_metrics_client_cert_pem != "" && var.billing_metrics_client_key_pem != "" + ) + error_message = "billing_metrics_client_cert_pem and billing_metrics_client_key_pem are both required when billing_metrics_endpoint is set." + } + } + family = "${local.name}-backend" network_mode = "awsvpc" requires_compatibilities = ["FARGATE"] diff --git a/terraform/litellm/gcp/cloudrun.tf b/terraform/litellm/gcp/cloudrun.tf index fa66d71f077..57533b71731 100644 --- a/terraform/litellm/gcp/cloudrun.tf +++ b/terraform/litellm/gcp/cloudrun.tf @@ -306,6 +306,18 @@ resource "google_cloud_run_v2_service" "gateway" { # ---------- Backend ---------- resource "google_cloud_run_v2_service" "backend" { + # Same guard as the gateway: the backend meters too (it serves the named-server + # MCP transport), and a targeted apply of just this resource must not slip a + # billing endpoint through without the credentials to use it. + lifecycle { + precondition { + condition = var.billing_metrics_endpoint == "" || ( + var.billing_metrics_client_cert_pem != "" && var.billing_metrics_client_key_pem != "" + ) + error_message = "billing_metrics_client_cert_pem and billing_metrics_client_key_pem are both required when billing_metrics_endpoint is set." + } + } + name = "${local.name}-backend" location = var.region ingress = "INGRESS_TRAFFIC_INTERNAL_LOAD_BALANCER"