66 "strings"
77
88 "github.com/aquasecurity/trivy/pkg/iac/terraform"
9+ "github.com/hashicorp/hcl/v2"
910 "github.com/zclconf/go-cty/cty"
1011
1112 "github.com/coder/terraform-provider-coder/v2/provider"
@@ -73,24 +74,16 @@ type ParameterValidation struct {
7374 Min * int64 `json:"validation_min"`
7475 Max * int64 `json:"validation_max"`
7576 Monotonic * string `json:"validation_monotonic"`
76- Invalid * bool `json:"validation_invalid"`
7777}
7878
7979// Valid takes the type of the value and the value itself and returns an error
8080// if the value is invalid.
81- func (v ParameterValidation ) Valid (typ string , value string ) error {
81+ func (v * ParameterValidation ) Valid (typ string , value string ) error {
8282 // TODO: Validate typ is the enum?
8383 // Use the provider.Validation struct to validate the value to be
8484 // consistent with the provider.
85- return (& provider.Validation {
86- Min : int (orZero (v .Min )),
87- MinDisabled : v .Min == nil ,
88- Max : int (orZero (v .Max )),
89- MaxDisabled : v .Max == nil ,
90- Monotonic : orZero (v .Monotonic ),
91- Regex : orZero (v .Regex ),
92- Error : v .Error ,
93- }).Valid (provider .OptionType (typ ), value )
85+ pv := providerValidation (v )
86+ return (& pv ).Valid (provider .OptionType (typ ), value )
9487}
9588
9689type ParameterOption struct {
@@ -100,6 +93,31 @@ type ParameterOption struct {
10093 Icon string `json:"icon"`
10194}
10295
96+ func (r * ParameterData ) Valid () hcl.Diagnostics {
97+ diag := (& provider.Parameter {
98+ Name : r .Name ,
99+ DisplayName : r .DisplayName ,
100+ Description : r .Description ,
101+ Type : provider .OptionType (r .Type ),
102+ FormType : r .FormType ,
103+ Mutable : r .Mutable ,
104+ Default : r .DefaultValue .AsString (),
105+ Icon : r .Icon ,
106+ Option : providerOptions (r .Options ),
107+ Validation : providerValidations (r .Validations ),
108+ Optional : false ,
109+ Order : int (r .Order ),
110+ Ephemeral : r .Ephemeral ,
111+ }).Valid ()
112+
113+ if diag .HasError () {
114+ // TODO: We can take the attr path and decorate the error with
115+ // source information.
116+ return hclDiagnostics (diag )
117+ }
118+ return nil
119+ }
120+
103121// CtyType returns the cty.Type for the ParameterData.
104122// A fixed set of types are supported.
105123func (r * ParameterData ) CtyType () (cty.Type , error ) {
0 commit comments