Skip to content

Commit

Permalink
Merge pull request #158 from wata727/fix_module_initialization_bug
Browse files Browse the repository at this point in the history
Use `strings.Trim` instead of `strings.Replace`
  • Loading branch information
wata727 committed Nov 12, 2017
2 parents 5cd30dc + 2edb680 commit 20c62fc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ language: go

sudo: false

go:
- 1.9
- tip
go: 1.9

script:
- 'make build'
2 changes: 1 addition & 1 deletion evaluator/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (e *Evaluator) initModule(module *schema.Module, c *config.Config) error {
if k != "source" {
if varToken, ok := module.GetToken(k); ok {
varName := "var." + k
ev, err := e.evalModuleAttr(k, strings.Replace(varToken.Text, "\"", "", -1))
ev, err := e.evalModuleAttr(k, strings.Trim(varToken.Text, "\""))
if err != nil {
return errors.New(fmt.Sprintf("Evaluation error: %s in %s:%d", err, varToken.Pos.Filename, varToken.Pos.Line))
}
Expand Down
35 changes: 35 additions & 0 deletions evaluator/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,41 @@ variable "amis" {
module "ec2_instance" {
source = "./tf_aws_ec2_instance"
ami = "${var.amis}"
}`,
Result: hil.EvalConfig{
GlobalScope: &hilast.BasicScope{
VarMap: map[string]hilast.Variable{
"var.ami": {
Type: hilast.TypeList,
Value: []hilast.Variable{
{
Type: hilast.TypeString,
Value: "ami-12345",
},
{
Type: hilast.TypeString,
Value: "ami-54321",
},
},
},
},
},
},
Error: false,
},
{
Name: "init module with list in map",
Input: `
variable "amis" {
default = {
test1 = ["ami-12345", "ami-54321"]
test2 = ["ami-123ab", "ami-abc12"]
}
}
module "ec2_instance" {
source = "./tf_aws_ec2_instance"
ami = "${var.amis["test1"]}"
}`,
Result: hil.EvalConfig{
GlobalScope: &hilast.BasicScope{
Expand Down

0 comments on commit 20c62fc

Please sign in to comment.