8000 chores: update terraform schema to expiration_policy.ttl & update max… · coder/terraform-provider-coder@2a34f0d · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a34f0d

Browse files
committed
chores: update terraform schema to expiration_policy.ttl & update max validation ttl value to 1 year
1 parent 1ae84e8 commit 2a34f0d

File tree

5 files changed

+35
-38
lines changed

5 files changed

+35
-38
lines changed

docs/data-sources/workspace_preset.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ Required:
5454

5555
Optional:
5656

57-
- `cache_invalidation` (Block Set, Max: 1) Configuration block that defines TTL (time-to-live) behavior for prebuilds. Use this to automatically invalidate and delete prebuilds after a certain period, ensuring they stay up-to-date. (see [below for nested schema](#nestedblock--prebuilds--cache_invalidation))
57+
- `expiration_policy` (Block Set, Max: 1) Configuration block that defines TTL (time-to-live) behavior for prebuilds. Use this to automatically invalidate and delete prebuilds after a certain period, ensuring they stay up-to-date. (see [below for nested schema](#nestedblock--prebuilds--expiration_policy))
5858

59-
<a id="nestedblock--prebuilds--cache_invalidation"></a>
60-
### Nested Schema for `prebuilds.cache_invalidation`
59+
<a id="nestedblock--prebuilds--expiration_policy"></a>
60+
### Nested Schema for `prebuilds.expiration_policy`
6161

6262
Required:
6363

64-
- `invalidate_after_secs` (Number) Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.
64+
- `ttl` (Number) Time in seconds after which an unclaimed prebuild is considered expired and eligible for cleanup.

integration/integration_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ func TestIntegration(t *testing.T) {
9090
// TODO (sasswart): the cli doesn't support presets yet.
9191
// once it does, the value for workspace_parameter.value
9292
// will be the preset value.
93-
"workspace_parameter.value": `param value`,
94-
"workspace_parameter.icon": `param icon`,
95-
"workspace_preset.name": `preset`,
96-
"workspace_preset.parameters.param": `preset param value`,
97-
"workspace_preset.prebuilds.instances": `1`,
98-
"workspace_preset.prebuilds.cache_invalidation.invalidate_after_secs": `86400`,
93+
"workspace_parameter.value": `param value`,
94+
"workspace_parameter.icon": `param icon`,
95+
"workspace_preset.name": `preset`,
96+
"workspace_preset.parameters.param": `preset param value`,
97+
"workspace_preset.prebuilds.instances": `1`,
98+
"workspace_preset.prebuilds.expiration_policy.ttl": `86400`,
9999
},
100100
},
101101
{

integration/test-data-source/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ data "coder_workspace_preset" "preset" {
2727

2828
prebuilds {
2929
instances = 1
30-
cache_invalidation {
31-
invalidate_after_secs = 86400
30+
expiration_policy {
31+
ttl = 86400
3232
}
3333
}
3434
}
@@ -55,7 +55,7 @@ locals {
5555
"workspace_preset.name" : data.coder_workspace_preset.preset.name,
5656
"workspace_preset.parameters.param" : data.coder_workspace_preset.preset.parameters.param,
5757
"workspace_preset.prebuilds.instances" : tostring(one(data.coder_workspace_preset.preset.prebuilds).instances),
58-
"workspace_preset.prebuilds.cache_invalidation.invalidate_after_secs" : tostring(one(one(data.coder_workspace_preset.preset.prebuilds).cache_invalidation).invalidate_after_secs),
58+
"workspace_preset.prebuilds.expiration_policy.ttl" : tostring(one(one(data.coder_workspace_preset.preset.prebuilds).expiration_policy).ttl),
5959
}
6060
}
6161

provider/workspace_preset.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ type WorkspacePreset struct {
2222

2323
type WorkspacePrebuild struct {
2424
Instances int `mapstructure:"instances"`
25-
// There should always be only one cache_invalidation block, but Terraform's type system
25+
// There should always be only one expiration_policy block, but Terraform's type system
2626
// still parses them as a slice, so we need to handle it as such. We could use
2727
// an anonymous type and rd.Get to avoid a slice here, but that would not be possible
2828
// for utilities that parse our terraform output using this type. To remain compatible
2929
// with those cases, we use a slice here.
30-
CacheInvalidation []CacheInvalidation `mapstructure:"cache_invalidation"`
30+
ExpirationPolicy []ExpirationPolicy `mapstructure:"expiration_policy"`
3131
}
3232

33-
type CacheInvalidation struct {
34-
InvalidateAfterSecs int `mapstructure:"invalidate_after_secs"`
33+
type ExpirationPolicy struct {
34+
TTL int `mapstructure:"ttl"`
3535
}
3636

3737
func workspacePresetDataSource() *schema.Resource {
@@ -91,20 +91,20 @@ func workspacePresetDataSource() *schema.Resource {
9191
ForceNew: true,
9292
ValidateFunc: validation.IntAtLeast(0),
9393
},
94-
"cache_invalidation": {
94+
"expiration_policy": {
9595
Type: schema.TypeSet,
9696
Description: "Configuration block that defines TTL (time-to-live) behavior for prebuilds. Use this to automatically invalidate and delete prebuilds after a certain period, ensuring they stay up-to-date.",
9797
Optional: true,
9898
MaxItems: 1,
9999
Elem: &schema.Resource{
100100
Schema: map[string]*schema.Schema{
101-
"invalidate_after_secs": {
101+
"ttl": {
102102
Type: schema.TypeInt,
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 invalidation is between 0 and 604800 seconds (7 days) to prevent stale prebuilds
107-
ValidateFunc: validation.IntBetween(0, 604800),
106+
// Ensure invalidation is between 0 and 31536000 seconds (1 year) to prevent stale prebuilds
107+
ValidateFunc: validation.IntBetween(0, 31536000),
108108
},
109109
},
110110
},

provider/workspace_preset_test.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func TestWorkspacePreset(t *testing.T) {
145145
},
146146
},
147147
{
148-
Name: "Prebuilds is set with a cache_invalidation field without its required fields",
148+
Name: "Prebuilds is set with a expiration_policy field without its required fields",
149149
Config: `
150150
data "coder_workspace_preset" "preset_1" {
151151
name = "preset_1"
@@ -154,16 +154,13 @@ func TestWorkspacePreset(t *testing.T) {
154154
}
155155
prebuilds {
156156
instances = 1
157-
cache_invalidation {}
157+
expiration_policy {}
158158
}
159159
}`,
160-
// Note: Match only the beginning of the error message to make the test more reliable.
161-
// The full error message includes formatting differences like newlines, which could
162-
// cause the test to fail unnecessarily.
163-
ExpectError: regexp.MustCompile("The argument \"invalidate_after_secs\" is required,"),
160+
ExpectError: regexp.MustCompile("The argument \"ttl\" is required, but no definition was found."),
164161
},
165162
{
166-
Name: "Prebuilds is set with a cache_invalidation field with its required fields",
163+
Name: "Prebuilds is set with a expiration_policy field with its required fields",
167164
Config: `
168165
data "coder_workspace_preset" "preset_1" {
169166
name = "preset_1"
@@ -172,8 +169,8 @@ func TestWorkspacePreset(t *testing.T) {
172169
}
173170
prebuilds {
174171
instances = 1
175-
cache_invalidation {
176-
invalidate_after_secs = 86400
172+
expiration_policy {
173+
ttl = 86400
177174
}
178175
}
179176
}`,
@@ -185,12 +182,12 @@ func TestWorkspacePreset(t *testing.T) {
185182
require.NotNil(t, resource)
186183
attrs := resource.Primary.Attributes
187184
require.Equal(t, attrs["name"], "preset_1")
188-
require.Equal(t, attrs["prebuilds.0.cache_invalidation.0.invalidate_after_secs"], "86400")
185+
require.Equal(t, attrs["prebuilds.0.expiration_policy.0.ttl"], "86400")
189186
return nil
190187
},
191188
},
192189
{
193-
Name: "Prebuilds block with cache_invalidation.invalidate_after_secs set to 15 days (exceeds 7 days limit)",
190+
Name: "Prebuilds block with expiration_policy.ttl set to 2 years (exceeds 1 year limit)",
194191
Config: `
195192
data "coder_workspace_preset" "preset_1" {
196193
name = "preset_1"
@@ -199,15 +196,15 @@ func TestWorkspacePreset(t *testing.T) {
199196
}
200197
prebuilds {
201198
instances = 1
202-
cache_invalidation {
203-
invalidate_after_secs = 1296000
199+
expiration_policy {
200+
ttl = 63072000
204201
}
205202
}
206203
}`,
207-
ExpectError: regexp.MustCompile(`expected prebuilds.0.cache_invalidation.0.invalidate_after_secs to be in the range \(0 - 604800\), got 1296000`),
204+
ExpectError: regexp.MustCompile(`expected prebuilds.0.expiration_policy.0.ttl to be in the range \(0 - 31536000\), got 63072000`),
208205
},
209206
{
210-
Name: "Prebuilds is set with a cache_invalidation field with its required fields and an unexpected argument",
207+
Name: "Prebuilds is set with a expiration_policy field with its required fields and an unexpected argument",
211208
Config: `
212209
data "coder_workspace_preset" "preset_1" {
213210
name = "preset_1"
@@ -216,8 +213,8 @@ func TestWorkspacePreset(t *testing.T) {
216213
}
217214
prebuilds {
218215
instances = 1
219-
cache_invalidation {
220-
invalidate_after_secs = 86400
216+
expiration_policy {
217+
ttl = 86400
221218
invalid_argument = "test"
222219
}
223220
}

0 commit comments

Comments
 (0)
0