Skip to content

Commit

Permalink
Handle multiple variables per line and match capitals
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrudd committed May 24, 2018
1 parent 876a465 commit ee16674
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion configuration.mock
Expand Up @@ -15,6 +15,6 @@ data "template_file" "template1" {
vars {
t1_var1 = "${var.t1_var1}"
t1-var2 = "${var.t1-var2}"
t1-var3 = "${var.t1-Var3}"
t1-var3 = "${var.t1-Var3}-${var.t1-inline}"
}
}
4 changes: 2 additions & 2 deletions generator_test.go
Expand Up @@ -41,8 +41,8 @@ func TestMatchVariable(t *testing.T) {
for _, text := range messages {
ter.matchVarPref(text, varPrefix)
}
if len(ter.Variables) != 4 {
t.Errorf("Should return four variable. but returned %d", len(ter.Variables))
if len(ter.Variables) != 5 {
t.Errorf("Should return five variable. but returned %d", len(ter.Variables))
t.Errorf("Variables found: %s", ter.Variables)
}

Expand Down
8 changes: 4 additions & 4 deletions terraform.go
Expand Up @@ -12,10 +12,10 @@ type terraformVars struct {

func (t *terraformVars) matchVarPref(row, varPrefix string) {
if strings.Contains(row, varPrefix) {
pattern := regexp.MustCompile(`var.([a-z?0-9?_][a-z?0-9?_?-]*)`)
match := pattern.FindAllStringSubmatch(row, 1)
if len(match) != 0 {
res := replacer.Replace(match[0][0])
pattern := regexp.MustCompile(`var.([a-z?A-Z?0-9?_][a-z?A-Z?0-9?_?-]*)`)
match := pattern.FindAllStringSubmatch(row, -1)
for _, m := range match {
res := replacer.Replace(m[0])
if !containsElement(t.Variables, res) {
t.Variables = append(t.Variables, res)
}
Expand Down

0 comments on commit ee16674

Please sign in to comment.