https://pulumi.com logo
Title
h

high-holiday-63390

11/07/2021, 10:28 PM
const privateSubnets = await vpc.getSubnets('private')
    const result = privateSubnets.map(net => net.id).join(",")
l

little-cartoon-10569

11/07/2021, 10:42 PM
You cannot get a string from an output. An output isn't a value until "later".
However there is always a way to use the strings that become available later. What is your aim? Can you share a larger chunk of code?
h

high-holiday-63390

11/07/2021, 10:43 PM
I need to pass a comma-separated list of subnets as a string argument to another resource
I also tried this but got null values
{
            name: "Subnets",
            namespace: "aws:ec2:vpc",
            value: pulumi.interpolate(`${privateSubnets[0].id},${privateSubnets[1].id}`)
        },
This is being assigned to an object
Which gets passed to
new aws.elasticbeanstalk.Environment
l

little-cartoon-10569

11/07/2021, 10:45 PM
If the other resource accepts an Input, then it will work. If it accepts only a string, then you'll have to create the other resource inside an
apply()
.
Iโ€™m not sure how to tell if the other resource accepts an input. But, this does work by just lifting one value like
privateSubnets[0].id
l

little-cartoon-10569

11/07/2021, 10:50 PM
I've checked the source. That's a bug, there's a lot of values in there that should accept inputs.
h

high-holiday-63390

11/07/2021, 10:50 PM
the abolve code does not throw an error, but I donโ€™t see the values in the diff
l

little-cartoon-10569

11/07/2021, 10:51 PM
In the short term, you need to do a lot of that work inside an
apply()
The code you have right now will have an error message as the value, that message about "you need to use apply or interpolate".
h

high-holiday-63390

11/07/2021, 10:52 PM
oddly this is what the diff looks like
name      : "Subnets"
           namespace : "aws:ec2:vpc"
           value     : "."
OK - where would this apply need to go exactly?
l

little-cartoon-10569

11/07/2021, 10:53 PM
The block of code from line 17 to 154 would need to be inside the apply()
h

high-holiday-63390

11/07/2021, 10:53 PM
What would the apply look like though?
l

little-cartoon-10569

11/07/2021, 10:54 PM
And you'll need to use something like this:
pulumi.all([privateSubnets[0].id, privateSubnets[1].id).apply(([id0, id1]) => { your code });
h

high-holiday-63390

11/07/2021, 10:55 PM
ah, ok
l

little-cartoon-10569

11/07/2021, 10:55 PM
Then id0 and id1 would be the correct string value you need to use. You can remove "interpolate" from the contained code, you have real strings at that point.
h

high-holiday-63390

11/07/2021, 10:55 PM
so is there an actual bug here?
l

little-cartoon-10569

11/07/2021, 10:55 PM
Can you also raise an issue about this? There's probably no reason to have the code this way: it should be possible to use
privateSubnets[0].id
directly as a value.
h

high-holiday-63390

11/07/2021, 10:56 PM
It does actually work as a value
l

little-cartoon-10569

11/07/2021, 10:56 PM
Yes, but it's the wrong value ๐Ÿ™‚
h

high-holiday-63390

11/07/2021, 10:57 PM
Is the bug that it works on its own, but not with interpolation?
Also, if it were working, would it show up in the diff as something other than
.
?
l

little-cartoon-10569

11/07/2021, 10:57 PM
No. It's not properly working even without interpolate. You're passing in an output, which typescript converts to a string. But that string is an error message, not the correct value.
Can you look at the environment settings in the AWS console? You'll see the error message.
h

high-holiday-63390

11/07/2021, 10:58 PM
Invalid option value: '.'
l

little-cartoon-10569

11/07/2021, 10:59 PM
Heh, I've just re-checked your code and I found another bug ๐Ÿ™‚
You have this:
pulumi.interpolate(`${privateSubnets[0].id},${privateSubnets[1].id}`)
It would need to be this:
pulumi.interpolate`${privateSubnets[0].id},${privateSubnets[1].id}`
h

high-holiday-63390

11/07/2021, 11:02 PM
ah, nice
how does that get interpreted exactly?
Appears to be working ๐Ÿ‘
๐Ÿ‘ 1
l

little-cartoon-10569

11/07/2021, 11:18 PM
Sorry, was on a call. Essentially,
pulumi.interpolate
is an operator, not a function. Hence the weird syntax.