I don’t want to say I found a bug but today I was ...
# aws
p
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
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
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
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
That’s what I meant
But no I didn’t change the name. Simply added the az
l
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
Nope, all the names were the same
l
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
Ah no, name is a string
l
Yes, the point is, you're supplying the name, rather than letting Pulumi make up a random one
p
Ohhhhh!
l
This will cause what you're seeing
p
So setting the resource name causes it not to delete?
l
No, not necessarily.
p
For instance if I same VPCName = blah-vpc
l
You can also set the
deleteBeforeReplace
opt, and it'll delete the resource first, which prevent the name clash
p
Ah ok, I’ll try that
l
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
But I want my stuff to have names in the AWS console otherwise I can’t tell them apart
l
You will get meaningful names, but with a suffix.
You will be able to tell them apart.
p
Ok
That’s odd lol
l
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
Yeah
l
Pulumi does it in order to avoid this problem.
p
But the names are unique?
l
AWS doesn't allow 2 resources of the same type with the same name.
p
Correct
l
When you replace the resource, Pulumi creates a new resource before deleting the old one. Hence, name clash
p
But AWS CDK knows to delete the resource regardless of name
l
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
Ok so I will not name the things then
I will take it out of my component resource
l
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
Thanks for explaining this I appreciate it 😇
q
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.