config: validate configuration doens't contain splats to ourselves
This commit is contained in:
parent
ed115f495b
commit
90a6a627ed
|
@ -385,6 +385,26 @@ func (c *Config) Validate() error {
|
||||||
n, d))
|
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 {
|
for source, vs := range vars {
|
||||||
|
|
|
@ -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) {
|
func TestConfigValidate_unknownThing(t *testing.T) {
|
||||||
c := testConfig(t, "validate-unknownthing")
|
c := testConfig(t, "validate-unknownthing")
|
||||||
if err := c.Validate(); err == nil {
|
if err := c.Validate(); err == nil {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
resource "aws_instance" "bar" {
|
||||||
|
connection {
|
||||||
|
host = "${element(aws_instance.bar.*.private_ip, 0)}"
|
||||||
|
}
|
||||||
|
|
||||||
|
provisioner "local-exec" {}
|
||||||
|
}
|
Loading…
Reference in New Issue