Pulumi StackReference Outputs Empty — Complete Guide
In this tutorial, you'll learn about Pulumi StackReference Outputs Empty. We cover key concepts, practical examples, and best practices.
A Pulumi StackReference outputs are empty or the reference fails with a 403 error.
Wrong ❌
// Wrong: referencing stack outputs that are not exported
import * as pulumi from "@pulumi/pulumi";
const infra = new pulumi.StackReference("organization/infrastructure/prod");
const vpcId = infra.getOutput("vpcId"); // vpcId not exported from infra stack
const bucketName = infra.getOutput("bucketName"); // bucketName not exported
Wrong Output
Error: pulumi:pulumi:StackReference 'organization/infrastructure/prod'
output 'vpcId' not found in stack 'organization/infrastructure/prod'
Available outputs: []
Right ✅
// In the infrastructure stack, export the required values:
export const vpcId = vpc.id;
export const subnetIds = subnets.ids;
export const bucketName = bucket.bucketName;
// In the consuming stack:
import * as pulumi from "@pulumi/pulumi";
const infra = new pulumi.StackReference("organization/infrastructure/prod");
const vpcId = infra.requireOutput("vpcId");
const subnetIds = infra.requireOutput("subnetIds");
const bucketName = infra.getOutput("bucketName");
// Use the values
new aws.ec2.Instance("app-server", {
vpcId: vpcId,
subnetId: subnetIds.apply(ids => ids[0]),
// ...
});
Right Output
Stack 'organization/application/dev' created successfully
Outputs:
vpcId: "vpc-0a1b2c3d4e5f"
subnetIds: ["subnet-abc", "subnet-def"]
bucketName: "my-app-bucket"
Prevention
- Always export values in the source stack using export const in the Pulumi program.
- Use requireOutput for mandatory dependencies to fail fast with a clear error.
- Use getOutput for optional dependencies that may not exist.
- Use the stack reference name format: organization/project/stack.
- Ensure the stack reference target stack has been deployed before referencing it.
DodaTech applies similar defensive patterns across Doda Browser, DodaZIP, and Durga Antivirus Pro infrastructure for production reliability.
Common Mistakes with stack reference
- Misunderstanding that
Stringis[Char]with poor performance for large text operations - Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging
These mistakes appear frequently in real-world PULUMI code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
This quick fix is part of the DodaTech infrastructure engineering series. Learn more at DodaTech tutorials.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro