calm-actor-89994
02/07/2025, 7:00 PMOutput[list[str]]
['10.10.16.0/24', '10.10.17.0/24', '10.10.18.0/25', '10.10.18.128/25', '10.10.19.0/27', '10.10.19.32/27']
it must be output, because it can be known only after some other resources have been provisioned.
now, I need to create a subnet based on the index, simplified sample looks like this:
for j, subnet in enumerate(subnets):
print(j, subnet.name)
subnet_cidrs.apply(lambda cidrs: print(subnet.name, cidrs[j]))
but the output is not what I expect:
0 int-az1
1 int-az2
2 ext-az1
3 ext-az2
4 db-az1
5 db-az2
========
db-az2 10.10.19.32/27
db-az2 10.10.19.32/27
db-az2 10.10.19.32/27
db-az2 10.10.19.32/27
db-az2 10.10.19.32/27
db-az2 10.10.19.32/27
it is very weird behavior. I suspect that apply
doesnt play well inside the for loop, where the value j
is changing, but I am not sure how to solve it.
any suggestions?able-ability-55163
02/07/2025, 7:19 PMfor j, subnet in enumerate(subnets):
print(j, subnet.name)
inner_j = j
subnet_cidrs.apply(lambda cidrs: print(subnet.name, cidrs[inner_j]))
able-ability-55163
02/07/2025, 7:35 PMfor j, subnet in enumerate(subnets):
print(j, subnet.name)
subnet_cidrs.apply(lambda cidrs, j=j: print(subnet.name, cidrs[j]))
calm-actor-89994
02/07/2025, 9:41 PM