https://pulumi.com logo
Title
p

purple-train-14007

01/30/2023, 11:45 PM
I don’t want to say I found a bug but today I was surprised by a stack update failure when I was expecting Pulumi to simply delete the resource and rebuild it. So I made a VPC and some subnets but forgot to add the az I wanted to put them in so I went ahead and added the az expecting the resource to destroy and rebuild. The resource however failed in my pipeline saying that the network conflicted with an existing resource instead of simply deleting the resource and building it back
l

little-cartoon-10569

01/31/2023, 12:06 AM
Is the AZ you added the same as the default AZ? If the AZ isn't actually changing (despite the property changing), then this might be expected behaviour? Don't know, never done it...
p

purple-train-14007

01/31/2023, 1:16 AM
Nope different AZ. The default was USW2C
But the issue is it failed to adjust the resource rather than destroy and remake it acted as if it didn’t know anything about the resource. I pulled open the state file and also verified that it was tracking the subnets and VPC too
l

little-cartoon-10569

01/31/2023, 1:20 AM
It's not supposed to adjust the resource. According to the docs, changing the AZ is supposed to destroy and recreate it.
Did you also change the name of the resource at the same time?
p

purple-train-14007

01/31/2023, 1:23 AM
That’s what I meant
But no I didn’t change the name. Simply added the az
l

little-cartoon-10569

01/31/2023, 2:24 AM
Have you set a name for any of the resources? Maybe it was doing a delete-before-create (which is the default), and the created resource was conflicting with the old version of the same resource?
p

purple-train-14007

01/31/2023, 2:25 AM
Nope, all the names were the same
l

little-cartoon-10569

01/31/2023, 2:26 AM
Yes, that's what I mean. If you use the
name
property, then there will be a conflict and it will fail
You have to either omit the
name
, or use
namePrefix
p

purple-train-14007

01/31/2023, 2:26 AM
Ah no, name is a string
l

little-cartoon-10569

01/31/2023, 2:26 AM
Yes, the point is, you're supplying the name, rather than letting Pulumi make up a random one
p

purple-train-14007

01/31/2023, 2:27 AM
Ohhhhh!
l

little-cartoon-10569

01/31/2023, 2:27 AM
This will cause what you're seeing
p

purple-train-14007

01/31/2023, 2:27 AM
So setting the resource name causes it not to delete?
l

little-cartoon-10569

01/31/2023, 2:27 AM
No, not necessarily.
p

purple-train-14007

01/31/2023, 2:27 AM
For instance if I same VPCName = blah-vpc
l

little-cartoon-10569

01/31/2023, 2:28 AM
You can also set the
deleteBeforeReplace
opt, and it'll delete the resource first, which prevent the name clash
p

purple-train-14007

01/31/2023, 2:28 AM
Ah ok, I’ll try that
l

little-cartoon-10569

01/31/2023, 2:28 AM
Generally, the best thing is to not specify a name.
Pulumi will generate a name for you, from the Pulumi name (1st arg) and a random suffix
p

purple-train-14007

01/31/2023, 2:28 AM
But I want my stuff to have names in the AWS console otherwise I can’t tell them apart
l

little-cartoon-10569

01/31/2023, 2:29 AM
You will get meaningful names, but with a suffix.
You will be able to tell them apart.
p

purple-train-14007

01/31/2023, 2:29 AM
Ok
That’s odd lol
l

little-cartoon-10569

01/31/2023, 2:29 AM
Note that some resources (e.g. EC2 instances) have special ways to name them. (For EC2 resources, it's the
name
tag).
What's odd? That Pulumi creates names?
p

purple-train-14007

01/31/2023, 2:29 AM
Yeah
l

little-cartoon-10569

01/31/2023, 2:30 AM
Pulumi does it in order to avoid this problem.
p

purple-train-14007

01/31/2023, 2:30 AM
But the names are unique?
l

little-cartoon-10569

01/31/2023, 2:30 AM
AWS doesn't allow 2 resources of the same type with the same name.
p

purple-train-14007

01/31/2023, 2:30 AM
Correct
l

little-cartoon-10569

01/31/2023, 2:30 AM
When you replace the resource, Pulumi creates a new resource before deleting the old one. Hence, name clash
p

purple-train-14007

01/31/2023, 2:30 AM
But AWS CDK knows to delete the resource regardless of name
l

little-cartoon-10569

01/31/2023, 2:30 AM
You think of it as 1 resource, but in AWS, there's the old one and the new one.
So does Pulumi.
Pulumi has a default policy of not deleting on replace, until the replacement resource is created.
p

purple-train-14007

01/31/2023, 2:31 AM
Ok so I will not name the things then
I will take it out of my component resource
l

little-cartoon-10569

01/31/2023, 2:32 AM
Yes. If you do that, then the created resource will have a different name than the old version of it. And there will be no name conflict
p

purple-train-14007

01/31/2023, 2:33 AM
Thanks for explaining this I appreciate it 😇
q

quaint-hydrogen-7228

01/31/2023, 10:22 AM
AWS CDK will also have issues in some cases if you set the name explicitly, if the resources need to be replaced, due to what the underlying Cloudformation support. The general rule there is the same, do not set names explicitly if you do not have to.