@@ -50,10 +50,12 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
5050
5151 pVal := richParameterValue (block )
5252
53- def := types .StringLiteral ("" )
53+ requiredValue := true
54+ def := types .NullString ()
5455 defAttr := block .GetAttribute ("default" )
5556 if ! defAttr .IsNil () {
5657 def = types .ToHCLString (block , defAttr )
58+ requiredValue = false
5759 }
5860
5961 ftmeta := optionalString (block , "styling" )
@@ -77,7 +79,7 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
7779 Icon : optionalString (block , "icon" ),
7880 Options : make ([]* types.ParameterOption , 0 ),
7981 Validations : make ([]* types.ParameterValidation , 0 ),
80- Required : optionalBoolean ( block , "required" ) ,
82+ Required : requiredValue ,
8183 DisplayName : optionalString (block , "display_name" ),
8284 Order : optionalInteger (block , "order" ),
8385 Ephemeral : optionalBoolean (block , "ephemeral" ),
@@ -138,40 +140,10 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
138140 p .Validations = append (p .Validations , & valid )
139141 }
140142
141- ctyType , err := p .CtyType ()
142- if err != nil {
143- paramTypeDiag := & hcl.Diagnostic {
144- Severity : hcl .DiagError ,
145- Summary : fmt .Sprintf ("Invalid parameter type %q" , p .Type ),
146- Detail : err .Error (),
147- Context : & block .HCLBlock ().DefRange ,
148- }
149-
150- if attr := block .GetAttribute ("type" ); attr != nil && ! attr .IsNil () {
151- paramTypeDiag .Subject = & attr .HCLAttribute ().Range
152- paramTypeDiag .Expression = attr .HCLAttribute ().Expr
153- paramTypeDiag .EvalContext = block .Context ().Inner ()
154- }
155- diags = diags .Append (paramTypeDiag )
156- p .FormType = provider .ParameterFormTypeError
157- }
158-
159- if ctyType != cty .NilType && pVal .Value .Type ().Equals (cty .String ) {
160- // TODO: Wish we could support more types, but only string types are
161- // allowed.
162- //nolint:gocritic // string type asserted
163- valStr := pVal .Value .AsString ()
164- // Apply validations to the parameter value
165- for _ , v := range p .Validations {
166- if err := v .Valid (string (pType ), valStr ); err != nil {
167- diags = diags .Append (& hcl.Diagnostic {
168- Severity : hcl .DiagError ,
169- Summary : fmt .Sprintf ("Paramater validation failed for value %q" , valStr ),
170- Detail : err .Error (),
171- Expression : pVal .ValueExpr ,
172- })
173- }
174- }
143+ if ! diags .HasErrors () {
144+ // Only do this validation if the parameter is valid, as if some errors
145+ // exist, then this is likely to fail be excess information.
146+ diags = diags .Extend (p .Valid (p .Value ))
175147 }
176148
177149 usageDiags := ParameterUsageDiagnostics (p )
@@ -189,7 +161,9 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
189161func ParameterUsageDiagnostics (p types.Parameter ) hcl.Diagnostics {
190162 valErr := "The value of a parameter is required to be sourced (default or input) for the parameter to function."
191163 var diags hcl.Diagnostics
192- if ! p .Value .Valid () {
164+ if p .Value .Value .IsNull () {
165+ // Allow null values
166+ } else if ! p .Value .Valid () {
193167 diags = diags .Append (& hcl.Diagnostic {
194168 Severity : hcl .DiagError ,
195169 Summary : "Parameter value is not valid" ,
@@ -244,7 +218,6 @@ func ParameterValidationFromBlock(block *terraform.Block) (types.ParameterValida
244218 Min : nullableInteger (block , "min" ),
245219 Max : nullableInteger (block , "max" ),
246220 Monotonic : nullableString (block , "monotonic" ),
247- Invalid : nullableBoolean (block , "invalid" ),
248221 }
249222
250223 return p , diags
@@ -477,6 +450,14 @@ func richParameterValue(block *terraform.Block) types.HCLString {
477450
478451 val , diags := valRef .Value (block .Context ().Inner ())
479452 source := hclext .CreateDotReferenceFromTraversal (valRef .Traversal )
453+
454+ // If no value attribute exists, then the value is `null`.
455+ if diags .HasErrors () && diags [0 ].Summary == "Unsupported attribute" {
456+ s := types .NullString ()
457+ s .Source = & source
458+ return s
459+ }
460+
480461 return types.HCLString {
481462 Value : val ,
482463 ValueDiags : diags ,
0 commit comments