Skip to content

Commit a7c734c

Browse files
authored
feat: support list(string) as coder_parameter (#6618)
* feat: support list(string) as coder_parameter * Fix
1 parent 7076dee commit a7c734c

File tree

9 files changed

+38
-45
lines changed

9 files changed

+38
-45
lines changed

coderd/apidoc/docs.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/workspacebuilds_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,16 @@ func TestWorkspaceBuildValidateRichParameters(t *testing.T) {
793793

794794
boolParameterName = "bool_parameter"
795795
boolParameterValue = "true"
796+
797+
listOfStringsParameterName = "list_of_strings_parameter"
798+
listOfStringsParameterValue = `["a","b","c"]`
796799
)
797800

798801
initialBuildParameters := []codersdk.WorkspaceBuildParameter{
799802
{Name: stringParameterName, Value: stringParameterValue},
800803
{Name: numberParameterName, Value: numberParameterValue},
801804
{Name: boolParameterName, Value: boolParameterValue},
805+
{Name: listOfStringsParameterName, Value: listOfStringsParameterValue},
802806
}
803807

804808
prepareEchoResponses := func(richParameters []*proto.RichParameter) *echo.Responses {
@@ -902,6 +906,10 @@ func TestWorkspaceBuildValidateRichParameters(t *testing.T) {
902906
{Name: boolParameterName, Type: "bool", Mutable: true},
903907
}
904908

909+
listOfStringsRichParameters := []*proto.RichParameter{
910+
{Name: listOfStringsParameterName, Type: "list(string)", Mutable: true},
911+
}
912+
905913
tests := []struct {
906914
parameterName string
907915
value string
@@ -930,6 +938,11 @@ func TestWorkspaceBuildValidateRichParameters(t *testing.T) {
930938
{boolParameterName, "true", true, boolRichParameters},
931939
{boolParameterName, "false", true, boolRichParameters},
932940
{boolParameterName, "cat", false, boolRichParameters},
941+
942+
{listOfStringsParameterName, `[]`, true, listOfStringsRichParameters},
943+
{listOfStringsParameterName, `["aa"]`, true, listOfStringsRichParameters},
944+
{listOfStringsParameterName, `["aa]`, false, listOfStringsRichParameters},
945+
{listOfStringsParameterName, ``, false, listOfStringsRichParameters},
933946
}
934947

935948
for _, tc := range tests {

codersdk/richparameters.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,6 @@ func validationEnabled(param TemplateVersionParameter) bool {
113113
return len(param.ValidationRegex) > 0 ||
114114
(param.ValidationMin != 0 && param.ValidationMax != 0) ||
115115
len(param.ValidationMonotonic) > 0 ||
116-
param.Type == "bool" // boolean type doesn't have any custom validation rules, but the value must be checked (true/false).
116+
param.Type == "bool" || // boolean type doesn't have any custom validation rules, but the value must be checked (true/false).
117+
param.Type == "list(string)" // list(string) type doesn't have special validation, but we need to check if this is a correct list.
117118
}

codersdk/templateversions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type TemplateVersionParameter struct {
4343
Name string `json:"name"`
4444
Description string `json:"description"`
4545
DescriptionPlaintext string `json:"description_plaintext"`
46-
Type string `json:"type" enums:"string,number,bool"`
46+
Type string `json:"type" enums:"string,number,bool,list(string)"`
4747
Mutable bool `json:"mutable"`
4848
DefaultValue string `json:"default_value"`
4949
Icon string `json:"icon"`

docs/api/schemas.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3777,13 +3777,14 @@ Parameter represents a set value for the scope.
37773777

37783778
#### Enumerated Values
37793779

3780-
| Property | Value |
3781-
| ---------------------- | ------------ |
3782-
| `type` | `string` |
3783-
| `type` | `number` |
3784-
| `type` | `bool` |
3785-
| `validation_monotonic` | `increasing` |
3786-
| `validation_monotonic` | `decreasing` |
3780+
| Property | Value |
3781+
| ---------------------- | -------------- |
3782+
| `type` | `string` |
3783+
| `type` | `number` |
3784+
| `type` | `bool` |
3785+
| `type` | `list(string)` |
3786+
| `validation_monotonic` | `increasing` |
3787+
| `validation_monotonic` | `decreasing` |
37873788

37883789
## codersdk.TemplateVersionParameterOption
37893790

docs/api/templates.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,13 +2266,14 @@ Status Code **200**
22662266

22672267
#### Enumerated Values
22682268

2269-
| Property | Value |
2270-
| ---------------------- | ------------ |
2271-
| `type` | `string` |
2272-
| `type` | `number` |
2273-
| `type` | `bool` |
2274-
| `validation_monotonic` | `increasing` |
2275-
| `validation_monotonic` | `decreasing` |
2269+
| Property | Value |
2270+
| ---------------------- | -------------- |
2271+
| `type` | `string` |
2272+
| `type` | `number` |
2273+
| `type` | `bool` |
2274+
| `type` | `list(string)` |
2275+
| `validation_monotonic` | `increasing` |
2276+
| `validation_monotonic` | `decreasing` |
22762277

22772278
To perform this operation, you must be authenticated. [Learn more](authentication.md).
22782279

go.mod

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ require (
7575
github.com/codeclysm/extract v2.2.0+incompatible
7676
github.com/coder/flog v1.0.0
7777
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d
78-
github.com/coder/terraform-provider-coder v0.6.17
78+
github.com/coder/terraform-provider-coder v0.6.20
7979
github.com/coreos/go-oidc/v3 v3.4.0
8080
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
8181
github.com/creack/pty v1.1.18
@@ -183,17 +183,13 @@ require (
183183
github.com/dustin/go-humanize v1.0.1 // indirect
184184
github.com/google/flatbuffers v23.1.21+incompatible // indirect
185185
github.com/h2non/filetype v1.1.3 // indirect
186-
github.com/hashicorp/go-plugin v1.4.4 // indirect
187-
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c // indirect
188-
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect
189186
github.com/json-iterator/go v1.1.12 // indirect
190187
github.com/juju/errors v1.0.0 // indirect
191188
github.com/mattn/go-localereader v0.0.1 // indirect
192189
github.com/mattn/go-sqlite3 v1.14.15 // indirect
193190
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
194191
github.com/modern-go/reflect2 v1.0.2 // indirect
195192
github.com/muesli/cancelreader v0.2.2 // indirect
196-
github.com/oklog/run v1.0.0 // indirect
197193
)
198194

199195
require (

go.sum

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,10 @@ github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d h1:09JG37IgTB6n3ouX9
376376
github.com/coder/retry v1.3.1-0.20230210155434-e90a2e1e091d/go.mod h1:r+1J5i/989wt6CUeNSuvFKKA9hHuKKPMxdzDbTuvwwk=
377377
github.com/coder/ssh v0.0.0-20220811105153-fcea99919338 h1:tN5GKFT68YLVzJoA8AHuiMNJ0qlhoD3pGN3JY9gxSko=
378378
github.com/coder/ssh v0.0.0-20220811105153-fcea99919338/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
379-
github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949 h1:8WfMfRTDaEpnmhCJWfFQ7JHz19GyP+EgFgLGu5ngdek=
380-
github.com/coder/tailscale v1.1.1-0.20230307022319-1e5e724a3949/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
381-
github.com/coder/tailscale v1.1.1-0.20230313184322-307d4b9ef4e1 h1:kOh+1rBcbahdodSiNBioO4g47m3Ef8CagNEX8U7/RyY=
382-
github.com/coder/tailscale v1.1.1-0.20230313184322-307d4b9ef4e1/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
383-
github.com/coder/tailscale v1.1.1-0.20230313192237-8d691a009b20 h1:FFPv3xLsAT+n8chkePxB/VwqFwn4NL8GV8Lk97efUP0=
384-
github.com/coder/tailscale v1.1.1-0.20230313192237-8d691a009b20/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
385-
github.com/coder/tailscale v1.1.1-0.20230313194848-e281f646c460 h1:WYnHzxQ1DsgDYyyS6i8tgdpjiwS1LrXJjwXcOVkU/3g=
386-
github.com/coder/tailscale v1.1.1-0.20230313194848-e281f646c460/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
387-
github.com/coder/tailscale v1.1.1-0.20230313195101-c6534848756b h1:3xWbBCpQ+CqVP2Myh1YhCw8cJbMi6mjkDl4/x6YkiUw=
388-
github.com/coder/tailscale v1.1.1-0.20230313195101-c6534848756b/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
389-
github.com/coder/tailscale v1.1.1-0.20230314021518-0cda9db154be h1:b0ZTDPpV/fAdkuS/V59cawnq+5vcXzkvXPMG/eZcRx0=
390-
github.com/coder/tailscale v1.1.1-0.20230314021518-0cda9db154be/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
391379
github.com/coder/tailscale v1.1.1-0.20230314023417-d9efcc0ac972 h1:193YGsJz8hc4yxqAclE36paKl+9CQ6KGLgdleIguCVE=
392380
github.com/coder/tailscale v1.1.1-0.20230314023417-d9efcc0ac972/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
393-
github.com/coder/terraform-provider-coder v0.6.15 h1:Llvh4RwxSQ/goy7ToTOeHf3tdEz+79qbyOh61hNnJs0=
394-
github.com/coder/terraform-provider-coder v0.6.15/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
395-
github.com/coder/terraform-provider-coder v0.6.17 h1:YvjM5nQx5RO+gXsYIv++CkiWCuJueQdJaPrsjnkZ4XQ=
396-
github.com/coder/terraform-provider-coder v0.6.17/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
381+
github.com/coder/terraform-provider-coder v0.6.20 h1:bVyITX9JlbnGzKzTj0qi/JziUCGqD2DiN3cXaWyDcxE=
382+
github.com/coder/terraform-provider-coder v0.6.20/go.mod h1:UIfU3bYNeSzJJvHyJ30tEKjD6Z9utloI+HUM/7n94CY=
397383
github.com/containerd/aufs v0.0.0-20200908144142-dab0cbea06f4/go.mod h1:nukgQABAEopAHvB6j7cnP5zJ+/3aVcE7hCYqvIwAHyE=
398384
github.com/containerd/aufs v0.0.0-20201003224125-76a6863f2989/go.mod h1:AkGGQs9NM2vtYHaUen+NljV0/baGCAPELGm2q9ZXpWU=
399385
github.com/containerd/aufs v0.0.0-20210316121734-20793ff83c97/go.mod h1:kL5kd6KM5TzQjR79jljyi4olc1Vrx6XBlcyj3gNv2PU=
@@ -1039,7 +1025,6 @@ github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+
10391025
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
10401026
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
10411027
github.com/hashicorp/go-plugin v1.4.4 h1:NVdrSdFRt3SkZtNckJ6tog7gbpRrcbOjQi/rgF7JYWQ=
1042-
github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
10431028
github.com/hashicorp/go-reap v0.0.0-20170704170343-bf58d8a43e7b h1:3GrpnZQBxcMj1gCXQLelfjCT1D5MPGTuGMKHVzSIH6A=
10441029
github.com/hashicorp/go-reap v0.0.0-20170704170343-bf58d8a43e7b/go.mod h1:qIFzeFcJU3OIFk/7JreWXcUjFmcCaeHTH9KoNyHYVCs=
10451030
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
@@ -1050,7 +1035,6 @@ github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/b
10501035
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
10511036
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
10521037
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
1053-
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
10541038
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
10551039
github.com/hashicorp/go-version v1.5.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
10561040
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
@@ -1087,9 +1071,7 @@ github.com/hashicorp/terraform-plugin-log v0.7.0/go.mod h1:p4R1jWBXRTvL4odmEkFfD
10871071
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0 h1:+KxZULPsbjpAVoP0WNj/8aVW6EqpcX5JcUcQ5wl7Da4=
10881072
github.com/hashicorp/terraform-plugin-sdk/v2 v2.20.0/go.mod h1:DwGJG3KNxIPluVk6hexvDfYR/MS/eKGpiztJoT3Bbbw=
10891073
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg=
1090-
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
10911074
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
1092-
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
10931075
github.com/hashicorp/yamux v0.0.0-20220718163420-dd80a7ee44ce h1:7FO+LmZwiG/eDsBWo50ZeqV5PoH0gwiM1mxFajXAkas=
10941076
github.com/hashicorp/yamux v0.0.0-20220718163420-dd80a7ee44ce/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
10951077
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 h1:aSVUgRRRtOrZOC1fYmY9gV0e9z/Iu+xNVSASWjsuyGU=
@@ -1513,7 +1495,6 @@ github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH
15131495
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
15141496
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
15151497
github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw=
1516-
github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA=
15171498
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
15181499
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
15191500
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
@@ -2182,7 +2163,6 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLL
21822163
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21832164
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21842165
golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
2185-
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21862166
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21872167
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
21882168
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=

0 commit comments

Comments
 (0)