fix(selfhost): cloud-sql-setup accepts Terraform outputs as documented
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.
- Admin secret 404. The header documents
CLOUD_SQL_ADMIN_SECRET_IDasterraform output postgres.admin_password_secret_id. That output is a fullprojects/<p>/secrets/<id>resource name, andgcloud secrets versions access --project <p> --secret <full name>then returns HTTP 404 (the path is doubled). - CA pin mismatch →
PostgresTlsConfigError.ensure_cawrites the bundle withjq -er '.[].cert', which adds one more trailing newline than Terraform'sserver_ca_cert. The ConfigMap's sha256 (0be12e…in the dry run) therefore differed from thecaSha256pins Terraform puts inchart_values(a6061f…), and the read API, ingest edge and search indexer (plus the indexer bootstrap Job) crash-looped withPostgresTlsConfigError: PostgreSQL TLS configuration is invalid.
What
admin_password()accepts either a secret id orprojects/<p>/secrets/<id>.ensure_canormalizes the bundle to exactly one trailing newline (Terraform's bytes), and an optionalCLOUD_SQL_CA_SHA256(thecaSha256fromchart_values) makesprestop 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
prewith this script, the full Terraform secret path andCLOUD_SQL_CA_SHA256fromchart_valuesrewrotecloud-sql-catoa6061f…. After restarting, the read API, ingest edge and search indexer became Ready, the indexer bootstrap Job completed, andverify-agent-relay.sh --require-native-historypassed 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](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
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 fullprojects/<project>/secrets/<id>resource name forCLOUD_SQL_ADMIN_SECRET_ID, which previously causedgcloudto return 404.- The CA bundle is normalized to exactly one trailing newline so its sha256 matches the
caSha256pins in Terraform'schart_values; an optionalCLOUD_SQL_CA_SHA256check makesprestop 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.