Skip to content

Commit 1bafa3a

Browse files
committed
chore: add minimum TTL value for expiration.policy.ttl
1 parent 28dae7f commit 1bafa3a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

provider/workspace_preset.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ func workspacePresetDataSource() *schema.Resource {
103103
Description: "Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.",
104104
Required: true,
105105
ForceNew: true,
106-
// Ensure TTL is between 0 and 31536000 seconds (1 year) to prevent stale prebuilds
107-
ValidateFunc: validation.IntBetween(0, 31536000),
106+
// Ensure TTL is between 3600 seconds (1 hour) and 31536000 seconds (1 year)
107+
ValidateFunc: validation.IntBetween(3600, 31536000),
108108
},
109109
},
110110
},

provider/workspace_preset_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,23 @@ func TestWorkspacePreset(t *testing.T) {
186186
return nil
187187
},
188188
},
189+
{
190+
Name: "Prebuilds block with expiration_policy.ttl set to 30 minutes (below 1 hour limit)",
191+
Config: `
192+
data "coder_workspace_preset" "preset_1" {
193+
name = "preset_1"
194+
parameters = {
195+
"region" = "us-east1-a"
196+
}
197+
prebuilds {
198+
instances = 1
199+
expiration_policy {
200+
ttl = 1800
201+
}
202+
}
203+
}`,
204+
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(3600 - 31536000\), got 1800`),
205+
},
189206
{
190207
Name: "Prebuilds block with expiration_policy.ttl set to 2 years (exceeds 1 year limit)",
191208
Config: `
@@ -201,7 +218,7 @@ func TestWorkspacePreset(t *testing.T) {
201218
}
202219
}
203220
}`,
204-
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(0 - 31536000\), got 63072000`),
221+
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(3600 - 31536000\), got 63072000`),
205222
},
206223
{
207224
Name: "Prebuilds is set with a expiration_policy field with its required fields and an unexpected argument",

0 commit comments

Comments
 (0)