Skip to content

Commit 70eba44

Browse files
authored
Merge pull request #131 from wata727/fix_panic_for_integer_variables_interpolation
Fix panic for integer variables interpolation
2 parents 7f0347f + 58644d1 commit 70eba44

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

evaluator/evaluator_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ variable "name" {
7373
Src: "${var.name}",
7474
Result: "test",
7575
},
76+
{
77+
Name: "completed integer variable",
78+
Input: `
79+
variable "name" {
80+
type = "string"
81+
default = 1
82+
}`,
83+
Src: "${var.name}",
84+
Result: "1",
85+
},
7686
{
7787
Name: "completed list variable",
7888
Input: `
@@ -105,6 +115,15 @@ variable "name" {
105115
Src: "${var.name}",
106116
Result: "test",
107117
},
118+
{
119+
Name: "integer variable in missing type",
120+
Input: `
121+
variable "name" {
122+
default = 1
123+
}`,
124+
Src: "${var.name}",
125+
Result: "1",
126+
},
108127
{
109128
Name: "list variable in missing key",
110129
Input: `

evaluator/variable.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package evaluator
33
import (
44
"reflect"
55

6+
"fmt"
7+
68
"github.com/hashicorp/hcl"
79
hclast "github.com/hashicorp/hcl/hcl/ast"
810
hilast "github.com/hashicorp/hil/ast"
@@ -99,7 +101,7 @@ func parseVariable(val interface{}, varType string) hilast.Variable {
99101
case HCL_STRING_VARTYPE:
100102
hilVar = hilast.Variable{
101103
Type: hilast.TypeString,
102-
Value: val,
104+
Value: fmt.Sprint(val),
103105
}
104106
case HCL_MAP_VARTYPE:
105107
// When HCL map var convert(parse) to Go var,

evaluator/variable_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,11 @@ func TestParseVariable(t *testing.T) {
539539
Value: map[string]hilast.Variable{
540540
"test3": {
541541
Type: hilast.TypeString,
542-
Value: 1,
542+
Value: "1",
543543
},
544544
"test4": {
545545
Type: hilast.TypeString,
546-
Value: 10,
546+
Value: "10",
547547
},
548548
},
549549
},

0 commit comments

Comments
 (0)