From a0bf097f1a0d4013a79cab353e7b03043e933b6b Mon Sep 17 00:00:00 2001 From: Rashit Azizbaev Date: Sat, 23 Jan 2021 01:26:49 +0300 Subject: [PATCH] Use json for transfering cty.Type --- tflint/client/decode_named_values.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tflint/client/decode_named_values.go b/tflint/client/decode_named_values.go index 7ad17cc..52c95ab 100644 --- a/tflint/client/decode_named_values.go +++ b/tflint/client/decode_named_values.go @@ -5,7 +5,7 @@ import ( hcl "github.com/hashicorp/hcl/v2" "github.com/terraform-linters/tflint-plugin-sdk/terraform/configs" - "github.com/zclconf/go-cty/cty" + "github.com/zclconf/go-cty/cty/json" "github.com/zclconf/go-cty/cty/msgpack" ) @@ -14,7 +14,7 @@ type Variable struct { Name string Description string Default []byte - Type cty.Type + Type []byte ParsingMode configs.VariableParsingMode Validations []*VariableValidation Sensitive bool @@ -35,14 +35,25 @@ func decodeVariable(variable *Variable) (*configs.Variable, hcl.Diagnostics) { ret[i] = validation } - defaultVal, err := msgpack.Unmarshal(variable.Default, variable.Type) + typeVal, err := json.UnmarshalType(variable.Type) if err != nil { return nil, hcl.Diagnostics{ &hcl.Diagnostic{ Severity: hcl.DiagError, - Summary: "cannot unmarshal variable default value", - Detail: fmt.Sprint(err), - Subject: &variable.DeclRange, + Summary: "cannot unmarshal type for variable", + Detail: fmt.Sprint(err), + Subject: &variable.DeclRange, + }, + } + } + defaultVal, err := msgpack.Unmarshal(variable.Default, typeVal) + if err != nil { + return nil, hcl.Diagnostics{ + &hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "cannot unmarshal variable default value", + Detail: fmt.Sprint(err), + Subject: &variable.DeclRange, }, } } @@ -51,7 +62,7 @@ func decodeVariable(variable *Variable) (*configs.Variable, hcl.Diagnostics) { Name: variable.Name, Description: variable.Description, Default: defaultVal, - Type: variable.Type, + Type: typeVal, ParsingMode: variable.ParsingMode, Validations: ret, Sensitive: variable.Sensitive,