config: validate dependsOn

This commit is contained in:
Mitchell Hashimoto 2014-07-22 17:16:48 -07:00
parent 0699cde1d4
commit 20da842bcf
4 changed files with 23 additions and 0 deletions

View File

@ -155,6 +155,17 @@ func (c *Config) Validate() error {
}
dupped = nil
// Make sure all dependsOn are valid in resources
for n, r := range resources {
for _, d := range r.DependsOn {
if _, ok := resources[d]; !ok {
errs = append(errs, fmt.Errorf(
"%s: resource depends on non-existent resource '%s'",
n, d))
}
}
}
for source, vs := range vars {
for _, v := range vs {
rv, ok := v.(*ResourceVariable)

View File

@ -16,6 +16,13 @@ func TestConfigValidate(t *testing.T) {
}
}
func TestConfigValidate_badDependsOn(t *testing.T) {
c := testConfig(t, "validate-bad-depends-on")
if err := c.Validate(); err == nil {
t.Fatal("should not be valid")
}
}
func TestConfigValidate_badMultiResource(t *testing.T) {
c := testConfig(t, "validate-bad-multi-resource")
if err := c.Validate(); err == nil {

View File

@ -0,0 +1,3 @@
resource "aws_instance" "web" {
depends_on = ["aws_instance.db"]
}

View File

@ -32,4 +32,6 @@ resource aws_instance "web" {
device_index = 0
description = "Main network interface"
}
depends_on = ["aws_security_group.firewall"]
}