@@ -153,13 +153,17 @@ func parameterDataSource() *schema.Resource {
153
153
}
154
154
155
155
// Validate options
156
+
157
+ // optionType might differ from parameter.Type. This is ok, and parameter.Type
158
+ // should be used for the value type, and optionType for options.
156
159
var optionType OptionType
157
160
optionType , parameter .FormType , err = ValidateFormType (parameter .Type , len (parameter .Option ), parameter .FormType )
158
161
if err != nil {
159
162
return diag .FromErr (err )
160
163
}
161
- // Set the form_type back in case the value was changed, eg via a
162
- // default.
164
+ // Set the form_type back in case the value was changed.
165
+ // Eg via a default. If a user does not specify, a default value
166
+ // is used and saved.
163
167
rd .Set ("form_type" , parameter .FormType )
164
168
165
169
if len (parameter .Option ) > 0 {
@@ -187,11 +191,13 @@ func parameterDataSource() *schema.Resource {
187
191
// If the type is list(string) and optionType is string, we have
188
192
// to ensure all elements of the default exist as options.
189
193
var defaultValues []string
194
+ // TODO: We do this unmarshal in a few spots. It should be standardized.
190
195
err = json .Unmarshal ([]byte (parameter .Default ), & defaultValues )
191
196
if err != nil {
192
197
return diag .Errorf ("default value %q is not a list of strings" , parameter .Default )
193
198
}
194
199
200
+ // missing is used to construct a more helpful error message
195
201
var missing []string
196
202
for _ , defaultValue := range defaultValues {
197
203
_ , defaultIsValid := values [defaultValue ]
@@ -206,7 +212,6 @@ func parameterDataSource() *schema.Resource {
206
212
parameter .Default , strings .Join (missing , ", " ),
207
213
)
208
214
}
209
-
210
215
} else {
211
216
_ , defaultIsValid := values [parameter .Default ]
212
217
if ! defaultIsValid {
0 commit comments