How can I find the public subnets of an existing aws VPC with pulumi?
I have tried several approaches and one that seems to get close is below, but I can't seem to filter on an attribute of the subnet due to how the pulumi.OutputInstance
works.
If Subnet.mapPublicIpOnLaunch
was a boolean
instead of a pulumi.OutputInstance<boolean | undefined>
, it could be filtered like this:
const publicSubnets = aws.ec2.getSubnetIds({vpcId: vpcId})
.then(s=> s.ids
.filter(i=>aws.ec2.Subnet.get(`subnet-`+i,i).mapPublicIpOnLaunch))
Since Subnet.mapPublicIpOnLaunch
is a pulumi.OutputInstance
it can't be filtered on them without first resolving the output. I have trying wrapping everything in a call to pulumi.output
in a few ways but still can't get the Subnet.mapPublicIpOnLaunch
unwrapped so that it can be filtered on.
My current workaround is below, but this feels like a hack and I would like to do this in a more pulumi style way and not have to exec.
const execAsync = util.promisify(exec)
const publicSubnets = execAsync(`aws ec2 describe-subnets --filter Name=vpc-id,Values=${vpcId} ` +
"--query Subnets[?MapPublicIpOnLaunch].SubnetId")
.then(r => JSON.parse(r.stdout) as string[])