This message was deleted.
# general
s
This message was deleted.
b
If you're coming from a CDK background this is the most annoying part of pulumi. CDK handles tokens for you automatically but here, you have to get those values via an async style.
Copy code
subnet_infos = private_subnets.ids.apply(lambda ids: [get_subnet_info(id) for id in ids])
Did you try that syntax?
a
@broad-doctor-18421 I done something similer for it. I am fustrated from this. There is no to much example also to be inspire from online
Well I got
AttributeError: 'list' object has no attribute 'apply'
Thanks for help @broad-doctor-18421
b
It is a frustrating model. It's something I believe should be taken care of natively by pulumi. Conversely in CDK, you will try to print an output and sometimes get:
subnet is Output<TOKEN:asdf23lkj>
But the code internally will just handle it, and you don't have to know if you're dealing with a string or an output.
I think your answer is somewhere along those lines. But I fumble with pulumi still. Hopefully someone else might have better advice.
a
Thanks for you time and trying to help out!
m
It looks like you're appending the result of the lookup rather than the
id
property of the subnet that was looked up, which I think is what you want.
If you change this:
Copy code
subnet_info = aws.ec2.get_subnet(id=subnet_id)
to this:
Copy code
subnet_info = aws.ec2.get_subnet(id=subnet_id).id
you get:
Copy code
Diagnostics:
  pulumi:pulumi:Stack (aws-python-bec8f14-dev):
    ['subnet-03e8c4a257e371bcc', 'subnet-013f2322ca6908836', 'subnet-08fbebe8d8aaa51af']
Hope that helps! You had everything right, just missed that one little thing, looks like. 🙂
Full program for reference:
Copy code
import pulumi_aws as aws

vpc = aws.ec2.Vpc.get("existing-vpc", id="vpc-abc123")

def get_subnets_info(private_subnets):
    subnets_info = []

    for subnet_id in private_subnets:
        subnet_info = aws.ec2.get_subnet(id=subnet_id).id
        subnets_info.append(subnet_info)

    return subnets_info

private_subnets = aws.ec2.get_subnets(filters=[{"name": "vpc-id", "values": [vpc.id]}],tags={"SubnetType":"Private"})
subnets_info = get_subnets_info(private_subnets.ids)
print(subnets_info)