https://pulumi.com logo
m

modern-evening-83482

07/07/2022, 6:57 AM
Copy code
pulumi:pulumi:Stack pulumi-infrastructure-network.dev running Calling __str__ on an Output[T] is not supported.
    pulumi:pulumi:Stack pulumi-infrastructure-network.dev running To get the value of an Output[T] as an Output[str] consider:
    pulumi:pulumi:Stack pulumi-infrastructure-network.dev running 1. o.apply(lambda v => f"prefix{v}suffix")
    pulumi:pulumi:Stack pulumi-infrastructure-network.dev running See <https://pulumi.io/help/outputs> for more details.
    pulumi:pulumi:Stack pulumi-infrastructure-network.dev running This function may throw in a future version of Pulumi.
    pulumi:pulumi:Stack pulumi-infrastructure-network.dev  5 messages
Hello Guys, Any clue why pulumi is throwing the following warning. I am create a aws vpc and then using the
vpc.id
field
l

little-cartoon-10569

07/08/2022, 3:32 AM
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

modern-evening-83482

07/20/2022, 4:44 PM
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

little-cartoon-10569

07/21/2022, 12:58 AM
Yes, where is the bad code? I don't see any problems there (though my Python is minimal)
m

modern-evening-83482

07/21/2022, 1:04 AM
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

little-cartoon-10569

07/21/2022, 1:07 AM
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

modern-evening-83482

07/21/2022, 1:07 AM
suffix is an input
l

little-cartoon-10569

07/21/2022, 1:07 AM
Won't work
m

modern-evening-83482

07/21/2022, 1:08 AM
idx is a value from enumerate...
l

little-cartoon-10569

07/21/2022, 1:08 AM
If they're inputs and strings, then cast them. If they're inputs and outputs, then it won't work.
m

modern-evening-83482

07/21/2022, 1:08 AM
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

little-cartoon-10569

07/21/2022, 1:09 AM
public_subnets is an output. You cannot use it for making names of Pulumi resources.
m

modern-evening-83482

07/21/2022, 1:09 AM
hmm its a list...
i am capturing
ec2_subnet.id.apply(lambda _id: f"{_id}")
l

little-cartoon-10569

07/21/2022, 1:09 AM
Sorry. It contains outputs.
m

modern-evening-83482

07/21/2022, 1:10 AM
hmm so how do i get strings then?
i just need the public subnet ids
l

little-cartoon-10569

07/21/2022, 1:10 AM
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

modern-evening-83482

07/21/2022, 1:11 AM
ok how do I go about this then? i would like to loop and create public
l

little-cartoon-10569

07/21/2022, 1:11 AM
Yes, but don't use the subnet ids for the resource names.
m

modern-evening-83482

07/21/2022, 1:11 AM
oh dont use it as resource names
l

little-cartoon-10569

07/21/2022, 1:11 AM
You could use whatever you used for the subnet resource names.
m

modern-evening-83482

07/21/2022, 1:12 AM
{subnet}
u mean
l

little-cartoon-10569

07/21/2022, 1:12 AM
All resource names must must be fully resolvable at run time. Nothing can come from a provider (cloud).
m

modern-evening-83482

07/21/2022, 1:12 AM
ok let me try this
even tags?
l

little-cartoon-10569

07/21/2022, 1:13 AM
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

modern-evening-83482

07/21/2022, 1:13 AM
ok
thank u
what about this cidr block?
f"10.27.{subnet}.0/24"
its going to be a pain
l

little-cartoon-10569

07/21/2022, 1:15 AM
That's not a resource name.
That's fine.
m

modern-evening-83482

07/21/2022, 1:15 AM
ah ok ok
😄
thank u dude
now it looks so much clear
l

little-cartoon-10569

07/21/2022, 1:15 AM
Though if the {subnet} value is an output, you have to use pulumi.interpolate
m

modern-evening-83482

07/21/2022, 1:15 AM
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

little-cartoon-10569

07/21/2022, 1:18 AM
pulumi interpolate is just a convenience wrapper that handles string outputs much like normal string interpolation. Not even sure it exists in Python.
m

modern-evening-83482

07/21/2022, 1:19 AM
got it..same as .apply?
l

little-cartoon-10569

07/21/2022, 1:24 AM
Very similar. Easier to read, but limited to strings.
m

modern-evening-83482

07/27/2022, 5:34 PM
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

little-cartoon-10569

07/27/2022, 7:58 PM
_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

modern-evening-83482

09/16/2022, 12:43 AM
thank you.
2 Views