I wrote a component for some Azure networking in P...
# azure
m
I wrote a component for some Azure networking in Python, and it's working well. However, I'm seeing it appending a random string to the names of things. How do I get it to stop that?
h
pulumi just does that by default for all resources, to prevent conflicts when recreating, using stacks, and a few other situations
if you really don't want it to, I think
pulumi.ResourceOptions
has a flag to override it
m
Oh, good call! I'll check that out. I'm trying to import existing vnets into using a component, and this would cause a re-creation, which is not desireable.
h
oh, you want the import options then
pulumi import
or
pulumi.ResourceOptions.import
i believe
m
I've imported the resources already, just trying to get the code to match.
h
in particular, there's a flow where
pulumi preview
can produce a template json that you can fill in resource IDs on and then hand to
pulumi import
ahhh
m
Yeah, and so the appended string is a surprise. XD
h
the import flow will tell pulumi which realized resources match which code resources/pulumi URNs, but you gotta get their properties to match manually
that is, adjust your code until it produces the properties the resource already has
keep in mind that most resources have some properties that can only be changed on creation, and that's a restriction by azure, not pulumi
m
Oh geez...No, my mistake was simpler than that. I was doing
Copy code
self.virtual_network = azure_native.network.VirtualNetwork(f"vnet-{name}",
            resource_group_name=self.resource_group.name,
            address_space=azure_native.network.AddressSpaceArgs(
                address_prefixes=[vnet_cidr]    
            ),
            opts=pulumi.ResourceOptions(parent=self.resource_group))
Instead of:
Copy code
self.virtual_network = azure_native.network.VirtualNetwork(f"vnet-{name}",
            vritual_network_name = f"vnet-{name}", <----- Missing this
            resource_group_name=self.resource_group.name,
            address_space=azure_native.network.AddressSpaceArgs(
                address_prefixes=[vnet_cidr]    
            ),
            opts=pulumi.ResourceOptions(parent=self.resource_group))
Since I wasn't explicitly calling the actual name arguement, Pulumi was doing it's derivative for the name.
That's where the random string came from.
h
ah, yes
i just use the random names myself, but i'm greenfielding
m
Yeah, this is after using Terraform for two years that I'm switching. So, there's a lot for me to catch up on.
Enjoy the greenfield! haha