Skip to content
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
4 changes: 2 additions & 2 deletions provider/workspace_preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func workspacePresetDataSource() *schema.Resource {
Description: "Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.",
Required: true,
ForceNew: true,
// Ensure TTL is between 0 and 31536000 seconds (1 year) to prevent stale prebuilds
ValidateFunc: validation.IntBetween(0, 31536000),
// Ensure TTL is between 3600 seconds (1 hour) and 31536000 seconds (1 year)
ValidateFunc: validation.IntBetween(3600, 31536000),
},
},
},
Expand Down
19 changes: 18 additions & 1 deletion provider/workspace_preset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ func TestWorkspacePreset(t *testing.T) {
return nil
},
},
{
Name: "Prebuilds block with expiration_policy.ttl set to 30 minutes (below 1 hour limit)",
Config: `
data "coder_workspace_preset" "preset_1" {
name = "preset_1"
parameters = {
"region" = "us-east1-a"
}
prebuilds {
instances = 1
expiration_policy {
ttl = 1800
}
}
}`,
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(3600 - 31536000\), got 1800`),
},
{
Name: "Prebuilds block with expiration_policy.ttl set to 2 years (exceeds 1 year limit)",
Config: `
Expand All @@ -201,7 +218,7 @@ func TestWorkspacePreset(t *testing.T) {
}
}
}`,
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(0 - 31536000\), got 63072000`),
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(3600 - 31536000\), got 63072000`),
},
{
Name: "Prebuilds is set with a expiration_policy field with its required fields and an unexpected argument",
Expand Down
Loading