Skip to content

Commit 5ee802d

Browse files
committed
fix: coder_parameter validation min and max are truly optional
1 parent 6fbb918 commit 5ee802d

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

provider/parameter.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,25 @@ func parameterDataSource() *schema.Resource {
6262
ReadContext: func(ctx context.Context, rd *schema.ResourceData, i interface{}) diag.Diagnostics {
6363
rd.SetId(uuid.NewString())
6464

65+
// 1. Read raw config to check if ptr fields are nil
66+
// 2. Update rd with nil values (it is already broken)
67+
68+
//vm := rd.GetRawConfig().AsValueMap()["validation"].AsValueSlice()[0].AsValueMap()
69+
//log.Println(vm)
70+
71+
val := rd.Get("validation")
72+
v := val.([]interface{})
73+
k := v[0].(map[string]interface{})
74+
k["min"] = nil
75+
k["max"] = nil
76+
v[0] = k
77+
err := rd.Set("validation", v)
78+
if err != nil {
79+
return diag.FromErr(err)
80+
}
81+
6582
var parameter Parameter
66-
err := mapstructure.Decode(struct {
83+
err = mapstructure.Decode(struct {
6784
Value interface{}
6885
Name interface{}
6986
DisplayName interface{}
@@ -98,7 +115,7 @@ func parameterDataSource() *schema.Resource {
98115
}(),
99116
Icon: rd.Get("icon"),
100117
Option: rd.Get("option"),
101-
Validation: rd.Get("validation"),
118+
Validation: val,
102119
Optional: func() bool {
103120
// This hack allows for checking if the "default" field is present in the .tf file.
104121
// If "default" is missing or is "null", then it means that this field is required,

0 commit comments

Comments
 (0)