config: detect variables in form of resource.name.*.blah

This commit is contained in:
Mitchell Hashimoto 2014-07-03 20:41:26 -07:00
parent 3337a625af
commit 5e79ddf7c6
4 changed files with 25 additions and 1 deletions

View File

@ -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 = `

View File

@ -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}"
}

View File

@ -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

View File

@ -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)