Skip to content

Commit b11b475

Browse files
authored
Use json for transfering cty.Type (#98)
1 parent 06d5c0a commit b11b475

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

tflint/client/decode_named_values.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
hcl "github.com/hashicorp/hcl/v2"
77
"github.com/terraform-linters/tflint-plugin-sdk/terraform/configs"
8-
"github.com/zclconf/go-cty/cty"
8+
"github.com/zclconf/go-cty/cty/json"
99
"github.com/zclconf/go-cty/cty/msgpack"
1010
)
1111

@@ -14,7 +14,7 @@ type Variable struct {
1414
Name string
1515
Description string
1616
Default []byte
17-
Type cty.Type
17+
Type []byte
1818
ParsingMode configs.VariableParsingMode
1919
Validations []*VariableValidation
2020
Sensitive bool
@@ -35,14 +35,25 @@ func decodeVariable(variable *Variable) (*configs.Variable, hcl.Diagnostics) {
3535
ret[i] = validation
3636
}
3737

38-
defaultVal, err := msgpack.Unmarshal(variable.Default, variable.Type)
38+
typeVal, err := json.UnmarshalType(variable.Type)
3939
if err != nil {
4040
return nil, hcl.Diagnostics{
4141
&hcl.Diagnostic{
4242
Severity: hcl.DiagError,
43-
Summary: "cannot unmarshal variable default value",
44-
Detail: fmt.Sprint(err),
45-
Subject: &variable.DeclRange,
43+
Summary: "cannot unmarshal type for variable",
44+
Detail: fmt.Sprint(err),
45+
Subject: &variable.DeclRange,
46+
},
47+
}
48+
}
49+
defaultVal, err := msgpack.Unmarshal(variable.Default, typeVal)
50+
if err != nil {
51+
return nil, hcl.Diagnostics{
52+
&hcl.Diagnostic{
53+
Severity: hcl.DiagError,
54+
Summary: "cannot unmarshal variable default value",
55+
Detail: fmt.Sprint(err),
56+
Subject: &variable.DeclRange,
4657
},
4758
}
4859
}
@@ -51,7 +62,7 @@ func decodeVariable(variable *Variable) (*configs.Variable, hcl.Diagnostics) {
5162
Name: variable.Name,
5263
Description: variable.Description,
5364
Default: defaultVal,
54-
Type: variable.Type,
65+
Type: typeVal,
5566
ParsingMode: variable.ParsingMode,
5667
Validations: ret,
5768
Sensitive: variable.Sensitive,

0 commit comments

Comments
 (0)