Skip to content

Type-safe cross-stack references that allow you to access outputs from other Pulumi stacks with full TypeScript support. Essential for multi-stack architectures where stateful infrastructure is separated from application stacks.

import * as pulumi from "@pulumi/pulumi";
import * as saws from "@stackattack/aws";
function env() {
const ctx = saws.context();
const certificate = saws.certificate(ctx, {
domain: "mydomain.dev",
wildcard: true
});
return { certificate };
}
function app() {
const ctx = saws.context();
const config = new pulumi.Config();
const envStack = saws.stackRef(config.require('env-stack'), env);
const certificate = envStack.require('certificate');
const bucket = saws.bucket(ctx, {
paths: ["./dist"]
});
const site = saws.staticSite(ctx, {
domain: "docs.mydomain.dev",
certificate,
bucket,
adapter: saws.astroAdapter()
});
return { url: site.url };
}
export default () => saws.select({ env, app });

Reference stacks using Pulumi config to specify stack names:

Terminal window
# Configure the env stack reference
pulumi config set stack-type app -s my-app-stack
pulumi config set env-stack my-env-stack -s my-app-stack
# Deploy with type-safe access to env stack outputs
pulumi up

The function parameter serves as a type template - it defines the shape of the referenced stack’s outputs without being executed. This enables full TypeScript IntelliSense and type checking for cross-stack references. See the Structuring Stacks guide for comprehensive multi-stack patterns.

Creates a reference to another Pulumi stack’s outputs.

function stackRef(stack: string, func: (args: never[]) => Output): StackRef<Output>
  • stack (string) - The stack reference string
  • func ((args: never[]) => Output) - Function that defines the output type structure
  • (StackRef<Output>) - Creates a reference to another Pulumi stack’s outputs.

Interface for referencing outputs from another Pulumi stack.

type StackRef = { get: (key: K) => AsOutput<T[K] | undefined>; require: (key: K) => AsOutput<T[K]> }