@@ -50,10 +50,12 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
50
50
51
51
pVal := richParameterValue (block )
52
52
53
- def := types .StringLiteral ("" )
53
+ requiredValue := true
54
+ def := types .NullString ()
54
55
defAttr := block .GetAttribute ("default" )
55
56
if ! defAttr .IsNil () {
56
57
def = types .ToHCLString (block , defAttr )
58
+ requiredValue = false
57
59
}
58
60
59
61
ftmeta := optionalString (block , "styling" )
@@ -77,7 +79,7 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
77
79
Icon : optionalString (block , "icon" ),
78
80
Options : make ([]* types.ParameterOption , 0 ),
79
81
Validations : make ([]* types.ParameterValidation , 0 ),
80
- Required : optionalBoolean ( block , "required" ) ,
82
+ Required : requiredValue ,
81
83
DisplayName : optionalString (block , "display_name" ),
82
84
Order : optionalInteger (block , "order" ),
83
85
Ephemeral : optionalBoolean (block , "ephemeral" ),
@@ -138,40 +140,10 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
138
140
p .Validations = append (p .Validations , & valid )
139
141
}
140
142
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 ))
175
147
}
176
148
177
149
usageDiags := ParameterUsageDiagnostics (p )
@@ -189,7 +161,9 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
189
161
func ParameterUsageDiagnostics (p types.Parameter ) hcl.Diagnostics {
190
162
valErr := "The value of a parameter is required to be sourced (default or input) for the parameter to function."
191
163
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 () {
193
167
diags = diags .Append (& hcl.Diagnostic {
194
168
Severity : hcl .DiagError ,
195
169
Summary : "Parameter value is not valid" ,
@@ -244,7 +218,6 @@ func ParameterValidationFromBlock(block *terraform.Block) (types.ParameterValida
244
218
Min : nullableInteger (block , "min" ),
245
219
Max : nullableInteger (block , "max" ),
246
220
Monotonic : nullableString (block , "monotonic" ),
247
- Invalid : nullableBoolean (block , "invalid" ),
248
221
}
249
222
250
223
return p , diags
@@ -477,6 +450,14 @@ func richParameterValue(block *terraform.Block) types.HCLString {
477
450
478
451
val , diags := valRef .Value (block .Context ().Inner ())
479
452
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
+
480
461
return types.HCLString {
481
462
Value : val ,
482
463
ValueDiags : diags ,
0 commit comments