Resource option: deletedWith
The deletedWith resource option allows you to skip resource deletion if another resource is being deleted as well.
deletedWith resource option has no direct effect on component resources. It is defined on the base resource-options type in every Pulumi SDK, so no SDK rejects it at compile time — passing it to a component resource has no direct effect at runtime. Setting deletedWith on a component is accepted by the SDK but has no direct effect, because the engine never calls Delete on components. The value does propagate to every child custom resource of the component, so using it on a component is the idiomatic way to apply deletedWith to a whole subtree.Pulumi will normally call the provider’s delete action for every resource during a delete operation. Sometimes, this is redundant if another resource is also deleted, such as a parent container resource, and can cause your delete or destroy operations to take longer than needed.
For example, if you are deleting a Kubernetes cluster or Kubernetes namespace, you might want to speed up deletion by skipping delete on any Pulumi managed resources created in that Kubernetes cluster or namespace since they will be deleted implicitly.
import * as k8s from "@pulumi/kubernetes";
let ns = new k8s.core.v1.Namespace("res1", {/*...*/})
let dep = new k8s.apps.v1.Deployment("res2", {/*...*/}, { deletedWith: ns });
import pulumi_kubernetes as k8s
ns = k8s.core.v1.Namespace("res1", {})
dep = k8s.apps.v1.Deployment("res2", opts=ResourceOptions(deleted_with=ns))
ns, err := v1.NewNamespace(ctx, "res1", nil)
if err != nil {
return err
}
dep, err := v1.NewDeployment(ctx, "res2", &v1.DeploymentArgs{/*...*/}, pulumi.DeletedWith(ns))
if err != nil {
return err
}
var ns = new Namespace("res1");
var dep = new Deployment("res2", new DeploymentArgs(),
new CustomResourceOptions { DeletedWith = ns });
var ns = new Namespace("res1");
var dep = new Deployment("res2", new DeploymentArgs(),
CustomResourceOptions.builder()
.deletedWith(ns)
.build());
resources:
ns:
type: kubernetes:core/v1:Namespace
name: res1
res2:
type: kubernetes:apps/v1:Deployment
name: res2
options:
deletedWith: ${ns}
Inheritance from parent
deletedWith is inherited from a resource’s parent. Setting deletedWith on a parent causes every descendant in the resource tree to skip its provider delete as well, which makes it the idiomatic way to apply deletedWith for component resources.
Because the Pulumi engine never invokes Delete on a component itself, setting deletedWith on a component has no direct effect on the component. Its effect comes entirely from propagating the value to each of the component’s child custom resources, which then skip their own deletes.
Thank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.