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 msgpack to encoding to pass cty.Value in variable default #96

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// handShakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes.
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 7,
ProtocolVersion: 8,
MagicCookieKey: "TFLINT_RULESET_PLUGIN",
MagicCookieValue: "5adSn1bX8nrDfgBqiAqqEkC6OE1h3iD8SqbMc5UUONx8x3xCF0KlPDsBRNDjoYDP",
}
Expand Down
19 changes: 17 additions & 2 deletions tflint/client/decode_named_values.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package client

import (
"fmt"

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/msgpack"
)

// Variable is an intermediate representation of configs.Variable.
type Variable struct {
Name string
Description string
Default cty.Value
Default []byte
Type cty.Type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I thought that cty.Type needs to be converted as well, but if you can't explicitly declare cty.unknownType in the Terraform config, it might be okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it can =( With "any" keyword in type, so I will make another PR

ParsingMode configs.VariableParsingMode
Validations []*VariableValidation
Expand All @@ -32,10 +35,22 @@ func decodeVariable(variable *Variable) (*configs.Variable, hcl.Diagnostics) {
ret[i] = validation
}

defaultVal, err := msgpack.Unmarshal(variable.Default, 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,
},
}
}

return &configs.Variable{
Name: variable.Name,
Description: variable.Description,
Default: variable.Default,
Default: defaultVal,
Type: variable.Type,
ParsingMode: variable.ParsingMode,
Validations: ret,
Expand Down