@@ -153,13 +153,17 @@ func parameterDataSource() *schema.Resource {
153153 }
154154
155155 // 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.
156159 var optionType OptionType
157160 optionType , parameter .FormType , err = ValidateFormType (parameter .Type , len (parameter .Option ), parameter .FormType )
158161 if err != nil {
159162 return diag .FromErr (err )
160163 }
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.
163167 rd .Set ("form_type" , parameter .FormType )
164168
165169 if len (parameter .Option ) > 0 {
@@ -187,11 +191,13 @@ func parameterDataSource() *schema.Resource {
187191 // If the type is list(string) and optionType is string, we have
188192 // to ensure all elements of the default exist as options.
189193 var defaultValues []string
194+ // TODO: We do this unmarshal in a few spots. It should be standardized.
190195 err = json .Unmarshal ([]byte (parameter .Default ), & defaultValues )
191196 if err != nil {
192197 return diag .Errorf ("default value %q is not a list of strings" , parameter .Default )
193198 }
194199
200+ // missing is used to construct a more helpful error message
195201 var missing []string
196202 for _ , defaultValue := range defaultValues {
197203 _ , defaultIsValid := values [defaultValue ]
@@ -206,7 +212,6 @@ func parameterDataSource() *schema.Resource {
206212 parameter .Default , strings .Join (missing , ", " ),
207213 )
208214 }
209-
210215 } else {
211216 _ , defaultIsValid := values [parameter .Default ]
212217 if ! defaultIsValid {
0 commit comments