@@ -50,7 +50,7 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
5050
5151 pVal := richParameterValue (block )
5252
53- def := types .StringLiteral ( "" )
53+ def := types .NullString ( )
5454 defAttr := block .GetAttribute ("default" )
5555 if ! defAttr .IsNil () {
5656 def = types .ToHCLString (block , defAttr )
@@ -138,45 +138,10 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
138138 p .Validations = append (p .Validations , & valid )
139139 }
140140
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- valStr := pVal .Value .AsString ()
163- // Apply validations to the parameter value
164- for _ , v := range p .Validations {
165- if err := v .Valid (string (pType ), valStr ); err != nil {
166- diags = diags .Append (& hcl.Diagnostic {
167- Severity : hcl .DiagError ,
168- Summary : fmt .Sprintf ("Paramater validation failed for value %q" , valStr ),
169- Detail : err .Error (),
170- Expression : pVal .ValueExpr ,
171- })
172- }
173- }
174- }
175-
176141 if ! diags .HasErrors () {
177142 // Only do this validation if the parameter is valid, as if some errors
178143 // exist, then this is likely to fail be excess information.
179- diags = diags .Extend (p .Valid ())
144+ diags = diags .Extend (p .Valid (p . Value ))
180145 }
181146
182147 usageDiags := ParameterUsageDiagnostics (p )
@@ -194,7 +159,9 @@ func ParameterFromBlock(block *terraform.Block) (*types.Parameter, hcl.Diagnosti
194159func ParameterUsageDiagnostics (p types.Parameter ) hcl.Diagnostics {
195160 valErr := "The value of a parameter is required to be sourced (default or input) for the parameter to function."
196161 var diags hcl.Diagnostics
197- if ! p .Value .Valid () {
162+ if p .Value .Value .IsNull () {
163+ // Allow null values
164+ } else if ! p .Value .Valid () {
198165 diags = diags .Append (& hcl.Diagnostic {
199166 Severity : hcl .DiagError ,
200167 Summary : "Parameter value is not valid" ,
@@ -478,6 +445,14 @@ func richParameterValue(block *terraform.Block) types.HCLString {
478445
479446 val , diags := valRef .Value (block .Context ().Inner ())
480447 source := hclext .CreateDotReferenceFromTraversal (valRef .Traversal )
448+
449+ // If no value attribute exists, then the value is `null`.
450+ if diags .HasErrors () && diags [0 ].Summary == "Unsupported attribute" {
451+ s := types .NullString ()
452+ s .Source = & source
453+ return s
454+ }
455+
481456 return types.HCLString {
482457 Value : val ,
483458 ValueDiags : diags ,
0 commit comments