examples
examples copied to clipboard
Add an Go stackref example
@EvanBoyle wrote this in slack, and I think it'd be useful to put here somewhere:
package main
import (
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
ref, err := pulumi.NewStackReference(ctx, "EvanBoyle/ref1/dev", nil)
if err != nil {
return err
}
strarr := ref.GetOutput(pulumi.String("ref")).ApplyStringArray(func(out interface{}) []string {
var res []string
if out != nil {
for _, v := range out.([]interface{}) {
res = append(res, v.(string))
}
}
return res
})
idx0 := strarr.ApplyString(func(a []string) string {
var res string
if len(a) > 0 {
res = a[0]
}
return res
})
ctx.Export("idx0", idx0)
return nil
})
}