https://pulumi.com logo
#general
Title
# general
r

rhythmic-accountant-71070

12/04/2023, 6:41 PM
Hi. Is it the responsibility of my program to return valid exports for every run of pulumi?
Copy code
package main

import (
        "github.com/pulumi/pulumi/sdk/v3/go/pulumi"
        "errors"
        "os"
)

func main() {
        pulumi.Run(func(ctx *pulumi.Context) error {
                if os.Getenv("FAIL") == "true" {
                        return errors.New("ERROR")
                }
                ctx.Export("output", pulumi.String("string"))
                return nil
        })
}
After the first run, I the output is set.
Copy code
Type                 Name                         Status     
     pulumi:pulumi:Stack  pulumi-output-dissapear-dev             

Outputs:
  + output: "string"
With FAIL=true env var my output is disappeared.
Copy code
Type                 Name                         Status         Info
     pulumi:pulumi:Stack  pulumi-output-dissapear-dev  **failed**     1 error

Diagnostics:
  pulumi:pulumi:Stack (pulumi-output-dissapear-dev):
    error: an unhandled error occurred: program failed:
    1 error occurred:
    	* ERROR

Outputs:
  - output: "string"
Is it desired behavior?
Copy code
[spigell@dragonfish pulumi-output-dissapear ]$ pulumi stack output 
Current stack outputs (0):
    No output values currently in this stack
b

billions-river-87988

12/06/2023, 8:57 PM
I would say this is expected- state in pulumi is the result of the procedural run of the program from start to finish. If something is added or removed (eg, the line of code creating a resource or output is removed or otherwise never run), the new state would not have that item, and in this case the diff would show the output being removed.