Skip to main content
  1. Docs
  2. Infrastructure as Code
  3. Concepts
  4. Resources
  5. Resource options
  6. retainOnDelete

Resource option: retainOnDelete

    The retainOnDelete resource option marks a resource to be retained. If this option is set then Pulumi will 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 will not be deleted from the backing cloud provider, but will be removed from the Pulumi state.

    Applies to custom resources only. The retainOnDelete 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 retainOnDelete on a component has no direct effect — components don't have cloud resources to retain. The value propagates to every child custom resource of the component, which is the idiomatic way to retain a whole subtree.

    If a retained resource is deleted by Pulumi and you later want to actually delete it from the backing cloud provider you will either need to use your provider’s manual interface to find and delete the resource, or import the resource back into Pulumi to unset retainOnDelete and delete it again fully.

    To actually delete a retained resource, this setting must first be set to false.

    • Set retainOnDelete: false and then run pulumi up

    Once the resource is no longer marked retained, it can be fully deleted as part of a following update.

    The default is to inherit this value from the parent resource, and false for resources without a parent.

    let db = new Database("db", {}, { retainOnDelete: true });
    
    db = Database("db", opts=ResourceOptions(retain_on_delete=True))
    
    db, _ := NewDatabase(ctx, "db", &DatabaseArgs{}, pulumi.RetainOnDelete(true));
    
    var db = new Database("db", new DatabaseArgs(),
        new CustomResourceOptions { RetainOnDelete = true });
    
    var db = new Database("db",
        DatabaseArgs.Empty,
        CustomResourceOptions.builder()
            .retainOnDelete(true)
            .build());
    
    resources:
      db:
        type: Database
        options:
          retainOnDelete: true