Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use json for transfering cty.Type #98

Merged
merged 1 commit into from
Jan 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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