Skip to content

Prebuild TTL Configuration Support #17916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ssncferreira opened this issue May 19, 2025 · 0 comments · Fixed by #17996
Closed

Prebuild TTL Configuration Support #17916

ssncferreira opened this issue May 19, 2025 · 0 comments · Fixed by #17996
Assignees

Comments

@ssncferreira
Copy link
Contributor

Description

Introduce support for a TTL (Time-To-Live) configuration for prebuilt workspaces, enabling automatic invalidation and replacement of unclaimed prebuilds after a specified duration.

When defining a prebuild in Terraform, users should be able to set the maximum lifetime of a prebuild using the invalidate_after_secs field under the cache_invalidation block. After this duration has passed, the prebuild should be considered stale and be replaced automatically.

prebuilds = {
  instances = 2
  cache_invalidation = {
    invalidate_after_secs = 86400 // 1 day
  }
}

This feature will help prevent stale workspaces due to outdated codebases or infrastructure changes (e.g., new VM images).

@ssncferreira ssncferreira self-assigned this May 19, 2025
ssncferreira added a commit that referenced this issue May 26, 2025
## Summary 

This PR introduces support for expiration policies in prebuilds. The TTL
(time-to-live) is retrieved from the Terraform configuration
([terraform-provider-coder
PR](coder/terraform-provider-coder#404)):
```
prebuilds = {
	  instances = 2
	  expiration_policy {
		  ttl = 86400
	  }
  }
```
**Note**: Since there is no need for precise TTL enforcement down to the
second, in this implementation expired prebuilds are handled in a single
reconciliation cycle: they are deleted, and new instances are created
only if needed to match the desired count.

## Changes

* The outcome of a reconciliation cycle is now expressed as a slice of
reconciliation actions, instead of a single aggregated action.
* Adjusted reconciliation logic to delete expired prebuilds and
guarantee that the number of desired instances is correct.
* Updated relevant data structures and methods to support expiration
policies parameters.
* Added documentation to `Prebuilt workspaces` page
* Update `terraform-provider-coder` to version 2.5.0:
https://github.com/coder/terraform-provider-coder/releases/tag/v2.5.0

Depends on: coder/terraform-provider-coder#404
Fixes: #17916
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant