hey everyone - I’ve been using crosswalk as a refe...
# typescript
c
hey everyone - I’ve been using crosswalk as a reference while I write my own components, and everything was going swimmingly until I started work on my VPC component (my order of operations was mess, was trying to create nats before public subnets, etc). it appears that the arch of the vpc component is much different than that of the others, specifically calling typeof VpcData on the top level component resource. I restructured my own component to match, and it obviously works now, but I still cant exactly explain if that typeof call has anything to do with it (I noticed some other issues with my original code going through yall’s), or why it may be necessary in this case. can someone help me understand a bit better what’s going on there/why it’s important in relation to the pulumi engine? thanks!
m
Sorry, I do not have a good answer on the architecture part, but I can say that I've run into similar confusion over this awsx component myself, and I'm interested in understanding more about this particularly component for my use case. I was attempting to get a subnet in a vpc by availability zone.
Copy code
const vpc = new awsx.vpc.fromExistingIds("shared-vpc", {
  privateSubnetIds,
  publicSubnetIds,
  vpcId,
});

const thisSubnetId = pulumi.output(
  vpc.vpc.publicSubnets
    .get()
    .then((subnets: awsx.ec2.Subnet[]) =>
      subnets.find((subnet: awsx.ec2.Subnet) => subnet.subnet.availabilityZone === pulumi.output("us-east-1a")),
    ),
);

console.log(thisSubnetId.apply(v => v));
c
I’d have to play around with this, but I can confidently tell you that your subnet IDs are in an array thats pushed onto in AZ order. so index 0 is always a, 1 is b, and so on. (I know that’s a horrible answer 🤣 )
hey @millions-furniture-75402 here’s what I came up with for an actual answer to your question. hope it helps!
Copy code
import * as awsx from "@pulumi/awsx";

const vpc = new awsx.ec2.Vpc("test-vpc", {});

const ue1aPubSub = vpc.publicSubnets.then((a) => {
  return a
    .filter((s) => s.subnet.availabilityZone.apply((az) => az === "us-east-1a"))
    .pop()?.id;
});

export const out = {
  vpcId: vpc.id,
  vpcPubSubIds: vpc.publicSubnetIds,
  vpcPrivSubIds: vpc.privateSubnetIds,
  vpcDataSubIds: vpc.isolatedSubnetIds,
  vpcPubSubCidrs: vpc.publicSubnets.then((a) =>
    a.map((s) => s.subnet.cidrBlock)
  ),
  vpcPrivSubCidrs: vpc.privateSubnets.then((a) =>
    a.map((s) => s.subnet.cidrBlock)
  ),
  vpcDataSubCidrs: vpc.isolatedSubnets.then((a) =>
    a.map((s) => s.subnet.cidrBlock)
  ),
  usEast1aPubSubnet: ue1aPubSub,
};
m
so index 0 is always a, 1 is b, and so on. (I know that’s a horrible answer 🤣 )
This is the horrible solution we've used so far, but our use cases have now required a more complex representation of the VPC. That looks great, I'll take a note and play around with it after I close out some other projects/tasks. It would be great to have something like this in the awsx package already.