https://pulumi.com logo
b

big-nail-28315

09/05/2019, 2:21 PM
Is there any way to retrieve the subnet id’s of a VPC to pass in to another function as a string? (before pulumi up is finished executing)
f

future-barista-68134

09/05/2019, 2:27 PM
You can get subnet ids using: https://www.pulumi.com/docs/reference/pkg/nodejs/pulumi/aws/ec2/#getSubnetIds and pass the result into other resources
b

big-nail-28315

09/05/2019, 3:08 PM
Thanks Dan
I guess I have a larger issue. I’m creating a VPC, then passing it to a function to create Elastic Beanstalk environments in that VPC. In order to use the code in that example, I need the VPC id which is an output parameter and I have the same issue as the output parameter with the subnet id’s. Sounds like VPCs and other resources might need to be setup separately???
f

future-barista-68134

09/05/2019, 4:30 PM
can you share a code sample of what you're trying to do? (even if it's not working)
b

big-nail-28315

09/05/2019, 4:45 PM
So on line 20, I need to get the vpc.id as a string, not an Output<string>…exact same issue as vpc.privateSubnetIds being an Ouput<string>[]
I’m still a little confused based on the documentation how to pass an ID of a VPC into another resource when all I get from the VPC class is an Output<string> that cannot be retrieved until the code execution is complete. How does one pass resource ID’s to other resources when a string is expected?
b

big-nail-28315

09/05/2019, 8:12 PM
Thanks @cool-egg-852. I’ve seen this and I’m still struggling to understand the docs here. I see that you can modify a local copy of an Output<string>, but what if you have resources that do not take an actual resource, they just take the ID? In my particular case, I am creating a VPC, then using that VPC in an EB Environment. EB expects subnets in a string[], not Output<string>[]. I went down the path of using aws.ec2.getSubnetIds() per
I went down the path of using aws.ec2.getSubnetIds() per @future-barista-68134, but I got the same issue where I needed to pass a string instead of an Output<string>.
I apologize guys…I feel like I’m missing something obvious
c

cool-egg-852

09/05/2019, 8:18 PM
I struggle with it too sometimes. If you can post the code you have, it would be a little easier to assist.
b

big-nail-28315

09/05/2019, 8:19 PM
I posted it in this Thread above, but I will condense that to just one particular situation…one moment
On line 20, the API is expecting a string, but because I created the VPC in the block above, the VPC ID is an Output<string>
c

cool-egg-852

09/05/2019, 8:20 PM
I’m not sure you want
vpc.id
anyways. I think
id
is the internal pulumi ID. I don’t use AWS for this, but in GCP we needed
vpc.selfLink
. You may need
vpc.name
or something instead.
And if you need to convert it to a string, you can do it via
Copy code
`${vpc.id}`
for example
b

big-nail-28315

09/05/2019, 8:22 PM
ah
thank you!
ugh…here’s what I’m getting…
Calling [toString] on an [Output<T>] is not supported. To get the value of an Output<T> as an Output<string> consider either: 1: o.apply(v =>
prefix${v}suffix
) 2: pulumi.interpolate
prefix${v}suffix
See https://pulumi.io/help/outputs for more details. This function may throw in a future version of @pulumi/pulumi.,Calling [toString] on an [Output<T>] is not supported.
this is a different error message than I got before
I’m using import { Vpc } from “@pulumi/awsx/ec2”;
I suspect the handling of Output parameters is different in awsx vs aws
c

cool-egg-852

09/05/2019, 8:44 PM
You can do
Copy code
pulumi.interpolate`${vpc.id}`
That may work.
Honestly, I end up doing trial and error a lot of times on this.
b

big-nail-28315

09/05/2019, 8:52 PM
Got it. Thanks for your help. I’ll give it a shot
console.log(pulumi.interpolate`${vpc.id}`);
after doing that just to see
I get the same error:
actually, scratch that
it’s not an error…
OutputImpl { __pulumiOutput: true, isKnown: Promise { <pending> }, isSecret: Promise { <pending> }, resources: [Function], promise: [Function], toString: [Function], toJSON: [Function], apply: [Function], get: [Function] }
that is the response I’m getting