Skip to content

Commit daf4bbb

Browse files
authored
Merge pull request #35 from skirsten/use-default-for-null
Fix `invalid duration ""`: Use default for null
2 parents 91b9184 + b30d1ee commit daf4bbb

File tree

6 files changed

+152
-0
lines changed

6 files changed

+152
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'datasource/timeouts: Use default for null and unknown ([#35](https://github.com/hashicorp/terraform-plugin-framework-timeouts/pull/35)).'
3+
time: 2023-02-10T17:58:32.928723089+01:00
4+
custom:
5+
Issue: "35"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'resource/timeouts: Use default for null and unknown ([#35](https://github.com/hashicorp/terraform-plugin-framework-timeouts/pull/35)).'
3+
time: 2023-02-10T17:58:52.979389154+01:00
4+
custom:
5+
Issue: "35"

datasource/timeouts/timeouts.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ func (t Value) getTimeout(ctx context.Context, timeoutName string, defaultTimeou
8989
return defaultTimeout, diags
9090
}
9191

92+
if value.IsNull() || value.IsUnknown() {
93+
tflog.Info(ctx, timeoutName+" timeout configuration is null or unknown, using provided default")
94+
95+
return defaultTimeout, diags
96+
}
97+
9298
// No type assertion check is required as the schema guarantees that the object attributes
9399
// are types.String.
94100
timeout, err := time.ParseDuration(value.(types.String).ValueString())

datasource/timeouts/timeouts_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,32 @@ func TestTimeoutsValueRead(t *testing.T) {
165165
},
166166
expectedTimeout: 20 * time.Minute,
167167
},
168+
"read-null": {
169+
timeoutsValue: timeouts.Value{
170+
Object: types.ObjectValueMust(
171+
map[string]attr.Type{
172+
"read": types.StringType,
173+
},
174+
map[string]attr.Value{
175+
"read": types.StringNull(),
176+
},
177+
),
178+
},
179+
expectedTimeout: 20 * time.Minute,
180+
},
181+
"read-unknown": {
182+
timeoutsValue: timeouts.Value{
183+
Object: types.ObjectValueMust(
184+
map[string]attr.Type{
185+
"read": types.StringType,
186+
},
187+
map[string]attr.Value{
188+
"read": types.StringUnknown(),
189+
},
190+
),
191+
},
192+
expectedTimeout: 20 * time.Minute,
193+
},
168194
"read-not-parseable-as-time-duration": {
169195
timeoutsValue: timeouts.Value{
170196
Object: types.ObjectValueMust(

resource/timeouts/timeouts.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ func (t Value) getTimeout(ctx context.Context, timeoutName string, defaultTimeou
107107
return defaultTimeout, diags
108108
}
109109

110+
if value.IsNull() || value.IsUnknown() {
111+
tflog.Info(ctx, timeoutName+" timeout configuration is null or unknown, using provided default")
112+
113+
return defaultTimeout, diags
114+
}
115+
110116
// No type assertion check is required as the schema guarantees that the object attributes
111117
// are types.String.
112118
timeout, err := time.ParseDuration(value.(types.String).ValueString())

resource/timeouts/timeouts_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,32 @@ func TestTimeoutsValueCreate(t *testing.T) {
180180
},
181181
expectedTimeout: 20 * time.Minute,
182182
},
183+
"create-null": {
184+
timeoutsValue: timeouts.Value{
185+
Object: types.ObjectValueMust(
186+
map[string]attr.Type{
187+
"create": types.StringType,
188+
},
189+
map[string]attr.Value{
190+
"create": types.StringNull(),
191+
},
192+
),
193+
},
194+
expectedTimeout: 20 * time.Minute,
195+
},
196+
"create-unknown": {
197+
timeoutsValue: timeouts.Value{
198+
Object: types.ObjectValueMust(
199+
map[string]attr.Type{
200+
"create": types.StringType,
201+
},
202+
map[string]attr.Value{
203+
"create": types.StringUnknown(),
204+
},
205+
),
206+
},
207+
expectedTimeout: 20 * time.Minute,
208+
},
183209
"create-not-parseable-as-time-duration": {
184210
timeoutsValue: timeouts.Value{
185211
Object: types.ObjectValueMust(
@@ -248,6 +274,32 @@ func TestTimeoutsValueRead(t *testing.T) {
248274
},
249275
expectedTimeout: 20 * time.Minute,
250276
},
277+
"read-null": {
278+
timeoutsValue: timeouts.Value{
279+
Object: types.ObjectValueMust(
280+
map[string]attr.Type{
281+
"read": types.StringType,
282+
},
283+
map[string]attr.Value{
284+
"read": types.StringNull(),
285+
},
286+
),
287+
},
288+
expectedTimeout: 20 * time.Minute,
289+
},
290+
"read-unknown": {
291+
timeoutsValue: timeouts.Value{
292+
Object: types.ObjectValueMust(
293+
map[string]attr.Type{
294+
"read": types.StringType,
295+
},
296+
map[string]attr.Value{
297+
"read": types.StringUnknown(),
298+
},
299+
),
300+
},
301+
expectedTimeout: 20 * time.Minute,
302+
},
251303
"read-not-parseable-as-time-duration": {
252304
timeoutsValue: timeouts.Value{
253305
Object: types.ObjectValueMust(
@@ -316,6 +368,32 @@ func TestTimeoutsValueUpdate(t *testing.T) {
316368
},
317369
expectedTimeout: 20 * time.Minute,
318370
},
371+
"update-null": {
372+
timeoutsValue: timeouts.Value{
373+
Object: types.ObjectValueMust(
374+
map[string]attr.Type{
375+
"update": types.StringType,
376+
},
377+
map[string]attr.Value{
378+
"update": types.StringNull(),
379+
},
380+
),
381+
},
382+
expectedTimeout: 20 * time.Minute,
383+
},
384+
"update-unknown": {
385+
timeoutsValue: timeouts.Value{
386+
Object: types.ObjectValueMust(
387+
map[string]attr.Type{
388+
"update": types.StringType,
389+
},
390+
map[string]attr.Value{
391+
"update": types.StringUnknown(),
392+
},
393+
),
394+
},
395+
expectedTimeout: 20 * time.Minute,
396+
},
319397
"update-not-parseable-as-time-duration": {
320398
timeoutsValue: timeouts.Value{
321399
Object: types.ObjectValueMust(
@@ -384,6 +462,32 @@ func TestTimeoutsValueDelete(t *testing.T) {
384462
},
385463
expectedTimeout: 20 * time.Minute,
386464
},
465+
"delete-null": {
466+
timeoutsValue: timeouts.Value{
467+
Object: types.ObjectValueMust(
468+
map[string]attr.Type{
469+
"delete": types.StringType,
470+
},
471+
map[string]attr.Value{
472+
"delete": types.StringNull(),
473+
},
474+
),
475+
},
476+
expectedTimeout: 20 * time.Minute,
477+
},
478+
"delete-unknown": {
479+
timeoutsValue: timeouts.Value{
480+
Object: types.ObjectValueMust(
481+
map[string]attr.Type{
482+
"delete": types.StringType,
483+
},
484+
map[string]attr.Value{
485+
"delete": types.StringUnknown(),
486+
},
487+
),
488+
},
489+
expectedTimeout: 20 * time.Minute,
490+
},
387491
"delete-not-parseable-as-time-duration": {
388492
timeoutsValue: timeouts.Value{
389493
Object: types.ObjectValueMust(

0 commit comments

Comments
 (0)