Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add minimum TTL value for expiration.policy.ttl#406

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
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
14 changes: 12 additions & 2 deletionsprovider/workspace_preset.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,7 @@ package provider

import (
"context"
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand DownExpand Up@@ -103,8 +104,17 @@ 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 either 0 (to disable expiration) or between 3600 seconds (1 hour) and 31536000 seconds (1 year)
ValidateFunc: func(val interface{}, key string) ([]string, []error) {
v := val.(int)
if v == 0 {
return nil, nil
}
if v < 3600 || v > 31536000 {
return nil, []error{fmt.Errorf("%q must be 0 or between 3600 and 31536000, got %d", key, v)}
}
return nil, nil
},
},
},
},
Expand Down
48 changes: 46 additions & 2 deletionsprovider/workspace_preset_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -157,7 +157,7 @@ func TestWorkspacePreset(t *testing.T) {
expiration_policy {}
}
}`,
ExpectError: regexp.MustCompile("The argument\"ttl\" is required, but no definition was found."),
ExpectError: regexp.MustCompile(`The argument "ttl" is required, but no definition was found.`),
},
{
Name: "Prebuilds is set with a expiration_policy field with its required fields",
Expand DownExpand Up@@ -186,6 +186,50 @@ func TestWorkspacePreset(t *testing.T) {
return nil
},
},
{
Name: "Prebuilds block with expiration_policy.ttl set to 0 seconds (disables expiration)",
Config: `
data "coder_workspace_preset" "preset_1" {
name = "preset_1"
parameters = {
"region" = "us-east1-a"
}
prebuilds {
instances = 1
expiration_policy {
ttl = 0
}
}
}`,
ExpectError: nil,
Check: func(state *terraform.State) error {
require.Len(t, state.Modules, 1)
require.Len(t, state.Modules[0].Resources, 1)
resource := state.Modules[0].Resources["data.coder_workspace_preset.preset_1"]
require.NotNil(t, resource)
attrs := resource.Primary.Attributes
require.Equal(t, attrs["name"], "preset_1")
require.Equal(t, attrs["prebuilds.0.expiration_policy.0.ttl"], "0")
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(`"prebuilds.0.expiration_policy.0.ttl" must be 0 or between 3600 and 31536000, got 1800`),
},
{
Name: "Prebuilds block with expiration_policy.ttl set to 2 years (exceeds 1 year limit)",
Config: `
Expand All@@ -201,7 +245,7 @@ func TestWorkspacePreset(t *testing.T) {
}
}
}`,
ExpectError: regexp.MustCompile(`expectedprebuilds.0.expiration_policy.0.ttl to bein the range \(0 - 31536000\), got 63072000`),
ExpectError: regexp.MustCompile(`"prebuilds.0.expiration_policy.0.ttl" must be0 or between 3600 and 31536000, got 63072000`),
},
{
Name: "Prebuilds is set with a expiration_policy field with its required fields and an unexpected argument",
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp