Time-to-live stacks
Time-to-live (TTL) Stacks enable the automated management of a stack's lifecycle by specifying a date and time after which the stack is automatically torn down. TTL stacks allow platform teams to control costs, improve security posture, and reduce operational overhead by ensuring temporary or ephemeral cloud resources (like development environments) are automatically de-provisioned.
INFO
A stack's time to live is measured from the stack's creation date, not its most recent update. Updating a stack does not reset its TTL.
Setting a Time-to-Live on a stack
Pulumi Cloud UI
In order to set up Time-to-Live Stacks in the Pulumi Cloud console, follow these steps:
- Ensure Deployments Settings are configured on the stack see the docs
- Navigate to the stack > Settings > Schedules
- Select "Time-to-Live"
- (Optional) Turn on "Delete After Destroy" if applicable
- Set the schedule using a cron expression
- Save the Schedule
You will now see a schedule in the Schedules tab which highlights when the destroy will occur.
REST API
For those who prefer to automate and script their infrastructure tasks, Time-to-Live schedules can be configured programmatically using simple HTTP requests.
- Create a Time-to-Live schedule
- Get a Time-to-Live schedule for a stack
- Update or delete a Time-to-Live schedule
- Pause or resume a Time-to-Live schedule
- List all schedules in the organization (includes raw Pulumi operations and Drift schedules)
Below is an example of setting up Time-To-Live on a stack programmatically:
curl -H "Accept: application/vnd.pulumi+json" \
-H "Content-Type: application/json" \
-H "Authorization: token $PULUMI_ACCESS_TOKEN" \
--request POST \
--data '{"timestamp":"2030-12-31T23:59:59Z","deleteAfterDestroy":true}' \
https://api.pulumi.com/api/stacks/{organization}/{project}/{stack}/deployments/ttl/schedulesRefer to the Pulumi Deployments REST API documentation for more details on how to use the REST API to manage Time-to-Live Stacks.
Pulumi Cloud provider
The Pulumi Service Provider allows you to set up and manage Time-to-Live Stacks in source control.
import * as pulumi from "@pulumi/pulumi";
import * as pulumiservice from "@pulumi/pulumiservice";
const organizationName = "my-org";
const projectName = "my-project";
const stackName = "temp-stack";
const ttlSchedule = new pulumiservice.TtlSchedule("ttlSchedule", {
organization: organizationName,
project: projectName,
stack: stackName,
timestamp: "2030-01-01T00:00:00Z" // Specify the ISO date/time for destruction
});
export const scheduleId = ttlSchedule.scheduleId;See the Pulumi Service Provider documentation for more details on how to manage Time-to-Live Stacks in source control.