https://pulumi.com logo
Title
c

clean-diamond-27934

08/19/2021, 9:20 PM
hey guys, I want to specify the subnet id in RouteTable Association obtained from subnet object array:
const subnet_public = []
 
for (let it = 1; it <= 2; it++) {
    subnet_public.push(new aws.ec2.Subnet(`${name}-public-${it}`, {
      vpcId: vpc.id,
      cidrBlock: `10.0.${2+it}.0/24`,
      availabilityZone: azs.then(azs => azs.names[`${it}`]),
      tags: {
        'Name': `${name}-public-${it}`,
        '<http://kubernetes.io/role/elb|kubernetes.io/role/elb>': '1',
        [`<http://kubernetes.io/cluster/pulumi-${environment}`|kubernetes.io/cluster/pulumi-${environment}`>]:  'shared',
        [`<http://kubernetes.io/cluster/pulumi-${environment}`|kubernetes.io/cluster/pulumi-${environment}`>]:  'shared',
      },
    }));
  }
....
  const publicRouteTableAssociation = new         aws.ec2.RouteTableAssociation("publicRouteTableAssociation", {
    routeTableId: publicRouteTable.id,
    subnetId: pulumi.all(subnet_public[0,1]),
  });
what is the proper way you may suggest of specifying -
subnetId: pulumi.all(subnet_public[0,1])
Cheers
l

little-cartoon-10569

08/19/2021, 10:03 PM
You don't need to wrap anything using
pulumi.all
in this case.
const publicRouteTableAssociation = new         aws.ec2.RouteTableAssociation("publicRouteTableAssociation", {
    routeTableId: publicRouteTable.id,
    subnetId: subnet_public[0].id
  });
However you need one association per subnet, so maybe you should create the associations inside the loop.
s

salmon-account-74572

08/19/2021, 11:12 PM
I’ve done it with a separate loop, but creating the association in the same loop is even better (now I need to go refactor my code!).