https://pulumi.com logo
b

bored-jackal-93148

12/10/2019, 11:04 PM
I want to associate each of my vpcs external subnets with a nat gateway and make available a map of the subnet ids to gateways for use bny other components.
Copy code
vpc.publicSubnetIds.reduce((gateways, id) => {
      gateways[pulumi.interpolate`${id}`] = vpc.addNatGateway(
        `${config.release.name}-${name}-${id}-gateway`,
        { subnet: id },
        { parent: vpc }
      );
    }, {});
Doesn’t work as output can’t be a key … any guidence
c

clever-sunset-76585

12/10/2019, 11:39 PM
Try this:
Copy code
vpc.publicSubnetIds.apply(ids => {
  ids.forEach(id => {
     gateways[id] = vpc.addNatGateway(
        `${config.release.name}-${name}-${id}-gateway`,
        { subnet: id },
        { parent: vpc }
      );
  });
});
b

bored-jackal-93148

12/10/2019, 11:47 PM
unfortunately subnetids is an array of output string not a output of string array
I need to flip the onion, but my ts foo is not that strong
c

clever-sunset-76585

12/10/2019, 11:51 PM
Ah I see, how about using
pulumi.all()
?
Copy code
pulumi.all(vpc.publicSubnetIds).apply((ids) => {
  ids.forEach(id => {
     gateways[id] = vpc.addNatGateway(
        `${config.release.name}-${name}-${id}-gateway`,
        { subnet: id },
        { parent: vpc }
      );
  });
});
Did you get this working?