diagrams icon indicating copy to clipboard operation
diagrams copied to clipboard

Feature request: Terraform support

Open mectors opened this issue 4 years ago • 16 comments

The diagrams that are generated are amazingly good looking. Excellent job! If a terraform script could be used as input to automatically generate them then any cloud consultant and audit department would use it in their DevOps pipeline because just like JavaDocs for Java, it would be the no brainier to generate cloud documentation. Would that be possible?

mectors avatar Feb 11 '20 07:02 mectors

What a great idea!

It might be possible with Resource Graph concept. Fortunately, terraform support terraform graph command (which generates Graphviz code), so we could read the terraform script like this way:

$ terraform graph | diagrams --terraform -o graph.png

So I need to create diagrams command line to support it.

Read the Graphviz code generated from terraform graph is much easier than read the HCL scripts directly.

mingrammer avatar Feb 11 '20 14:02 mingrammer

That's a great idea. Using terraform graph is a good starting point, but I think some kind of mapping code would be required to denote relations that go beyond what can be represented with Terraform alone.

E.g. A few instances/instance groups are in a VPC, to denote that they communicate to each, you would need to explicitly tell diagram to draw a line between them. I don't think it can safely be inferred from Terraform. E.g: the only indication may be from a certain firewall rule like allow all instances in the VPC to communicate with port 443.

To reiterate, this is a great idea and we would definitely use that.

j-martin avatar Feb 12 '20 19:02 j-martin

Thank you for giving an example.

I'll have to test some complicated Terraform codes to see if this is possible.

mingrammer avatar Feb 13 '20 14:02 mingrammer

Upvote for that request. I agree that it will be hard, if not impossible to get all relations (eg. between instances), from terraform natively. Maybe adding additional "meta" information, like tags or so, might help. Aside from the graph functionality, the statefile might be a source for gathering information.

ghost avatar May 19 '20 15:05 ghost

It might be useful to take a look at a tool I help developing - https://github.com/Cloud-Architects/cloud-discovery.

We use this library as a visualization engine, provide different commands to report different parts of the infrastructure and have on-top aggregations to simplify usually complex solutions.

meshuga avatar Jun 09 '20 16:06 meshuga

Hi all!

At Cycloid we have just have released a tool that does exactly what's been asked here, generate a Graph from HCL/State in a more human readable way than terraform graph, the tool is InfraMap https://github.com/cycloidio/inframap.

The format in which the graphs are printed can be customized, for now we only support DOT, but would be possible to change it and add a diagrams printer format.

Thanks you all!.

xescugc avatar Jul 16 '20 13:07 xescugc

The idea to provide meta information to the graphs from terraform code would be very useful too.

rightaway avatar Aug 06 '20 15:08 rightaway

I think the reverse! If I create a Graph could I create automatically a terraform code to deploy my environment?

guidiego avatar Nov 24 '20 17:11 guidiego

There might be some useful prior-art over in in https://github.com/28mm/blast-radius

dhirschfeld avatar Dec 04 '20 00:12 dhirschfeld

Another option is to parse tfstate which is a "simple" json instead of HCL which is much more complex.

sfertman avatar Mar 17 '21 20:03 sfertman

HCL2 -> JSON: https://pypi.org/project/python-hcl2/

tbugfinder avatar Mar 30 '21 21:03 tbugfinder

What a great idea!

It might be possible with Resource Graph concept. Fortunately, terraform support terraform graph command (which generates Graphviz code), so we could read the terraform script like this way:

$ terraform graph | diagrams --terraform -o graph.png

So I need to create diagrams command line to support it.

Read the Graphviz code generated from terraform graph is much easier than read the HCL scripts directly.

Hello mingrammer ,I hope you are doing well. I just wanted to ask, did you have any progress for the requested feature?? It is a precious tool but it needs lots of manual coding. In case of major changes in your infra it takes weeks to find details about communications and coding them.

cybrarymin avatar Jun 21 '22 09:06 cybrarymin

Two requests that are complementary, yet necessarily in order below:

  • Reverse engineering of diagrams from tf plan code.

    • With diagrams, docs and /etc/hosts and ansible inventory could be generated?
  • Forward engineering of diagrams to tf plan code.

    • Sounds great, but this DEPENDS upon graphical and lexical standards.

Are either of these on the roadmap in any organized way?

jeremy-donson avatar Dec 02 '22 15:12 jeremy-donson

Any update on this? or any work around for now on how we can automatically or dynamically generate diagrams for our terraform code? 🙏🏻. @mingrammer

vinsten99 avatar May 12 '23 11:05 vinsten99

The diagrams that are generated are amazingly good looking. Excellent job! If a terraform script could be used as input to automatically generate them then any cloud consultant and audit department would use it in their DevOps pipeline because just like JavaDocs for Java, it would be the no brainier to generate cloud documentation. Would that be possible?

Hi guys,

Mingrammer is really a cool tool but of course there are just things that requires extra work to make it functional. So is generating Terraform diagrams from code. We really spent lots of time and work to make it available. With Holori you can now generate terraform diagrams in GitHub Pull request. We support AWS, Azure and GCP and offer 50/run per month for free! Give it a spin : https://app.holori.com/

terraform diagram cicd

alexlegland avatar Nov 28 '23 15:11 alexlegland

I think this has been stale for a while now. And abused for advertisements even. Any progress on the actual issue? Anyone?

icodeforyou-dot-net avatar Feb 20 '24 10:02 icodeforyou-dot-net