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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add max validation of 604800 seconds (7 days) for invalidate_a…
…fter_secs to prevent stale prebuilds
  • Loading branch information
ssncferreira committed May 23, 2025
commit 1ae84e8533d6fa108d6d394ebe819263ff268ec4
11 changes: 6 additions & 5 deletions provider/workspace_preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ func workspacePresetDataSource() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"invalidate_after_secs": {
Type: schema.TypeInt,
Description: "Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.",
Required: true,
ForceNew: true,
ValidateFunc: validation.IntAtLeast(0),
Type: schema.TypeInt,
Description: "Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.",
Required: true,
ForceNew: true,
// Ensure invalidation is between 0 and 604800 seconds (7 days) to prevent stale prebuilds
ValidateFunc: validation.IntBetween(0, 604800),
},
},
},
Expand Down
17 changes: 17 additions & 0 deletions provider/workspace_preset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@ func TestWorkspacePreset(t *testing.T) {
return nil
},
},
{
Name: "Prebuilds block with cache_invalidation.invalidate_after_secs set to 15 days (exceeds 7 days limit)",
Config: `
data "coder_workspace_preset" "preset_1" {
name = "preset_1"
parameters = {
"region" = "us-east1-a"
}
prebuilds {
instances = 1
cache_invalidation {
invalidate_after_secs = 1296000
}
}
}`,
ExpectError: regexp.MustCompile(`expected prebuilds.0.cache_invalidation.0.invalidate_after_secs to be in the range \(0 - 604800\), got 1296000`),
},
{
Name: "Prebuilds is set with a cache_invalidation field with its required fields and an unexpected argument",
Config: `
Expand Down
Loading