Skip to content

feat: add expiration_policy parameter to prebuild resource #404

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

Merged
merged 12 commits into from
May 23, 2025

Conversation

ssncferreira
Copy link
Contributor

@ssncferreira ssncferreira commented May 22, 2025

Summary

This PR adds Terraform support for configuring a expiration_policy field in a template preset. This allows users to specify a TTL (ttl) for prebuild workspaces, after which they are considered expired and eligible for deletion and replacement.

Changes

  • Updated the Terraform template preset resource to include the new expiration_policy block.
  • Added validation and tests to ensure correct TTL handling.

Example Usage

prebuilds = {
	  instances = 2
	  expiration_policy {
		  ttl = 86400
	  }
  }

Related:

@SasSwart
Copy link
Contributor

Looks good. I'd just like to revisit the schema:

prebuilds {
	  instances = 2
	  cache_invalidation {
		  invalidate_after_secs = 86400
	  }
  }

Do we need the nested cache_invalidation block? Is it because we expect other cache invalidation related fields to eventually be added? Could we get away with the following?

prebuilds {
	  instances = 2
	  invalidate_after_secs = 86400
  }

@ssncferreira ssncferreira requested a review from mafredri May 23, 2025 10:40
@ssncferreira
Copy link
Contributor Author

Looks good. I'd just like to revisit the schema:

prebuilds {
	  instances = 2
	  cache_invalidation {
		  invalidate_after_secs = 86400
	  }
  }

Do we need the nested cache_invalidation block? Is it because we expect other cache invalidation related fields to eventually be added? Could we get away with the following?

prebuilds {
	  instances = 2
	  invalidate_after_secs = 86400
  }

I also thought about that, the nested cache_invalidation block was mainly to keep things flexible in case we want to add more expiration or invalidation-related settings down the road. For readability, I actually prefer this option, especially since if I understand correctly there’s another config coming for autoscaling. It makes sense to keep these configurations grouped per block and separated by concern. But I’m definitely open to suggestions! 🙂

One other concern I had was about the naming of cache_invalidation. Since we’re not really dealing with traditional caching but more with managing prebuild lifecycle or resource expiration, the name might be a bit misleading. Maybe something like expiration_policy would make more sense? What do you think?

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the naming/use of block, this seems good to me 👍🏻

@ssncferreira
Copy link
Contributor Author

Looks good. I'd just like to revisit the schema:

prebuilds {
	  instances = 2
	  cache_invalidation {
		  invalidate_after_secs = 86400
	  }
  }

Do we need the nested cache_invalidation block? Is it because we expect other cache invalidation related fields to eventually be added? Could we get away with the following?

prebuilds {
	  instances = 2
	  invalidate_after_secs = 86400
  }

I also thought about that, the nested cache_invalidation block was mainly to keep things flexible in case we want to add more expiration or invalidation-related settings down the road. For readability, I actually prefer this option, especially since if I understand correctly there’s another config coming for autoscaling. It makes sense to keep these configurations grouped per block and separated by concern. But I’m definitely open to suggestions! 🙂

One other concern I had was about the naming of cache_invalidation. Since we’re not really dealing with traditional caching but more with managing prebuild lifecycle or resource expiration, the name might be a bit misleading. Maybe something like expiration_policy would make more sense? What do you think?

As discussed internally, and after getting the confirmation that we'll likely introduce more expiration-related parameters in the future, the terraform schema was updated to:

prebuilds = {
  instances = 2
  expiration_policy {
    ttl = 86400
  }
}

@ssncferreira ssncferreira changed the title feat: add cache_invalidation parameter to prebuild resource feat: add expiration_policy parameter to prebuild resource May 23, 2025
@ssncferreira ssncferreira requested a review from mafredri May 23, 2025 17:11
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good and docs and test coverage seems on point, nice work! 👍🏻

@ssncferreira ssncferreira merged commit 28dae7f into main May 23, 2025
6 checks passed
@ssncferreira ssncferreira deleted the ssncferreira/feat-prebuild-cache-invalidation branch May 23, 2025 18:45
@github-actions github-actions bot locked and limited conversation to collaborators May 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants