config: validate configuration doens't contain splats to ourselves

This commit is contained in:
Mitchell Hashimoto 2015-02-20 09:18:08 -08:00
parent ed115f495b
commit 90a6a627ed
3 changed files with 34 additions and 0 deletions

View File

@ -385,6 +385,26 @@ func (c *Config) Validate() error {
n, d))
}
}
// Verify provisioners don't contain any splats
for _, p := range r.Provisioners {
// This validation checks that there are now splat variables
// referencing ourself. This currently is not allowed.
for _, v := range p.ConnInfo.Variables {
rv, ok := v.(*ResourceVariable)
if !ok {
continue
}
if rv.Multi && rv.Index == -1 && rv.Type == r.Type && rv.Name == r.Name {
errs = append(errs, fmt.Errorf(
"%s: connection info cannot contain splat variable "+
"referencing itself", n))
break
}
}
}
}
for source, vs := range vars {

View File

@ -179,6 +179,13 @@ func TestConfigValidate_pathVarInvalid(t *testing.T) {
}
}
func TestConfigValidate_provConnSplatSelf(t *testing.T) {
c := testConfig(t, "validate-prov-conn-splat-self")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_unknownThing(t *testing.T) {
c := testConfig(t, "validate-unknownthing")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,7 @@
resource "aws_instance" "bar" {
connection {
host = "${element(aws_instance.bar.*.private_ip, 0)}"
}
provisioner "local-exec" {}
}