I recently noticed that terraform graph doesn't look different for modules and doesn't scope/descope modules, even when specifying module-depth as shown in the "Plans and Graphs" section here: https://www.terraform.io/docs/modules/usage.html
For example:
terraform graph config/ | wc -l
150
terraform graph --module-depth=1 config/ | wc -l
150
terraform graph --module-depth=0 config/ | wc -l
150
I can't really include an example but it should be simple enough to reproduce. If you need more details, let me know and I'll manufacture one.
-module-depth, there is only one minus.
Unfortunately, that doesn't make a whole lot of difference. I've found that terraform tends to honour both single and double minuses (which is good):
terraform --version
Terraform v0.6.12
terraform graph -module-depth=0 config/ | wc -l
159
terraform graph --module-depth=0 config/ | wc -l
159
terraform graph -module-depth=1 config/ | wc -l
159
terraform graph config/ | wc -l
159
Just noticed this as well. The resulting graph doesn't have any module information in it. It does contain all of the resources from the included modules but doesn't have any module boxes around them.
Edit: This is on version v0.6.14.
Still broken as of
terraform --version
Terraform v0.6.16
terraform graph -module-depth=0 config/ | wc -l
426
terraform graph --module-depth=0 config/ | wc -l
426
terraform graph config/ | wc -l
426
terraform graph -module-depth=1 config/ | wc -l
426
terraform graph -module-depth=2 config/ | wc -l
426
This issue is marked as a question. I think it's confirmed as a bug.
As another point of reference, -module-depth=n works correctly with terraform show in Terraform v0.6.16.
Still not working with Terraform v0.7.0 or v0.7.1 .
Everything else works fine, but without module information the generated graph becomes messy and hard to understand :/
Improving my comment:
If we try to replicate the graph at the Using Modules Page with something like this (please correct me if this is wrong):
# main.tf
module "consul" {
source = "./consul"
}
resource "aws_instance" "bar" {
ami = "ami-6869aa05"
instance_type = "t2.micro"
availability_zone = "${module.consul.availability_zone}"
}
# ./consul/main.tf
resource "aws_instance" "server" {
ami = "ami-6869aa05"
instance_type = "t2.micro"
}
output "availability_zone" {
value = "us-east-1"
}
Running terraform graph | dot -Tpng > graph.png and with any value of -module-depth it yelds the following graph:

Which doesn't group the module inside a bigger box. (And as the -module-depth doesn't change anything, it keeps the same even with -module-depth=0)
Any news on this ?
The -module-depth flag on _graph_ is actually no longer available as of 0.8. The graphs we generate for 0.8 no longer collapse modules into a single graph, meaning that flattening them doesn't make sense any more.
The module depth flag doesn't make a lot of sense either because edges often go in and out of a module and if you collapse it to a single box it'll LOOK like a cycle (when it really isn't since the arrows go to something _in_ the module, not to the module itself).
On the flip side, the graphs generated for Terraform 0.8 are generally much smaller/simpler (except for the NEW infra case) so regardless of this change they should be relatively readable.
The module depth flag still exists and makes sense for apply and so on.
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Still not working with Terraform v0.7.0 or v0.7.1 .
Everything else works fine, but without module information the generated graph becomes messy and hard to understand :/
Improving my comment:
If we try to replicate the graph at the Using Modules Page with something like this (please correct me if this is wrong):
Running
terraform graph | dot -Tpng > graph.pngand with any value of-module-depthit yelds the following graph:Which doesn't group the module inside a bigger box. (And as the
-module-depthdoesn't change anything, it keeps the same even with-module-depth=0)