config: allow exact multi-resource references outside slices

This commit is contained in:
Mitchell Hashimoto 2014-10-11 17:20:39 -07:00
parent ecafcfa682
commit 4cb1ea6ae1
3 changed files with 15 additions and 1 deletions

View File

@ -455,7 +455,7 @@ func (c *Config) validateVarContextFn(
return
}
if rv.Multi && loc != reflectwalk.SliceElem {
if rv.Multi && rv.Index == -1 && loc != reflectwalk.SliceElem {
*errs = append(*errs, fmt.Errorf(
"%s: multi-variable must be in a slice", source))
}

View File

@ -221,6 +221,13 @@ func TestConfigValidate_varDefaultInterpolate(t *testing.T) {
}
}
func TestConfigValidate_varMultiExactNonSlice(t *testing.T) {
c := testConfig(t, "validate-var-multi-exact-non-slice")
if err := c.Validate(); err != nil {
t.Fatalf("should be valid: %s", err)
}
}
func TestConfigValidate_varMultiNonSlice(t *testing.T) {
c := testConfig(t, "validate-var-multi-non-slice")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,7 @@
resource "aws_instance" "foo" {
count = 3
}
resource "aws_instance" "bar" {
foo = "${aws_instance.foo.0.id}"
}