https://pulumi.com logo
#python
Title
# python
e

echoing-dawn-86996

01/10/2021, 12:51 PM
Hey guys! I have a weird issue where
delete_before_replace=True
is simply not working. Here is how I do it:
Copy code
compute.Instance(
    f"{name}-{zone}",
    # More instance config here
    opts=ResourceOptions(delete_before_replace=True)
)
However, pulumi simply ignores it. Each time the resource changes (the name changes), it first creates the new resource, and then deletes the old one. What am I missing here?
g

gentle-diamond-70147

01/10/2021, 10:47 PM
Sounds like a bug. Mind opening an issue at github.com/pulumi/pulumi/issues ?
1
e

echoing-dawn-86996

01/11/2021, 9:39 AM
Could it be because the resource name changes? This sounds like the issue here. This is a follow up to my question in the #general channel: https://pulumi-community.slack.com/archives/C84L4E3N1/p1610047032187200 I'll elaborate my use case: I'm using a container optimized os instance, which supports cloud-init as instance metadata. I have a container version in this instance metadata, and basically the only change that could happen to the instance is when the container version changes - so I need to simply update the metadata. However, in pulumi, when metadata changes it simply updates the instance - but then the cloud init won't run. I have another requirement that 2 instances cannot be run at the same time. Basically I need the instance to be always recreated on any change, so I've added the "version" variable into the resource name. But I also need to make sure that the old instance is removed before the new instance is created.
Basically an option like
recreate_on_update
would have solved the issue for me, but there is no such thing. Should I perhaps open an issue with feature request instead?
@gentle-diamond-70147 I would really appreciate your opinion on this
g

gentle-diamond-70147

01/12/2021, 4:44 PM
Changing the resource name is effectively creating a new resource as far as the Pulumi engine is concerned, so that's why
delete_before_replace
isn't being honored there. If there's some other property you can change that would cause the resource to be replaced (e.g. like
zone
?), then
delete_before_replace
should work in that case. Alternatively, you could call
pulumi up --target-replace ...
to replace the instance which should honor
delete_before_replace
. Would that work for you?
e

echoing-dawn-86996

01/14/2021, 8:53 AM
@gentle-diamond-70147 --target-replace assumes that I know that the instance metadata has changed and therefore I'll be running it on the specific urn. However, in an automated gitops continuous deployment flow you never know what has changed, that's why I'm searching for an option like
recreate_on_update
or some other workaround here..
g

gentle-diamond-70147

01/14/2021, 11:49 PM
I see. I'm not aware of a way to achieve what you're wanting at this time unfortunately.
Do you mind opening an issue at https://github.com/pulumi/pulumi with more details about the functionality you'd like?
e

echoing-dawn-86996

01/17/2021, 3:47 PM
@gentle-diamond-70147 thanks, I've opened an issue - hopefully I've explained it well enough: https://github.com/pulumi/pulumi/issues/6130