Skip to content

Commit 1ae84e8

Browse files
committed
chore: add max validation of 604800 seconds (7 days) for invalidate_after_secs to prevent stale prebuilds
1 parent 1c1ea40 commit 1ae84e8

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

provider/workspace_preset.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ func workspacePresetDataSource() *schema.Resource {
9999
Elem: &schema.Resource{
100100
Schema: map[string]*schema.Schema{
101101
"invalidate_after_secs": {
102-
Type: schema.TypeInt,
103-
Description: "Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.",
104-
Required: true,
105-
ForceNew: true,
106-
ValidateFunc: validation.IntAtLeast(0),
102+
Type: schema.TypeInt,
103+
Description: "Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.",
104+
Required: true,
105+
ForceNew: true,
106+
// Ensure invalidation is between 0 and 604800 seconds (7 days) to prevent stale prebuilds
107+
ValidateFunc: validation.IntBetween(0, 604800),
107108
},
108109
},
109110
},

provider/workspace_preset_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,23 @@ func TestWorkspacePreset(t *testing.T) {
189189
return nil
190190
},
191191
},
192+
{
193+
Name: "Prebuilds block with cache_invalidation.invalidate_after_secs set to 15 days (exceeds 7 days limit)",
194+
Config: `
195+
data "coder_workspace_preset" "preset_1" {
196+
name = "preset_1"
197+
parameters = {
198+
"region" = "us-east1-a"
199+
}
200+
prebuilds {
201+
instances = 1
202+
cache_invalidation {
203+
invalidate_after_secs = 1296000
204+
}
205+
}
206+
}`,
207+
ExpectError: regexp.MustCompile(`expected prebuilds.0.cache_invalidation.0.invalidate_after_secs to be in the range \(0 - 604800\), got 1296000`),
208+
},
192209
{
193210
Name: "Prebuilds is set with a cache_invalidation field with its required fields and an unexpected argument",
194211
Config: `

0 commit comments

Comments
 (0)