config: detect variables in form of resource.name.*.blah
This commit is contained in:
parent
3337a625af
commit
5e79ddf7c6
|
@ -238,6 +238,10 @@ aws_instance[web] (x1)
|
||||||
vars
|
vars
|
||||||
resource: aws_security_group.firewall.foo
|
resource: aws_security_group.firewall.foo
|
||||||
user: var.foo
|
user: var.foo
|
||||||
|
aws_instance[db] (x1)
|
||||||
|
security_groups
|
||||||
|
vars
|
||||||
|
resource: aws_security_group.firewall.*.id
|
||||||
`
|
`
|
||||||
|
|
||||||
const basicVariablesStr = `
|
const basicVariablesStr = `
|
||||||
|
|
|
@ -28,3 +28,7 @@ resource aws_instance "web" {
|
||||||
description = "Main network interface"
|
description = "Main network interface"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "aws_instance" "db" {
|
||||||
|
security_groups = "${aws_security_group.firewall.*.id}"
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
var varRegexp *regexp.Regexp
|
var varRegexp *regexp.Regexp
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
varRegexp = regexp.MustCompile(`(?i)(\$+)\{([-.a-z0-9_]+)\}`)
|
varRegexp = regexp.MustCompile(`(?i)(\$+)\{([*-.a-z0-9_]+)\}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReplaceVariables takes a configuration and a mapping of variables
|
// ReplaceVariables takes a configuration and a mapping of variables
|
||||||
|
|
|
@ -87,6 +87,22 @@ func TestVariableDetectWalker_resource(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestVariableDetectWalker_resourceMulti(t *testing.T) {
|
||||||
|
w := new(variableDetectWalker)
|
||||||
|
|
||||||
|
str := `foo ${ec2.foo.*.bar}`
|
||||||
|
if err := w.Primitive(reflect.ValueOf(str)); err != nil {
|
||||||
|
t.Fatalf("err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(w.Variables) != 1 {
|
||||||
|
t.Fatalf("bad: %#v", w.Variables)
|
||||||
|
}
|
||||||
|
if w.Variables["ec2.foo.*.bar"].(*ResourceVariable).FullKey() != "ec2.foo.*.bar" {
|
||||||
|
t.Fatalf("bad: %#v", w.Variables)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestVariableDetectWalker_bad(t *testing.T) {
|
func TestVariableDetectWalker_bad(t *testing.T) {
|
||||||
w := new(variableDetectWalker)
|
w := new(variableDetectWalker)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue