diff --git a/terraform/transform_reference.go b/terraform/transform_reference.go index b85877fd4..f848274aa 100644 --- a/terraform/transform_reference.go +++ b/terraform/transform_reference.go @@ -88,6 +88,18 @@ func (m *ReferenceMap) References(v dag.Vertex) ([]dag.Vertex, []string) { continue } + // Make sure this isn't a self reference, which isn't included + selfRef := false + for _, p := range parents { + if p == v { + selfRef = true + break + } + } + if selfRef { + continue + } + matches = append(matches, parents...) } diff --git a/terraform/transform_reference_test.go b/terraform/transform_reference_test.go index f9c7715e7..525add6bd 100644 --- a/terraform/transform_reference_test.go +++ b/terraform/transform_reference_test.go @@ -28,6 +28,29 @@ func TestReferenceTransformer_simple(t *testing.T) { } } +func TestReferenceTransformer_self(t *testing.T) { + g := Graph{Path: RootModulePath} + g.Add(&graphNodeRefParentTest{ + NameValue: "A", + Names: []string{"A"}, + }) + g.Add(&graphNodeRefChildTest{ + NameValue: "B", + Refs: []string{"A", "B"}, + }) + + tf := &ReferenceTransformer{} + if err := tf.Transform(&g); err != nil { + t.Fatalf("err: %s", err) + } + + actual := strings.TrimSpace(g.String()) + expected := strings.TrimSpace(testTransformRefBasicStr) + if actual != expected { + t.Fatalf("bad:\n\n%s", actual) + } +} + func TestReferenceTransformer_path(t *testing.T) { g := Graph{Path: RootModulePath} g.Add(&graphNodeRefParentTest{