@adrianhall/cloudflare-toolkit
@adrianhall/cloudflare-toolkit / lib/vite / readTerraformOutputs
Function: readTerraformOutputs()
readTerraformOutputs<
T>(options):T|undefined
Defined in: src/lib/vite/terraform-outputs.ts:88
Read and parse a Terraform outputs JSON file (produced by terraform output -json), projecting it onto a typed, caller-named shape via options.keys. Returns undefined on any failure — the file doesn't exist yet, its contents aren't valid JSON, or one of the mapped output names is missing or not a string — rather than throwing, so callers can use it as a soft-fail "is live infra available?" probe (typically to choose between real Terraform-backed values and hermetic local-dev placeholders in a cloudflare.config.ts defineWorker callback).
Only string-valued Terraform outputs are supported, matching the scalar-output convention documented in the cloudflare-terraform-best-practices skill.
Type Parameters
T
T extends Record<string, string>
Parameters
options
ReadTerraformOutputsOptions<T>
keys (required) mapping T's keys to Terraform output names, and an optional path (defaults to "infra/outputs.json" resolved against process.cwd()).
Returns
T | undefined
The projected outputs, or undefined if they could not be read.