Skip to content

Commit d4eb950

Browse files
committed
Detect variables with dashes and numbers in them
1 parent 1c73152 commit d4eb950

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

configuration.mock

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ resource "aws_nat_gateway" "nat" {
88
allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
99
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
1010
count = "${length(var.public_subnets)}"
11-
}
11+
}
12+
13+
data "template_file" "template1" {
14+
template = "${file("${path.module}/template1.tpl")}"
15+
vars {
16+
t1_var1 = "${var.t1_var1}"
17+
t1-var2 = "${var.t1-var2}"
18+
t1-var3 = "${var.t1-Var3}"
19+
}
20+
}

generator_test.go

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

4849
}

terraform.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ type terraformVars struct {
1111

1212
func (t *terraformVars) matchVarPref(row, varPrefix string) {
1313
if strings.Contains(row, varPrefix) {
14-
pattern := regexp.MustCompile(`var.([a-z?_]+)`)
14+
pattern := regexp.MustCompile(`var.([a-z?0-9?_][a-z?0-9?_?-]*)`)
1515
match := pattern.FindAllStringSubmatch(row, 1)
1616
if len(match) != 0 {
1717
res := replacer.Replace(match[0][0])

0 commit comments

Comments
 (0)