This message was deleted.
s
This message was deleted.
l
It's because you're attempting to use
vpc.id
as a string, but it's not a string. It's a promise of a future string. You need to use an apply, which will be called in the future, when the value of the id will be available.
m
thank you
Copy code
ec2_public_rt = aws.ec2.RouteTable(
    f"{env}-route-table-public-{suffix}",
    vpc_id=vpc.id,
    tags={
        "Name": f"{env}-route-table-public-{suffix}",
    },
    routes=[
        aws.ec2.RouteTableRouteArgs(
            cidr_block="0.0.0.0/0",
            gateway_id=ec2_internet_gateway.id,
        ),
    ],
    opts=pulumi.ResourceOptions(provider=provider),
)
public_route_table = ec2_public_rt.id.apply(lambda _id: f"{_id}")
I have something like that
but i still see the Calling str on an Output[T] is not supported.
l
Yes, where is the bad code? I don't see any problems there (though my Python is minimal)
m
Copy code
for idx, subnet in enumerate(public_subnets):
    ec2_subnet_route_table_association = aws.ec2.RouteTableAssociation(
        f"{env}-public-subnet-route-table-association-{suffix}-{subnet}-{idx}",
        route_table_id=ec2_public_rt.id,
        subnet_id=subnet,
        opts=pulumi.ResourceOptions(provider=provider),
    )
i have this code following that
and I hit
Copy code
dev-public-subnet-route-table-association-btrq-Calling __str__ on an Output[T] is not supported.
i try to get the route table id so i can use it when i do the subnet route table association
l
What are suffix, idx and subnet? Are any of those outputs? You're converting those to strings, so that won't work if they're outputs.
m
suffix is an input
l
Won't work
m
idx is a value from enumerate...
l
If they're inputs and strings, then cast them. If they're inputs and outputs, then it won't work.
m
Copy code
public_subnets = []
for subnet in range(subnet_counter, subnet_counter + number_of_azs):
    ec2_subnet = aws.ec2.Subnet(
        f"{env}-public-subnet-{subnet}-{suffix}",
        availability_zone=available_azs.names[subnet - subnet_counter],
        cidr_block=f"10.27.{subnet}.0/24",
        vpc_id=vpc.id,
        map_public_ip_on_launch=False,
        tags={
            "Type": "Public",
            "Name": f"{env}-public-subnet-{subnet}-{suffix}",
        },
        opts=pulumi.ResourceOptions(provider=provider),
    )
    public_subnets.append(ec2_subnet.id.apply(lambda _id: f"{_id}"))
this is how i am getting the public subnet ids
cast them to?
l
public_subnets is an output. You cannot use it for making names of Pulumi resources.
m
hmm its a list...
i am capturing
ec2_subnet.id.apply(lambda _id: f"{_id}")
l
Sorry. It contains outputs.
m
hmm so how do i get strings then?
i just need the public subnet ids
l
You do not get at strings that come from the cloud (like subnet ids) for use in the 1st parameter of Pulumi constructors. Just don't do it.
In general, you get at strings from outputs inside an apply(). But don't do it (don't even try it) for Pulumi resource names.
m
ok how do I go about this then? i would like to loop and create public
l
Yes, but don't use the subnet ids for the resource names.
m
oh dont use it as resource names
l
You could use whatever you used for the subnet resource names.
m
{subnet}
u mean
l
All resource names must must be fully resolvable at run time. Nothing can come from a provider (cloud).
m
ok let me try this
even tags?
l
You can put a value into a tag and into a resource name. But you can't get a tag from a provider and then put it into a resource name.
m
ok
thank u
what about this cidr block?
f"10.27.{subnet}.0/24"
its going to be a pain
l
That's not a resource name.
That's fine.
m
ah ok ok
😄
thank u dude
now it looks so much clear
l
Though if the {subnet} value is an output, you have to use pulumi.interpolate
m
its not an output there
so i am good
i was loving pulumi and then is aw this
thank u for clearing this
i thought u have to use pulumi.Output?
never heard of pulumi.interpolate..will read about it..
l
pulumi interpolate is just a convenience wrapper that handles string outputs much like normal string interpolation. Not even sure it exists in Python.
m
got it..same as .apply?
l
Very similar. Easier to read, but limited to strings.
m
Hi Paul hope you are doing well. I had a quick question. i am getting a stack reference output...
ecs_cluster_name = infra_stack.get_output("ecs_cluster_name")
i would like to use the value of
ecs_cluster_name
in my current stack in the ecs commands list(strings)
l
_ecs_cluster_name_ is an output. If you can use it as an input, then you don't need to do anything. If you cannot, then you'll need to apply() to get the value. Where is the API for the ECS commands list that you mention? We can figure out how to get the string / output into the right format.
m
thank you.