A TTL (time-to-live) policy destroys a stack and everything in it once a set duration has passed. It’s the mechanism for ephemeral infrastructure: dev workspaces, test environments, demos, anything that should clean itself up without someone remembering to run destroy.
How it works
The countdown starts when the stack is first created with the policy attached, and it counts down in the background: no apply is needed to trigger the eventual destroy. Re-applying the stack does not restart the clock; it always counts from the original creation time.
When the TTL expires, formae destroys the stack and all its resources.
Configuration
onDependents
When the TTL expires, formae checks whether any resource outside the stack depends on a resource inside it:
abort (default): cancel the destruction. The stack stays intact until the dependency is removed.
cascade: delete the dependent resources too, following the dependency chain into other stacks.
cascade can delete resources in stacks you didn’t intend to touch, anywhere the dependency chain leads. Use abort unless you’re certain nothing outside the stack should survive it.
Examples
Inline TTL policy:
Reusable TTL policy, shared by every developer’s sandbox stack:
Use cases
- Development environments that clean themselves up at the end of the workday.
- CI/CD test infrastructure that disappears once the test run finishes with it.
- Demo environments that auto-destroy after the demo window.
- Cost control: forgotten resources stop accumulating cost on their own.
Monitoring
Shows every stack’s attached policies, including TTL and its expiry.
See also
- Policy: inline vs. reusable policies, and how to query them.
- Auto-reconcile policy: enforce declared state instead of expiring it. The two can be combined on the same stack.