diff --git a/.gitignore b/.gitignore index dc828b9..2fbb82f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -rover +build/rover .DS_Store rover.zip plan.out @@ -6,4 +6,6 @@ plan.out # Ignore generated terraform files .terraform** -.idea/ \ No newline at end of file +.idea/ + +build/ \ No newline at end of file diff --git a/example/multiple-files-same-resource-type-test/file-one.tf b/example/multiple-files-same-resource-type-test/file-one.tf new file mode 100644 index 0000000..4886113 --- /dev/null +++ b/example/multiple-files-same-resource-type-test/file-one.tf @@ -0,0 +1,4 @@ +resource "random_integer" "one" { + min = 1 + max = 3 +} \ No newline at end of file diff --git a/example/multiple-files-same-resource-type-test/file-two.tf b/example/multiple-files-same-resource-type-test/file-two.tf new file mode 100644 index 0000000..2ed8e73 --- /dev/null +++ b/example/multiple-files-same-resource-type-test/file-two.tf @@ -0,0 +1,4 @@ +resource "random_integer" "two" { + min = 1 + max = 4 +} \ No newline at end of file diff --git a/graph.go b/graph.go index c1185ea..2490d1f 100644 --- a/graph.go +++ b/graph.go @@ -113,10 +113,17 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re label := l[len(l)-1] midParent := parent + if midParent == mid { - midParent = strings.TrimSuffix(midParent, fmt.Sprintf(".%v", label)) + midParent = nodeMap[midParent].Data.Parent + } + + if nodeMap[midParent].Data.Type == ResourceTypeFile { + mid = fmt.Sprintf("%s {%s}", mid, nodeMap[parent].Data.Label) } + //fmt.Printf(midParent + " - " + mid + "\n") + // Append resource type nmo = append(nmo, mid) nodeMap[mid] = Node{ @@ -145,6 +152,7 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re }, Classes: fmt.Sprintf("%s-name %s", re.Type, mrChange), } + //fmt.Printf(id + " - " + mid + "\n") nmo = append(nmo, r.addNodes(base, id, nodeMap, re.Children)...)