Is it possible to define a relationship like “if t...
# general
d
Is it possible to define a relationship like “if this resource is deleted, all of these associated resources are implicitly deleted”? The specific problem I have is using the new
Command
module, if my instance is deleted, Pulumi tries to execute the
delete
part of the command, which is no longer possible. So I want to tell it to just give up on cleaning up any commands that were run on a deleted instance. Is something like this possible? Right now, I have to manually edit my state to clean them up.
l
Add the
dependsOn
opt to everything that should have been deleted before the instance.
That will force Pulumi to delete those resources first, then the instance afterwards.
And afaik, Command resource deletion is trivially removing it from state.
d
That doesn’t quite do what I need - I meant that the instance is deleted externally to Pulumi (e.g. crashes), and then
Command
tries to run it’s
delete
action on an instance that no longer exists.
l
If the resource is changed outside Pulumi, then the only way to get things back in line is to run
pulumi refresh
.
d
Exactly, that doesn’t do anything for the
Command
action - there’s no way for it to know that “this instance was deleted” means “this command is deleted too”. That’s what I want to be able to express. As far as I can tell,
dependsOn
doesn’t seem to include that kind of relationship. If I delete my instance,
pulumi refresh
, and then
pulumi up
, it correctly recreates the instance, but it tries to run the command’s
delete
operation (on the old instance, which no longer exists) before creating the new command on the new instance.
l
Why does it delete anything? I'd have thought it'd go something like this: • Resource is deleted in cloud. •
pulumi refresh
removes resource from state. •
pulumi up
updates state and cloud from code. In that sequence, Pulumi isn't deleting anything. If the Command is being deleted, maybe it's because you have a dependsOn that you don't want? It does seem like you're stuck though: I don't think there is a way to have
refresh
delete resources that have no cloud presence (Command). You don't need to manually edit the state file though, you just need to run
pulumi state delete urn
.
d
You don’t need to manually edit the state file though, you just need to run
pulumi state delete urn
.
Yeah, this is what I meant - I was using
jq
to delete a bunch of commands at once, since
pulumi state delete
doesn’t support wildcards afaik.
Why does it delete anything? I’d have thought it’d go something like this:
• Resource is deleted in cloud.
pulumi refresh
removes resource from state.
pulumi up
updates state and cloud from code.
Exactly -
pulumi refresh
only removes the Instance, it doesn’t detect that the Command is also effectively removed by the instance not existing anymore. Then the
pulumi up
sees that the
connection
input to the Command has changed, so this triggers a
replace
operation, which tries to run the
delete
of the command on the previous instance, and the
create
on the new instance. But the
delete
part fails of course.