Skip to content

Commit 9433b31

Browse files
committed
chore: use default path in error if sourced from default
1 parent 0fd96ee commit 9433b31

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

provider/parameter.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ func parameterDataSource() *schema.Resource {
152152
// Always set back the value, as it can be sourced from the default
153153
rd.Set("value", value)
154154

155-
// Set the form_type as it could have changed in the validation.
155+
// Set the form_type, as if it was unset, a default form_type will be updated on
156+
// the parameter struct. Always set back the updated form_type to be more
157+
// specific than the default empty string.
156158
rd.Set("form_type", parameter.FormType)
157159

158160
return nil
@@ -397,9 +399,13 @@ func (v *Parameter) ValidateInput(input *string) (string, diag.Diagnostics) {
397399
var err error
398400
var optionType OptionType
399401

402+
valuePath := cty.Path{}
400403
value := input
401404
if input == nil {
402405
value = v.Default
406+
if v.Default != nil {
407+
valuePath = defaultValuePath
408+
}
403409
}
404410

405411
// optionType might differ from parameter.Type. This is ok, and parameter.Type
@@ -436,7 +442,7 @@ func (v *Parameter) ValidateInput(input *string) (string, diag.Diagnostics) {
436442
forcedValue = *value
437443
}
438444

439-
d := v.validValue(forcedValue, optionType, optionValues, cty.Path{})
445+
d := v.validValue(forcedValue, optionType, optionValues, valuePath)
440446
if d.HasError() {
441447
return "", d
442448
}
@@ -511,7 +517,7 @@ func (v *Parameter) validValue(value string, optionType OptionType, optionValues
511517
if len(optionValues) > 0 {
512518
if v.Type == OptionTypeListString && optionType == OptionTypeString {
513519
// If the type is list(string) and optionType is string, we have
514-
// to ensure all elements of the default exist as options.
520+
// to ensure all elements of the value exist as options.
515521
listValues, err := valueIsListString(value)
516522
if err != nil {
517523
return diag.Diagnostics{

0 commit comments

Comments
 (0)