hey everyone, trying to get some basics right and ...
# python
r
hey everyone, trying to get some basics right and looking to get some help… I have this code available https://gist.github.com/mirzawaqasahmed/819a32cedf73808e57fd4b0ab431d642 https://gist.github.com/mirzawaqasahmed/674abdb307906ac25e592614383d2957 and what i am trying to do is to make sure that 1. https://gist.github.com/mirzawaqasahmed/819a32cedf73808e57fd4b0ab431d642#file-__main__-py-L17 recognizes the fact that VPC isnt created yet and IPv6 block isnt available and wait for it…and only move forward with the rest of the code of creating the subnets once ipv6 cidr is available. 2. trying to store the exports from subnets creation for it to be user later on by applying a custom route table to selected subnets only based on their type Appreciate the help and thanks in advance
b
@rhythmic-lamp-79430 I think we've accurately explained this a couple of times now. If you want to wait for a resource to be finished creating and then do something, you have to use an
apply
in order to do so. I would recommend reading this blog article I wrote: https://www.leebriggs.co.uk/blog/2021/05/09/pulumi-apply.html You're going to have a lot easier time here if you create your own ipv6 block instead of replying on the output from the VPC, but if you really want to use the output from the VPC, you're going to need an
apply
.
r
Hi @billowy-army-68599 i have actually tried it and it didnt work
hence trying to find any other way of doing it
ideally would like keep the ipv6 dynamic as is for now
b
can you share what you tried?
r
also the second ask i am seeking help is around is the storing of export data to refer it in next stage of deployment…any pointers to that
b
r
tried this
Copy code
ipv6_network = resource_vpc.ipv6_cidr_block
ipv6_subnets_generator = ipv6_network.apply(_get_ipv6_subnets_of)
in this case get a new error due to type
Copy code
File "./__main__.py", line 73, in <module>
        ipv6_cidr = str(next(ipv6_subnets_generator))
    TypeError: 'Output' object is not an iterator
based on that tried to change this function to _`_get__ipv6_subnets_of`
Copy code
def _get_ipv6_subnets_of(cidr, prefix):
    ipv6_network = IPNetwork(cidr.apply(lambda cidr: f"{cidr}"))
    cidrs = ipv6_network.subnet(prefix.apply(lambda prefix: int(prefix)))
    return cidrs
still didnt work 🙂
the moment i use the apply property it starts another series of issues with type
b
I don't have enough context here to really fix the problem, but you need to do any manipulation to the networks inside the apply and also do the subnet creation inside the apply
you're not doing that - you're just returning a subnet block and hoping you can manipulate it. you can't, you have to wait for the result to resolve
r
Thanks Jax for the clarification…understood Have tried with few variations but couldn’t make it work…will look at more options