pulumi/pulumi · error
failed to convert stack output %T to object
Error message
failed to convert stack output %T to object
What it means
StackReference.GetOutput fetches the referenced stack's outputs and expects the 'outputs' value to be an object. If it is not an object (e.g. the raw outputs state is unknown or a non-object shape), the Apply returns this error and the resulting AnyOutput becomes an error output.
Source
Thrown at sdk/go/pulumi/stack_reference.go:45
// Name is in the form "Org/Program/Stack"
Name StringOutput `pulumi:"name"`
// Outputs resolves with exports from the named stack
Outputs MapOutput `pulumi:"outputs"`
// ctx is a reference to the context used to create the stack reference. It must be
// valid and non-nil to call `GetOutput`.
ctx *Context
}
// GetOutput returns a stack output keyed by the given name as an AnyOutput
// If the given name is not present in the StackReference, Output<nil> is returned.
func (s *StackReference) GetOutput(name StringInput) AnyOutput {
return All(name, s.rawOutputs).
ApplyT(func(args []any) (any, error) {
n, stack := args[0].(string), args[1].(resource.PropertyMap)
if !stack["outputs"].IsObject() {
return Any(nil), fmt.Errorf("failed to convert stack output %T to object", stack)
}
outs := stack["outputs"].ObjectValue()
v, ok := outs[resource.PropertyKey(n)]
if !ok {
if s.ctx.DryRun() {
// It is a dry run, so it is safe to return an unknown output.
return UnsafeUnknownOutput([]Resource{s}), nil
}
// We don't return an error to remain consistent with other SDKs regarding missing keys.
return nil, nil
}
ret, secret, _ := unmarshalPropertyValue(s.ctx, v)
if secret {
ret = ToSecret(ret)
}View on GitHub (pinned to 793f7b2e16)
Solutions
- Ensure the referenced stack exists and has been successfully deployed with outputs (pulumi stack output in that project).
- Check the stack reference name format (org/project/stack) for typos.
- Handle the error output downstream (ApplyT error) or guard with a known-value check before use.
- Refresh the referenced stack (pulumi refresh) if its state is stale.
Example fix
// before
sr := pulumi.NewStackReference(ctx, "org/proj/stk", nil)
out := sr.GetOutput(pulumi.String("missingKey"))
// after — verify the referenced stack and key first
// $ pulumi stack output missingKey --stack org/proj/stk (run in referenced project)
// then in the program handle the Apply error:
out.ApplyT(func(v interface{}) (interface{}, error) {
// handle unknown/missing gracefully
return v, nil
}) Defensive patterns
Strategy: validation
Validate before calling
// verify referenced stack and outputs before referencing // $ pulumi stack select org/proj/stk && pulumi stack output // in program: verify key presence via export // pulumi stack export --stack org/proj/stk | jq '..outputs'
Try / catch
sr.GetOutput(pulumi.String("key")).ApplyT(func(v interface{}) (interface{}, error) {
if v == nil {
return nil, fmt.Errorf("output key not found")
}
return v, nil
}) Prevention
- Confirm the referenced stack is deployed and has outputs before referencing
- Use correct stack reference format org/project/stack
- Run pulumi stack export to inspect actual output shape
- Expect unknown outputs during preview and handle nil in ApplyT
When it happens
Trigger: Calling StackReference.GetOutput(name) when the resolved rawOutputs property map's "outputs" entry is not a resource.PropertyValue holding an object — typically when outputs are unavailable/unknown during preview or the referenced stack state is malformed.
Common situations: Previewing (dry run) before the referenced stack's outputs are known; referencing a stack that has never been deployed or has no outputs; corrupt stack state.
Related errors
- stack reference output %q does not exist on stack %q
- getting stack reference output %q on stack %q, failed to con
- getting stack reference output %q on stack %q, failed to con
- getting stack reference output %q on stack %q, failed to con
- Cannot call 'getOutputValue' if the referenced stack output
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/85e1f06dbdd95dd8.
Report an issue: GitHub.