Not sure if I should ask here or if I should ask i...
# python
c
Not sure if I should ask here or if I should ask in the #C84L4E3N1 questions... but here goes! I am using Azure and Python. I would like to use a pre-existing subnet if it exists, but if it doesn't, then I would like to create and use it. I have a try/except setup that seems to do what I expect the first time I run
pulumi up
, but the second time, it wants to delete the subnet I created previously. Here is my try/except block:
Copy code
try:
    print("trying....")
    subnet = network.get_subnet(
        resource_group_name=resource_group.name,
        subnet_name="CS-DEL-subnet-" + pulumi.get_stack(),
        virtual_network_name=vnet_name,
    )
except:
    print("Got to the except")
    subnet = network.Subnet(
        address_prefix=vnet.apply(get_next_subnet_prefix),
        resource_name="CS-DEL-subnet-" + pulumi.get_stack(),
        resource_group_name=resource_group.name,
        subnet_name="CS-DEL-subnet-" + pulumi.get_stack(),
        virtual_network_name=vnet_name,
    )
I'm not sure if this is a Pulumi thing I'm doing wrong, or a Python thing I'm doing wrong. Any insight would be fantastic! Don't necessarily need a solution, just direction toward documentation would be great! (Though a solution would not be turned down 🙂 )
s
based on the code, if the subnet exists
network.Subnet
resource doesn't get added to the code/state anymore, as its using the get_subnet object.
c
Thanks! I realized that after banging my head into the wall a bit 😉 Thanks for the reply!