8000 chore: multi select form control allows options to be string · coder/terraform-provider-coder@b80ab8f · GitHub
[go: up one dir, main page]

Skip to content

Commit b80ab8f

Browse files
committed
chore: multi select form control allows options to be string
1 parent 9fc221c commit b80ab8f

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

provider/parameter.go

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,35 @@ func parameterDataSource() *schema.Resource {
181181
}
182182

183183
if parameter.Default != "" {
184-
_, defaultIsValid := values[parameter.Default]
185-
if !defaultIsValid {
186-
return diag.Errorf("default value %q must be defined as one of options", parameter.Default)
184+
if parameter.Type == "list(string)" && optionType == "string" {
185+
// If the type is list(string) and optionType is string, we have
186+
// to ensure all elements of the default exist as options.
187+
var defaultValues []string
188+
err = json.Unmarshal([]byte(parameter.Default), &defaultValues)
189+
if err != nil {
190+
return diag.Errorf("default value %q is not a list of strings", parameter.Default)
191+
}
192+
193+
var missing []string
194+
for _, defaultValue := range defaultValues {
195+
_, defaultIsValid := values[defaultValue]
196+
if !defaultIsValid {
197+
missing = append(missing, defaultValue)
198+
}
199+
}
200+
201+
if len(missing) > 0 {
202+
return diag.Errorf(
203+
"default value %q is not a valid option, values %q are missing from the option",
204+
parameter.Default, strings.Join(missing, ", "),
205+
)
206+
}
207+
208+
} else {
209+
_, defaultIsValid := values[parameter.Default]
210+
if !defaultIsValid {
211+
return diag.Errorf("%q default value %q must be defined as one of options", parameter.FormType, parameter.Default)
212+
}
187213
}
188214
}
189215
}

0 commit comments

Comments
 (0)
0