diff --git a/tfconfig/load_hcl.go b/tfconfig/load_hcl.go index 72b5d4a..8186bca 100644 --- a/tfconfig/load_hcl.go +++ b/tfconfig/load_hcl.go @@ -148,7 +148,7 @@ func loadModule(dir string) (*Module, Diagnostics) { // guaranteed valid by ctyjson.Marshal. panic(fmt.Errorf("failed to re-parse default value from JSON: %s", err)) } - v.Default = def + v.Default = &Default{Value: def} } } diff --git a/tfconfig/load_legacy.go b/tfconfig/load_legacy.go index 86ffdf1..319b352 100644 --- a/tfconfig/load_legacy.go +++ b/tfconfig/load_legacy.go @@ -101,7 +101,7 @@ func loadModuleLegacyHCL(dir string) (*Module, Diagnostics) { Name: name, Type: block.Type, Description: block.Description, - Default: block.Default, + Default: &Default{Value: block.Default}, Pos: sourcePosLegacyHCL(item.Pos(), filename), } if _, exists := mod.Variables[name]; exists { diff --git a/tfconfig/variable.go b/tfconfig/variable.go index 0f73fc9..1955d07 100644 --- a/tfconfig/variable.go +++ b/tfconfig/variable.go @@ -1,5 +1,13 @@ package tfconfig +import ( + "encoding/json" +) + +type Default struct { + Value interface{} +} + // Variable represents a single variable from a Terraform module. type Variable struct { Name string `json:"name"` @@ -10,7 +18,11 @@ type Variable struct { // the native Go type system. The conversion from the value given in // configuration may be slightly lossy. Only values that can be // serialized by json.Marshal will be included here. - Default interface{} `json:"default,omitempty"` + Default *Default `json:"default,omitempty"` Pos SourcePos `json:"pos"` } + +func (d *Default) MarshalJSON() ([]byte, error) { + return json.Marshal(&d.Value) +}