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

Fix panic for integer variables interpolation #131

Merged
merged 1 commit into from
Aug 2, 2017
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
19 changes: 19 additions & 0 deletions evaluator/evaluator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ variable "name" {
Src: "${var.name}",
Result: "test",
},
{
Name: "completed integer variable",
Input: `
variable "name" {
type = "string"
default = 1
}`,
Src: "${var.name}",
Result: "1",
},
{
Name: "completed list variable",
Input: `
Expand Down Expand Up @@ -105,6 +115,15 @@ variable "name" {
Src: "${var.name}",
Result: "test",
},
{
Name: "integer variable in missing type",
Input: `
variable "name" {
default = 1
}`,
Src: "${var.name}",
Result: "1",
},
{
Name: "list variable in missing key",
Input: `
Expand Down
4 changes: 3 additions & 1 deletion evaluator/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package evaluator
import (
"reflect"

"fmt"

"github.com/hashicorp/hcl"
hclast "github.com/hashicorp/hcl/hcl/ast"
hilast "github.com/hashicorp/hil/ast"
Expand Down Expand Up @@ -99,7 +101,7 @@ func parseVariable(val interface{}, varType string) hilast.Variable {
case HCL_STRING_VARTYPE:
hilVar = hilast.Variable{
Type: hilast.TypeString,
Value: val,
Value: fmt.Sprint(val),
}
case HCL_MAP_VARTYPE:
// When HCL map var convert(parse) to Go var,
Expand Down
4 changes: 2 additions & 2 deletions evaluator/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,11 +539,11 @@ func TestParseVariable(t *testing.T) {
Value: map[string]hilast.Variable{
"test3": {
Type: hilast.TypeString,
Value: 1,
Value: "1",
},
"test4": {
Type: hilast.TypeString,
Value: 10,
Value: "10",
},
},
},
Expand Down