CoursesPulumiIntermediate

Stack references & multi-project

Wire networking to app stacks.

Intermediate10 min · lesson 8 of 12

Large infrastructure is split across stacks — a networking stack, a data stack, an app stack — so blast radius and ownership stay small. A StackReference lets one stack read another’s outputs: the app stack reads the VPC ID and subnet IDs the networking stack exported, without duplicating them or hard-coding IDs. It is the typed, first-class way to wire stacks together.

WIRING STACKS TOGETHER
1Networking stack
export vpcId, privateSubnetIds
2new StackReference
app stack points at 'acme/networking/prod'
3getOutput("vpcId")
read another stack's outputs by name
4Use in app resources
LoadBalancer subnets = read subnet IDs
A StackReference only reads outputs, so the app stack cannot modify the producer.
networking/index.ts
// producer: export what other stacks may consume
export const vpcId = vpc.id;
export const privateSubnetIds = privateSubnets.map(s => s.id);
app/index.ts
// consumer: read another stack’s outputs by name
const net = new pulumi.StackReference("acme/networking/prod");
const vpcId = net.getOutput("vpcId");
const subnets = net.getOutput("privateSubnetIds");
new aws.lb.LoadBalancer("app-lb", { subnets: subnets as pulumi.Output<string[]> });

Boundaries and ownership

Splitting by stack maps naturally to team ownership and change cadence: the network team owns the networking stack and its exported contract, app teams consume it. Because a StackReference only reads outputs, the consuming stack cannot accidentally modify the producer — the coupling is a read-only, versioned interface, which is exactly what you want between teams.

Exports are a public contract
Once other stacks consume an output via StackReference, renaming or removing it breaks them — treat exported names like a published API. Export deliberately and keep the set stable; if you must change one, add the new output, migrate consumers, then remove the old, rather than renaming in place and breaking every downstream stack at once.