``` const privateSubnets = await vpc.getSubnets...
# general
h
Copy code
const privateSubnets = await vpc.getSubnets('private')
    const result = privateSubnets.map(net => net.id).join(",")
l
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
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
Copy code
{
            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
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
I've checked the source. That's a bug, there's a lot of values in there that should accept inputs.
h
the abolve code does not throw an error, but I donโ€™t see the values in the diff
l
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
oddly this is what the diff looks like
Copy code
name      : "Subnets"
           namespace : "aws:ec2:vpc"
           value     : "."
OK - where would this apply need to go exactly?
l
The block of code from line 17 to 154 would need to be inside the apply()
h
What would the apply look like though?
l
And you'll need to use something like this:
Copy code
pulumi.all([privateSubnets[0].id, privateSubnets[1].id).apply(([id0, id1]) => { your code });
h
ah, ok
l
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
so is there an actual bug here?
l
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
It does actually work as a value
l
Yes, but it's the wrong value ๐Ÿ™‚
h
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
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
Invalid option value: '.'
l
Heh, I've just re-checked your code and I found another bug ๐Ÿ™‚
You have this:
Copy code
pulumi.interpolate(`${privateSubnets[0].id},${privateSubnets[1].id}`)
It would need to be this:
Copy code
pulumi.interpolate`${privateSubnets[0].id},${privateSubnets[1].id}`
h
ah, nice
how does that get interpreted exactly?
Appears to be working ๐Ÿ‘
๐Ÿ‘ 1
l
Sorry, was on a call. Essentially,
pulumi.interpolate
is an operator, not a function. Hence the weird syntax.