config: validate dependsOn
This commit is contained in:
parent
0699cde1d4
commit
20da842bcf
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
resource "aws_instance" "web" {
|
||||
depends_on = ["aws_instance.db"]
|
||||
}
|
|
@ -32,4 +32,6 @@ resource aws_instance "web" {
|
|||
device_index = 0
|
||||
description = "Main network interface"
|
||||
}
|
||||
|
||||
depends_on = ["aws_security_group.firewall"]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue