Skip to content

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}.json
gs://{bucket}/{prefix}{stack}/{stage}/__stack_output__.json
gs://{bucket}/{prefix}{stack}/{stage}/__lease__.json

Concurrent 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 {};
}),
);

In CI (CI=true) a missing bucket fails the run instead of being created. Create it once ahead of time:

Terminal window
alchemy state bootstrap --backend gcp --profile <your-ci-profile>