Skip to content

Commit ee16674

Browse files
committed
Handle multiple variables per line and match capitals
1 parent 876a465 commit ee16674

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

configuration.mock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ data "template_file" "template1" {
1515
vars {
1616
t1_var1 = "${var.t1_var1}"
1717
t1-var2 = "${var.t1-var2}"
18-
t1-var3 = "${var.t1-Var3}"
18+
t1-var3 = "${var.t1-Var3}-${var.t1-inline}"
1919
}
2020
}

generator_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ func TestMatchVariable(t *testing.T) {
4141
for _, text := range messages {
4242
ter.matchVarPref(text, varPrefix)
4343
}
44-
if len(ter.Variables) != 4 {
45-
t.Errorf("Should return four variable. but returned %d", len(ter.Variables))
44+
if len(ter.Variables) != 5 {
45+
t.Errorf("Should return five variable. but returned %d", len(ter.Variables))
4646
t.Errorf("Variables found: %s", ter.Variables)
4747
}
4848

terraform.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ type terraformVars struct {
1212

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

0 commit comments

Comments
 (0)