patrickchugh / terravision

Terravision creates Professional Cloud Architecture Diagrams from your Terraform code automatically. Supports AWS, Google and Azure.
Mozilla Public License 2.0
683 stars 67 forks source link

KeyError: 'edges' #116

Open patrickmlvn opened 2 months ago

patrickmlvn commented 2 months ago

Checking out terravision for the first time and running into the following issue with a simple Azure Resource Group Terraform file.

My environment: OS: MacOS Sonoma 14.4.1 terravision Version: 0.5 pyenv Version: 2.4.0 python3 Version: 3.10.14

> terravision draw --debug

[sic]

Analysing plan..

Traceback (most recent call last):
  File "~/terravision/terravision", line 265, in <module>
    cli(
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "~/terravision/terravision", line 188, in draw
    tfdata = compile_tfdata(source, varfile, workspace, debug, annotate)
  File "~/terravision/terravision", line 48, in compile_tfdata
    tfdata = tfwrapper.tf_makegraph(tfdata)
  File "~/terravision/modules/tfwrapper.py", line 200, in tf_makegraph
    for connection in tfdata["tfgraph"]["edges"]:
KeyError: 'edges'
patrickchugh commented 1 month ago

Thanks for the bug report. Can you confirm if this still exists with the latest release pushed just now?

patrickmlvn commented 1 month ago

You're welcome. Upgraded to terravision 0.6 and re-ran the command but still running into an issue, looks like the debug is slightly different now:

[sic]

Analysing plan..

Converting TF Graph Connections..  (this may take a while)

Traceback (most recent call last):
  File "~/git/macos/terravision/terravision", line 289, in <module>
    cli(
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/.pyenv/versions/3.10.14/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "~/git/macos/terravision/terravision", line 207, in draw
    tfdata = compile_tfdata(source, varfile, workspace, debug, annotate)
  File "~/git/macos/terravision/terravision", line 50, in compile_tfdata
    tfdata = tfwrapper.tf_makegraph(tfdata)
  File "~/git/macos/terravision/modules/tfwrapper.py", line 220, in tf_makegraph
    for connection in tfdata["tfgraph"]["edges"]:
KeyError: 'edges'
patrickchugh commented 1 month ago

It's very peculiar that your tf graph output doesn't have any edges? I made some modification to check for the edges. Please try again and if it doesn't work can you share your Terraform source with me so I can try to reproduce the error?

patrickmlvn commented 1 month ago

Thanks for the update. Pulled the latest changes in main and I am no longer receiving the edges error. However, I do receive this error:

error ``` > terravision draw --debug [sic] Decoding plan.. Analysing plan.. Converting TF Graph Connections.. (this may take a while) ERROR: No AWS, Azure or Google resources will be created with current plan. Exiting. ```

It could still be a user error on my end, but I tried with just a simple Azure Resource Group creation, as well as a Resource Group, VNET, and NSG. I also tried with a clean environment (removed .terraform/ and .terraform.lock.hcl) with no change.

Just to rule out how/where I was running terravision, all of my attempts have been from within the directory that contains my terraform code. I also tried running from the terravision directory and supplying the --source parameter with no change in the error.

Below, you can see that terraform plan that terravision is executing does see changes to apply:

Generating Terraform Plan.. ```hcl Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # azurerm_resource_group.this will be created + resource "azurerm_resource_group" "this" { + id = (known after apply) + location = "centralus" + name = "sandbox-cus-rsg" + tags = { + "environment" = "sandbox" } } Plan: 1 to add, 0 to change, 0 to destroy. ```

If it would still be helpful, I've included the terraform code below (if you need the provider, or any other info, let me know).

main.tf ```hcl resource "azurerm_resource_group" "this" { name = "sandbox-cus-rsg" location = "centralus" tags = { environment = "sandbox" } } ```