https://pulumi.com logo
#golang
Title
# golang
c

creamy-engine-1851

12/07/2020, 8:04 PM
I have a question about types. I have a
pulumi.StringArrayOutput
that I'm exporting through
ctx.Export
. When I'm importing this through
StackReference.GetOutput
in another stack I'm getting an
pulumi.AnyOutput
. How do I convert it? Should I use
.ApplyStringArray
in some way?
Copy code
AnyOutput.ApplyStringArray(func(value pulumi.StringArrayOutput) pulumi.StringArrayOutput {
   return value
})
Result in a panic with a stacktrace
l

lemon-agent-27707

12/07/2020, 8:37 PM
yes the conversion will be a little more involved:
Copy code
output.ApplyStringArray(func(v []interface{})([]string, error) {
var result []string
for _, s := range v {
result = append(result, v.(string)
}
return result, nil
})
May require a little tweaking. The signature might need to be
func(v interface{})
with an additional type assertion in there.
🙏 1
c

creamy-engine-1851

12/07/2020, 8:38 PM
Thanks a lot! I'm trying it out
This ended up working for me:
Copy code
.ApplyStringArray(func(v interface{}) ([]string, error) {
	v2 := v.([]interface{})
	var result []string
	for _, s := range v2 {
		result = append(result, s.(string))
	}
	return result, nil
})
I'm having most of my struggles with these custom pulumi types, once you learn how they're supposed to work it becomes easier to build the configurations, I think a lot of my struggles could've been solved if there were more practical examples. Some feedback for improving the docs.
l

lemon-agent-27707

12/07/2020, 11:58 PM
Agree, we hope to improve the docs in this area.
5 Views