Skip to content

Resource option: retainOnDelete ​

The retainOnDelete resource option marks a resource to be retained. If this option is set, Pulumi does not call through to the resource provider's Delete method when deleting or replacing the resource during pulumi up or pulumi destroy. As a result, the resource is not deleted from the backing cloud provider, but is removed from the Pulumi state.

For a complete walkthrough of using this option to remove a resource from a stack without deleting the underlying infrastructure, including how it compares to pulumi state delete, see Removing resources without deleting them.

typescript
const db = new Database("db", {}, { retainOnDelete: true });

Deleting a retained resource ​

To delete a retained resource from the backing cloud provider, first set retainOnDelete: false and run pulumi up. Once the resource is no longer marked retained, a later update that removes it, or pulumi destroy, deletes it fully.

If Pulumi has already removed a retained resource from the stack, the resource still exists in the cloud provider. To delete it, either use the provider's console or CLI, or import it back into Pulumi, unset retainOnDelete, and delete it again.

Inheritance from parent ​

retainOnDelete is inherited from a resource's parent, and defaults to false for resources without a parent. Setting retainOnDelete on a parent retains every descendant in the resource tree, which makes it the way to retain all of the resources in a component resource.

Because a component has no infrastructure of its own in the cloud provider, setting retainOnDelete on a component has no direct effect on the component. Its effect comes entirely from propagating the value to the component's children.

A child can override an inherited value by setting retainOnDelete explicitly. For example, set retainOnDelete: false on a child to delete it normally even though its parent is retained. For the full list of options children inherit, see Inherited resource options.

Content from the official Pulumi documentation (github.com/pulumi/docs).