Skip to content

Instantly share code, notes, and snippets.

Created February 27, 2021 15:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Writing a file in an apply
package main
import (
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
a := pulumi.String("a").ToStringOutput()
b := pulumi.String("b").ToStringOutput()
c := pulumi.String("c").ToStringOutput()
// we have an array of outputs
arr := pulumi.StringArray{a, b, c}
// we will run an apply on the array to get access to the underlying output values
out := arr.ToStringArrayOutput().ApplyT(func(ar []string) string {
res := strings.Join(ar, ",")
// in the apply we write out the values to a file
ioutil.WriteFile("output.txt", []byte(res), 0644)
return res
// finally, since this output isn't a part of the dependency graph
// we'll export it as a stack output to ensure that it runs
ctx.Export("out", out)
return nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment