fix(selfhost): cloud-sql-setup accepts Terraform outputs as documented

Merged
KH
9d ago
+42-2

Why

Found while dry-running the documented GKE native install of agent-relay-2026.11.1 (terraform/examples/gcp → scripts/selfhost/cloud-sql-setup.sh pre → Helm → post) in a fresh namespace.

  1. Admin secret 404. The header documents CLOUD_SQL_ADMIN_SECRET_ID as terraform output postgres.admin_password_secret_id. That output is a full projects/<p>/secrets/<id> resource name, and gcloud secrets versions access --project <p> --secret <full name> then returns HTTP 404 (the path is doubled).
  2. CA pin mismatch → PostgresTlsConfigError. ensure_ca writes the bundle with jq -er '.[].cert', which adds one more trailing newline than Terraform's server_ca_cert. The ConfigMap's sha256 (0be12e… in the dry run) therefore differed from the caSha256 pins Terraform puts in chart_values (a6061f…), and the read API, ingest edge and search indexer (plus the indexer bootstrap Job) crash-looped with PostgresTlsConfigError: PostgreSQL TLS configuration is invalid.

What

  • admin_password() accepts either a secret id or projects/<p>/secrets/<id>.
  • ensure_ca normalizes the bundle to exactly one trailing newline (Terraform's bytes), and an optional CLOUD_SQL_CA_SHA256 (the caSha256 from chart_values) makes pre stop before any database change if the bundle differs.
  • Three new offline tests in scripts/selfhost/tests/cloud-sql-setup-test.sh. They fail on the current script (not ok - CA bundle bytes differ from Terraform's server_ca_cert) and pass with the change.

Verification

  • bash scripts/selfhost/tests/cloud-sql-setup-test.sh: 7/7 ok.
  • shellcheck -S warning: clean.
  • Live, on the GKE dry run: rerunning pre with this script, the full Terraform secret path and CLOUD_SQL_CA_SHA256 from chart_values rewrote cloud-sql-ca to a6061f…. After restarting, the read API, ingest edge and search indexer became Ready, the indexer bootstrap Job completed, and verify-agent-relay.sh --require-native-history passed 18/18.

No chart, Terraform or image change. Existing installs: the next pre rewrites cloud-sql-ca to Terraform's bytes, which is what their chart pins already expect.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Fixes two failures in cloud-sql-setup.sh when used with the documented GKE install path, which left the read API, ingest edge, and search indexer crash-looping with PostgresTlsConfigError.

  • admin_password() now accepts Terraform's full projects/<project>/secrets/<id> resource name for CLOUD_SQL_ADMIN_SECRET_ID, which previously caused gcloud to return 404.
  • The CA bundle is normalized to exactly one trailing newline so its sha256 matches the caSha256 pins in Terraform's chart_values; an optional CLOUD_SQL_CA_SHA256 check makes pre stop before any database change on mismatch.

Three new offline tests cover both fixes and fail on the previous script. No chart, Terraform, or image changes; existing installs converge on the next pre run.