ubx destroy or removes the block. An autoscaling group’s desired_capacity is managed at runtime by AWS Auto Scaling, and Pulumi shouldn’t try to reset it on every apply. An EC2 instance that requires zero downtime should have its replacement provisioned before the old one is torn down. The lifecycle block is where you express these exceptions — three settings that override the default resource management behavior in precisely targeted ways.
What you’ll learn
prevent_destroy— block accidental destruction of critical resourcesignore_changes— suppress drift on attributes managed outside ubxcreate_before_destroy— provision a replacement before tearing down the original
Why this matters
lifecycle settings are evaluated by Pulumi at apply time, not at compile time. They’re metadata instructions to the Pulumi engine, not ubx expressions. This means they don’t interact with the Pending<T> system and can’t reference resource outputs — they take literal values only.The source code
How it works
prevent_destroy is a Pulumi engine flag
When
prevent_destroy = true, Pulumi marks the resource with a destruction guard. Any plan that would destroy it — ubx destroy, a block removal, or an attribute change that forces replacement — errors before executing. The only way to remove the resource is to set prevent_destroy = false first, then apply, then remove the block.ignore_changes suppresses drift detection
Attributes listed in
ignore_changes are excluded from Pulumi’s diff calculation. Even if the live value differs from what’s in .iac, Pulumi won’t generate an update for those attributes. This is essential for attributes managed by external systems — autoscalers, Kubernetes controllers, manual operator changes.create_before_destroy changes the replacement order
Normally Pulumi destroys then creates (to avoid naming conflicts).
create_before_destroy = true reverses this: the replacement is provisioned first, then the old resource is destroyed. Required for resources where the old instance must remain available until the new one is ready.What ubx generates
Common mistakes
Run it
What you learned
prevent_destroy = true blocks any plan that would destroy the resourceignore_changes suppresses drift on attributes managed by external systemscreate_before_destroy = true provisions the replacement before destroying the originalNext steps
Timeouts and ignore_changes
Override provider-default wait times
lifecycle reference
Full lifecycle block syntax
Full runnable example: github.com/ubiquex/ubx-examples/10-lifecycle-block

