Skip to content

Commit

Permalink
Use json for transfering cty.Type (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
syndicut authored Jan 23, 2021
1 parent 06d5c0a commit b11b475
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions tflint/client/decode_named_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
Expand All @@ -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,
},
}
}
Expand All @@ -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,
Expand Down

0 comments on commit b11b475

Please sign in to comment.