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

salmon-account-74572

09/23/2020, 10:31 PM
I have a question about StackReferences and type conversions in Go. I have an array of AWS subnet IDs that I am exporting (via
ctx.Export("subnetIds", pulumi.StringArray("subnets"))
in one stack. In another stack, I'd like to use a StackReference to pull that data out, but I'd like for it to just be a plain, ordinary array of strings so that I can iterate over it. Is there any way to do that?
l

lemon-agent-27707

09/23/2020, 11:13 PM
What are you trying to do with them? Apply is always an option. Also, Automation API allows you to access stack references synchronously.
s

salmon-account-74572

09/23/2020, 11:32 PM
Hey Evan! The code I got from you a while back (which involves the use of
ApplyStringArray
) still generates an array of type
OutputArray
, which can't be iterated over. The ultimate end goal is to use these values either in some
kustomize
Transformations or to write them into a YAML file.
c

clever-byte-21551

09/24/2020, 5:48 AM
@salmon-account-74572 if you will use the automation API you could access the outputs of one stack and transform them to strings / array whatever:
Copy code
outputs, _ := stack.Outputs(ctx)
val, ok := outputs["someExportVar"]
if !ok {
	return nil, errors.New("previous stack didn't output 'someExportVar' value")
}
v := val.Value.(string)
4 Views