I'm coming to the end of writing my first vpc in p...
# python
b
I'm coming to the end of writing my first vpc in pulumi and doing it without crosswalk. Someone helped me write a for loop to sort out my subnets into route table associations and I'm getting the error
Copy code
error: Duplicate resource URN 'urn:pulumi:dev::HNO1::aws:ec2/routeTableAssociation:RouteTableAssociation::rta-Calling __str__ on an Output[T] is not supported.
    
    To get the value of an Output[T] as an Output[str] consider:
    1. o.apply(lambda v: f"prefix{v}suffix")
    
    See <https://pulumi.io/help/outputs> for more details.
    This function may throw in a future version of Pulumi.-public'; try giving it a unique name
This is the code that is producing the error, I think I know what has caused it but I don't know how to fix it.
Copy code
pub_rtas = []

for pub_subnet in pub_subnets:
    rta_name = f"rta-{pub_subnet.id}-public"
    pub_rtas.append(rta_name)

    ec2.RouteTableAssociation(
	    rta_name,
	    subnet_id = pub_subnet.id,
	    gateway_id = igw.id,
	    route_table_id="HNO-route-table-public",
	)
b
it’s this line:
Copy code
rta_name = f"rta-{pub_subnet.id}-public"
You can’t concat a string with an
Output[str]
resource names need to be known on creation so this won’t work, you’ll need to use a known value
b
ok thanks
ok I changed it and I think I fixed that error but now I'm getting a stack error that tells me I'm missing a resource name argument where I've clearly defined one here's the new code
Copy code
pub_rtas = []

for pub_subnet in pub_subnets:
    rta_name = pub_subnet.id
    newCall = pub_rtas.append(f"{rta_name}-public")

    ec2.RouteTableAssociation(
		resource_name = newCall,
	    subnet_id = pub_subnet.id,
	    gateway_id = igw.id,
	    route_table_id="HNO-route-table-public",
	)
b
no that doesn’t look correct either:
Copy code
rta_name = pub_subnet.id
    newCall = pub_rtas.append(f"{rta_name}-public")
this just assigned the value
pub_subnet.id
to a string, so it’s still an
Output[str]
so you still can’t concatenate
Copy code
resource_name = newCall,
i din’t think that’s a valid parameter
b
I got it from pulumi documentation and it's built into vscode as well. I don't think you normally need it but I tried to go more explicit since it's saying it doesn't exist
267 Views