Hi, I have the following aws vpc configuration: `...
# typescript
Hi, I have the following aws vpc configuration:
Copy code
export const vpc = new awsx.ec2.Vpc("vpc", {
   numberOfAvailabilityZones: 3,
I'm struggling to find a way to grab the private subnet so that I can use it to create an EC2 instance. This is what I came to thus far:
Copy code
const privateSubnets = pulumi.output(vpc.privateSubnets).apply(
    subnets => subnets.filter(x => x.subnet.availabilityZone == pulumi.output("us-east-1a"))

export const server = new aws.ec2.Instance("server", {
    instanceType: aws.ec2.C5InstanceLarge,
    vpcSecurityGroupIds: [ vpc.sgInternal.id ],
    subnetId: privateSubnets.apply(x => x[0].id),
    ami: "ami-;02507631a9f7bc956",
I'm getting the following error:
Copy code
$ pulumi up
Previewing update (xxx):

     Type                 Name                      Plan     Info
     pulumi:pulumi:Stack  xxx           1 error; 5 messages
  pulumi:pulumi:Stack (xxx):
    TypeError: Cannot read property 'id' of undefined
        at exports.server.aws.ec2.Instance.subnetId.privateSubnets.apply.x (ec2.ts:24:46)
        at OutputImpl.<anonymous> (node_modules/@pulumi/pulumi/output.js:104:47)
        at Generator.next (<anonymous>)
        at fulfilled (node_modules/@pulumi/pulumi/output.js:17:58)
This should work for you:
Copy code
const server = new aws.ec2.Instance("web-server", {
    // ...
    subnetId: vpc.privateSubnetsIds[0], // reference the subnet created by awsx
Will index 0 always be
I believe it will always be the first available zone found, but different accounts have different zones.
Not all accounts have an a to be more specific.
my issue here is that I have an EBS volume in AZ
that I need to attach to the instance. that's why I used a filter on the subnet collection.
I tried to simplify my example, but what I actually have is:
Copy code
subnets => subnets.filter(x => x.subnet.availabilityZone == ebs.availabilityZone)
OK, I worked around this by selecting
when configuring the EBS volume AZ
👍 1