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

brave-lizard-56518

04/24/2022, 3:49 PM
I used the (*pulumi.Context).Export() function to export a pulumi.StringArray of subnet IDs, and a few other metadata. At the bottom is an excerpt of my stack output as stored in my state file, which I’m already able to load using pulumi.NewStackReference(), and read a plain string like the “eip-1”, for example. My code for reading the eip-1 (which works) is:
Copy code
nsr, _ := pulumi.NewStackReference(ctx, vpcStackRef, nil)
eip1 := nsr.GetStringOutput(pulumi.String("eip-1"))
Now what I can’t figure out is how to read “data-subnets” into a slice. Can anybody help?
Copy code
"resources": [
                {
                    "urn": "urn:pulumi:dev::vpc::pulumi:pulumi:Stack::dev",
                    "custom": false,
                    "type": "pulumi:pulumi:Stack",
                    "outputs": {
                        "data-subnets": [
                            "subnet-abcddaed530b25d91",
                            "subnet-abcdcfacd0c04fe74",
                            "subnet-abcd693e4a8ae4ca8"
                        ],
                        "eip-1": "eipalloc-abcdcfa5cf063576d"
e

echoing-dinner-19531

04/24/2022, 9:22 PM
You can use
GetOutput("data-subnets")
which will return any
AnyOutput
. If you
ApplyT
that you can get the
interface{}
value inside and I think it should be castable to a string slice.
🙌 1
b

brave-lizard-56518

04/24/2022, 10:08 PM
@echoing-dinner-19531, I was looking for a canned function, but there appears to be none. Anyway, I’ve tried it with the ApplyT, and got it to work. Thanks!.
5 Views