Skip to content

Commit a9b64aa

Browse files
authored
fix: support unlimited parameter options (#345)
1 parent 4b3fc65 commit a9b64aa

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

docs/data-sources/parameter.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ data "coder_parameter" "home_volume_size" {
147147
- `ephemeral` (Boolean) The value of an ephemeral parameter will not be preserved between consecutive workspace builds.
148148
- `icon` (String) A URL to an icon that will display in the dashboard. View built-in icons [here](https://github.com/coder/coder/tree/main/site/static/icon). Use a built-in icon with `"${data.coder_workspace.me.access_url}/icon/<path>"`.
149149
- `mutable` (Boolean) Whether this value can be changed after workspace creation. This can be destructive for values like region, so use with caution!
150-
- `option` (Block List, Max: 64) Each `option` block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option))
150+
- `option` (Block List) Each `option` block defines a value for a user to select from. (see [below for nested schema](#nestedblock--option))
151151
- `order` (Number) The order determines the position of a template parameter in the UI/CLI presentation. The lowest order is shown first and parameters with equal order are sorted by name (ascending order).
152152
- `type` (String) The type of this parameter. Must be one of: `"number"`, `"string"`, `"bool"`, or `"list(string)"`.
153153
- `validation` (Block List, Max: 1) Validate the input of a parameter. (see [below for nested schema](#nestedblock--validation))

provider/parameter.go

-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ func parameterDataSource() *schema.Resource {
237237
Description: "Each `option` block defines a value for a user to select from.",
238238
ForceNew: true,
239239
Optional: true,
240-
MaxItems: 64,
241240
Elem: &schema.Resource{
242241
Schema: map[string]*schema.Schema{
243242
"name": {

provider/parameter_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package provider_test
22

33
import (
4+
"fmt"
45
"regexp"
6+
"strings"
57
"testing"
68

79
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -816,3 +818,43 @@ func TestValueValidatesType(t *testing.T) {
816818
})
817819
}
818820
}
821+
822+
func TestParameterWithManyOptions(t *testing.T) {
823+
t.Parallel()
824+
825+
const maxItemsInTest = 1024
826+
827+
var options strings.Builder
828+
for i := 0; i < maxItemsInTest; i++ {
829+
_, _ = options.WriteString(fmt.Sprintf(`option {
830+
name = "%d"
831+
value = "%d"
832+
}
833+
`, i, i))
834+
}
835+
836+
resource.Test(t, resource.TestCase{
837+
ProviderFactories: coderFactory(),
838+
IsUnitTest: true,
839+
Steps: []resource.TestStep{{
840+
Config: fmt.Sprintf(`data "coder_parameter" "region" {
841+
name = "Region"
842+
type = "string"
843+
%s
844+
}`, options.String()),
845+
Check: func(state *terraform.State) error {
846+
require.Len(t, state.Modules, 1)
847+
require.Len(t, state.Modules[0].Resources, 1)
848+
param := state.Modules[0].Resources["data.coder_parameter.region"]
849+
850+
for i := 0; i < maxItemsInTest; i++ {
851+
name, _ := param.Primary.Attributes[fmt.Sprintf("option.%d.name", i)]
852+
value, _ := param.Primary.Attributes[fmt.Sprintf("option.%d.value", i)]
853+
require.Equal(t, fmt.Sprintf("%d", i), name)
854+
require.Equal(t, fmt.Sprintf("%d", i), value)
855+
}
856+
return nil
857+
},
858+
}},
859+
})
860+
}

0 commit comments

Comments
 (0)