https://pulumi.com logo
Title
o

orange-byte-86458

06/30/2021, 11:40 PM
I’m wondering what’s the reason for
pulumi state delete
to not support resource deletion if it has children. I’m trying to delete a
k8s.yaml.ConfigFile
, which subsequently expands into ~100 k8s resources and deleting them one by one manually is just not feasible..
l

little-cartoon-10569

06/30/2021, 11:43 PM
Resources are dependent on their parents. If a parent goes, then the definition of the child resources is incomplete.
o

orange-byte-86458

06/30/2021, 11:51 PM
Right, but there could be a flag telling it to delete a parent with all of its children. I think that’s how terraform does it
b

bored-oyster-3147

06/30/2021, 11:53 PM
I think you're looking for
pulumi destroy --target {urn} --target-dependents
? Or is your intention to alter state and not actually destroy anything?
o

orange-byte-86458

06/30/2021, 11:55 PM
Yeah, I for some reason, quite frequently end up in the situation where my pulumi state and the actual state mismatches. In this particular case I was experimenting with the “import” option and ended up in the state where Pulumi has created all the objects in its own state BUT deleted them all from the actual k8s cluster 🤷 Hence yeah, I need to just cleanup the state,
destroy
won’t work 🙂
b

bored-oyster-3147

06/30/2021, 11:56 PM
does a
pulumi refresh
resolve the discrepancies between state and reality?
o

orange-byte-86458

06/30/2021, 11:56 PM
nope, because it doesn’t know how to “unfurl” the
k8s.yaml.ConfigFile
For this particular case I’ve already written a shell script to delete them all btw, I was just wondering in general what’s the reason not to support children deletion
🤔 1
b

better-shampoo-48884

07/01/2021, 10:02 AM
and yeah - the `--target-dependents`doesn't delete children of a given resource "just like that". Had the same issue when trying to delete things like whole component resources - it will not delete the children of said component resource just because it has
--target-dependents
like this:
λ pulumi destroy --target urn:pulumi:stage.infra.customer::baseline-infra::dep:components:provider$dep:components:group$dep:components:network::Net --target-dependents
Previewing destroy (stage.infra.customer):
     Type                        Name                              Plan     Info
     pulumi:pulumi:Stack         baseline-infra-stage.infra.customer
     └─ dep:components:network  Net                                        1 error

Diagnostics:
  dep:components:network (Net):
    error: Cannot delete parent resource 'urn:pulumi:stage.infra.customer::baseline-infra::dep:components:provider$dep:components:group$dep:components:network::Net' without also deleting child 'urn:pulumi:stage.infra.customer::baseline-infra::dep:components:provider$dep:components:group$twin:components:network$azure-native:network:VirtualNetwork::<vnet>-<region>'.
this is why I set up all my component resources with a
create: boolean
flag - I just flip the create to false and it will remove whatever has been created from the stack.. but this doesn't resolve Maksim's issue - there's no way to remove something from a stack, let's say if something screwed up and the stack doesn't represent reality anymore (and a refresh won't work as mentioned) and it needs to be fully re-adopted or simply no longer managed by pulumi.. i.e. a pulumi destroy won't work when you just need it removed from the state since the original resource may not exist.
1