Skip to content

Commit 34d9c5e

Browse files
authored
list: add timeouts for list (#197)
* add timeouts for list * bump go.mod
1 parent 54894bc commit 34d9c5e

File tree

6 files changed

+748
-9
lines changed

6 files changed

+748
-9
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ toolchain go1.23.7
66

77
require (
88
github.com/google/go-cmp v0.7.0
9-
github.com/hashicorp/terraform-plugin-framework v1.15.1
10-
github.com/hashicorp/terraform-plugin-go v0.28.0
9+
github.com/hashicorp/terraform-plugin-framework v1.16.0-beta.1.0.20250812160436-e3cf75ae63ec
10+
github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1
1111
github.com/hashicorp/terraform-plugin-log v0.9.0
1212
)
1313

@@ -19,5 +19,5 @@ require (
1919
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
2020
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
2121
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
22-
golang.org/x/sys v0.32.0 // indirect
22+
golang.org/x/sys v0.33.0 // indirect
2323
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
77
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
88
github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
99
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
10-
github.com/hashicorp/terraform-plugin-framework v1.15.1 h1:2mKDkwb8rlx/tvJTlIcpw0ykcmvdWv+4gY3SIgk8Pq8=
11-
github.com/hashicorp/terraform-plugin-framework v1.15.1/go.mod h1:hxrNI/GY32KPISpWqlCoTLM9JZsGH3CyYlir09bD/fI=
12-
github.com/hashicorp/terraform-plugin-go v0.28.0 h1:zJmu2UDwhVN0J+J20RE5huiF3XXlTYVIleaevHZgKPA=
13-
github.com/hashicorp/terraform-plugin-go v0.28.0/go.mod h1:FDa2Bb3uumkTGSkTFpWSOwWJDwA7bf3vdP3ltLDTH6o=
10+
github.com/hashicorp/terraform-plugin-framework v1.16.0-beta.1.0.20250812160436-e3cf75ae63ec h1:MoRO3dd5Q1zgRMTDdL7CaJHDdGXzO4IIiUYe14VBNRU=
11+
github.com/hashicorp/terraform-plugin-framework v1.16.0-beta.1.0.20250812160436-e3cf75ae63ec/go.mod h1:XQfoA+oS1ETMuQrcM689/TWMx9leV59N7Xscm5t7b+g=
12+
github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1 h1:xeHlRQYev3iMXwX2W7+D1bSfLRBs9jojZXqE6hmNxMI=
13+
github.com/hashicorp/terraform-plugin-go v0.29.0-beta.1/go.mod h1:5pww/UULn9C2tItq6o5sbScEkJxBUt9X9kI4DkeRsIw=
1414
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
1515
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
1616
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
@@ -37,8 +37,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
3737
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3838
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3939
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
40-
golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20=
41-
golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
40+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
41+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
4242
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4343
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4444
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

list/timeouts/schema.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package timeouts
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
10+
"github.com/hashicorp/terraform-plugin-framework/list/schema"
11+
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
12+
"github.com/hashicorp/terraform-plugin-framework/types"
13+
14+
"github.com/hashicorp/terraform-plugin-framework-timeouts/internal/validators"
15+
)
16+
17+
const (
18+
attributeNameList = "list"
19+
)
20+
21+
// Opts is used as an argument to BlockWithOpts and AttributesWithOpts to indicate
22+
// whether supplied descriptions should override default descriptions.
23+
type Opts struct {
24+
ListDescription string
25+
}
26+
27+
// BlockWithOpts returns a schema.Block containing attributes for `Open`, which is
28+
// defined as types.StringType and optional. A validator is used to verify
29+
// that the value assigned to `Open` can be parsed as time.Duration. The supplied
30+
// Opts are used to override defaults.
31+
func BlockWithOpts(ctx context.Context, opts Opts) schema.Block {
32+
return schema.SingleNestedBlock{
33+
Attributes: attributesMap(opts),
34+
CustomType: Type{
35+
ObjectType: types.ObjectType{
36+
AttrTypes: attrTypesMap(),
37+
},
38+
},
39+
}
40+
}
41+
42+
// Block returns a schema.Block containing attributes for `Open`, which is
43+
// defined as types.StringType and optional. A validator is used to verify
44+
// that the value assigned to `Open` can be parsed as time.Duration.
45+
func Block(ctx context.Context) schema.Block {
46+
return schema.SingleNestedBlock{
47+
Attributes: attributesMap(Opts{}),
48+
CustomType: Type{
49+
ObjectType: types.ObjectType{
50+
AttrTypes: attrTypesMap(),
51+
},
52+
},
53+
}
54+
}
55+
56+
// AttributesWithOpts returns a schema.SingleNestedAttribute which contains an
57+
// attribute for `Open`, which is defined as types.StringType and optional.
58+
// A validator is used to verify that the value assigned to an attribute
59+
// can be parsed as time.Duration. The supplied Opts are used to override defaults.
60+
func AttributesWithOpts(ctx context.Context, opts Opts) schema.Attribute {
61+
return schema.SingleNestedAttribute{
62+
Attributes: attributesMap(opts),
63+
CustomType: Type{
64+
ObjectType: types.ObjectType{
65+
AttrTypes: attrTypesMap(),
66+
},
67+
},
68+
Optional: true,
69+
}
70+
}
71+
72+
// Attributes returns a schema.SingleNestedAttribute which contains an
73+
// attribute for `Open`, which is defined as types.StringType and optional.
74+
// A validator is used to verify that the value assigned to an attribute
75+
// can be parsed as time.Duration.
76+
func Attributes(ctx context.Context) schema.Attribute {
77+
return schema.SingleNestedAttribute{
78+
Attributes: attributesMap(Opts{}),
79+
CustomType: Type{
80+
ObjectType: types.ObjectType{
81+
AttrTypes: attrTypesMap(),
82+
},
83+
},
84+
Optional: true,
85+
}
86+
}
87+
88+
func attributesMap(opts Opts) map[string]schema.Attribute {
89+
attribute := schema.StringAttribute{
90+
Optional: true,
91+
Description: `A string that can be [parsed as a duration](https://pkg.go.dev/time#ParseDuration) ` +
92+
`consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are ` +
93+
`"s" (seconds), "m" (minutes), "h" (hours).`,
94+
Validators: []validator.String{
95+
validators.TimeDuration(),
96+
},
97+
}
98+
99+
if opts.ListDescription != "" {
100+
attribute.Description = opts.ListDescription
101+
}
102+
103+
return map[string]schema.Attribute{
104+
attributeNameList: attribute,
105+
}
106+
}
107+
108+
func attrTypesMap() map[string]attr.Type {
109+
return map[string]attr.Type{
110+
attributeNameList: types.StringType,
111+
}
112+
}

0 commit comments

Comments
 (0)