File tree Expand file tree Collapse file tree 4 files changed +25
-10
lines changed Expand file tree Collapse file tree 4 files changed +25
-10
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,13 @@ resource "aws_nat_gateway" "nat" {
8
8
allocation_id = "${element(aws_eip.nat.*.id, count.index)}"
9
9
subnet_id = "${element(aws_subnet.public.*.id, count.index)}"
10
10
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}-${var.t1-inline}"
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -17,10 +17,9 @@ var tfFileExt = "*.tf"
17
17
var dstFile = "./variables.tf"
18
18
var varTemplate = template .Must (template .New ("var_file" ).Parse (`{{range .}}
19
19
variable "{{ . }}" {
20
- description = ""
20
+ description = ""
21
21
}
22
- {{end}}
23
- ` ))
22
+ {{end}}` ))
24
23
25
24
func init () {
26
25
replacer = strings .NewReplacer (":" , "." ,
@@ -72,6 +71,7 @@ func main() {
72
71
f , err := os .Create (dstFile )
73
72
checkError (err )
74
73
74
+ t .sortVars ()
75
75
err = varTemplate .Execute (f , t .Variables )
76
76
checkError (err )
77
77
log .Infof ("Variables are generated to %q file" , dstFile )
Original file line number Diff line number Diff line change @@ -41,8 +41,9 @@ func TestMatchVariable(t *testing.T) {
41
41
for _ , text := range messages {
42
42
ter .matchVarPref (text , varPrefix )
43
43
}
44
- if len (ter .Variables ) != 1 {
45
- t .Errorf ("Should return one 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 ))
46
+ t .Errorf ("Variables found: %s" , ter .Variables )
46
47
}
47
48
48
49
}
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"regexp"
5
+ "sort"
5
6
"strings"
6
7
)
7
8
@@ -11,13 +12,17 @@ type terraformVars struct {
11
12
12
13
func (t * terraformVars ) matchVarPref (row , varPrefix string ) {
13
14
if strings .Contains (row , varPrefix ) {
14
- pattern := regexp .MustCompile (`var.([a-z?_]+ )` )
15
- match := pattern .FindAllStringSubmatch (row , 1 )
16
- if len ( match ) != 0 {
17
- 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 ])
18
19
if ! containsElement (t .Variables , res ) {
19
20
t .Variables = append (t .Variables , res )
20
21
}
21
22
}
22
23
}
23
24
}
25
+
26
+ func (t * terraformVars ) sortVars () {
27
+ sort .Sort (sort .StringSlice (t .Variables ))
28
+ }
You can’t perform that action at this time.
0 commit comments