GCP.StateStore reference
Source:
packages/gcp/src/StateStore/State.ts
State store backed by a Google Cloud Storage bucket.
Stack state is persisted as JSON objects in a bucket in your project, laid out like the local state store’s file tree:
gs://{bucket}/{prefix}{stack}/{stage}/{fqn}.jsongs://{bucket}/{prefix}{stack}/{stage}/__stack_output__.jsongs://{bucket}/{prefix}{stack}/{stage}/__lease__.jsonConcurrent deploys of one stack and stage share an __lease__.json
object written with ifGenerationMatch preconditions. The second deploy
fails immediately instead of mixing rows.
The bucket is created on the first state operation if it does not
exist, with uniform bucket-level access, public access prevention, and
object versioning. Project Owners and Editors get
roles/storage.objectAdmin on it, since uniform access otherwise leaves
them unable to read objects. Nothing touches GCP credentials at layer
construction time.
state: Using the Cloud Storage State Store
Section titled “state: Using the Cloud Storage State Store”Pass GCP.state() as the state option of a Stack. By default the state
is stored in a bucket named alchemy-state-{project}.
Default bucket
import * as Alchemy from "alchemy";import * as GCP from "@alchemy.run/gcp";import * as Effect from "effect/Effect";
export default Alchemy.Stack( "MyApp", { providers: GCP.providers(), state: GCP.state() }, Effect.gen(function* () { return {}; }),);Named store with a key prefix
export default Alchemy.Stack( "MyApp", { providers: GCP.providers(), state: GCP.state({ name: "platform", prefix: "alchemy" }), }, Effect.gen(function* () { return {}; }),);state: Provisioning in CI
Section titled “state: Provisioning in CI”In CI (CI=true) a missing bucket fails the run instead of being
created. Create it once ahead of time:
alchemy state bootstrap --backend gcp --profile <your-ci-profile>