Skip to content

Resource option: protect ​

The protect resource option marks a resource as protected. A protected resource cannot be deleted directly, and it will be an error to do a Pulumi deployment which tries to delete a protected resource for any reason.

protect is a Pulumi-engine construct, enforced entirely within Pulumi and never sent to the cloud provider. Many cloud resources also carry their own, separate deletion-protection attributes, such as deletionProtection on a GCP Cloud SQL instance or an AWS RDS instance, which the cloud provider enforces independently of anything Pulumi knows about. A resource can be unprotected in Pulumi and still refuse to delete, or vice versa. See Deletion protection on the resource itself for how to tell the two apart and resolve each.

To delete a protected resource, it must first be unprotected. There are two ways to unprotect a resource:

Once the resource is unprotected, it can be 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.

typescript
let db = new Database("db", {}, { protect: true });

Overriding inherited protection ​

Child resources inherit the protect option from their parent resource. When a parent resource has protect: true, all of its children are also protected by default. To allow a specific child resource to be deleted independently of its protected parent, explicitly set protect: false on that child.

The following example creates a protected parent resource alongside a child resource with protection explicitly disabled:

typescript
const parent = new MyResource("parent", {}, { protect: true });
const child = new MyResource("child", {}, { parent: parent, protect: false });

Applying protection to all resources ​

There is no built-in configuration flag to mark every resource in a stack as protected. To apply protect: true to all resources in a stack, use stack transforms. A stack transform is a callback that the Pulumi engine invokes for every resource during deployment; it can inspect and modify resource options, including protect, before the resource is created or updated.

See also ​

protect is one of several safeguards for keeping production infrastructure safe. For the full workflow, including reviewing previews, update plans, policy as code, and CI/CD gating, see Protecting against undesired changes.

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