How To Use Graphviz With Terraform To Visualize Your Infrastructure

Terraform enables you to create, change and improve infrastructure reliably and predictably, it’s open source and lets you create declarative configuration files that can be treated as code. (Infrastructure As Code). In this video, Nick will take you through the steps required to visualise your infrastructure prior to applying it within Azure. Writing infrastructure as code is great and the recommended path, but how many times have you thought, ‘I would like to visualise this, see what my configuration looks like’? Terraform comes with this functionality built in, using Graphviz (you need to install this) and the terraform ‘graph’ command you will generate a SVG format file to view your infrastructure. A great artefact to store with your code !

Prerequisites include: Install graphviz - Add graphviz to your path C:\Program Files (x86)\Graphviz2.38\bin Azure Subscription Terraform installed

Hello and Welcome to this video where I'm going to show you how to use graphviz with Tereform to visualize your infrastructure. So to get started. We're using a file called Maine dot TF and in this file we have a resource group. A network. And also a subnet defined for using an Azure. So by using graphviz we can actually visualize what we're going to implement and this is quite straightforward. We need to run a command called Terraform and then graph then we're going to output that to base dot dot. So as we've got graphviz installed file Outputs to using the file extension. DOT which indicates it's using the graphic description language and will have a look at that just in a second. So as you'll see from the output. We've actually got text file, so this text file is then rendered by Graphviz. So the first option. We can use GV edit, which is installed by default with graphviz we can do file open. And you'll see if we open the dot file. We get our original text and we get the actual diagram, which is now visualized so as you'll see in the diagram. We have our subnet defined then working down into a virtual network and then to a resource group. So these graphics that are produced or not visio standard so but they are good for checking your infrastructure before you actually apply it. So the best way to actually do this from the command line is to use the terraform graph command and pipe that into dot. The minus T indicates there file format. We're going to use SVG and then we output that to graph dot SVG. So there's the output that's generated. So once we've opened up in browser. I'm using Chrome at the moment. You'll actually see the output that we get and that's direct from the command line so after you've run terraform graph. You might go on to run terraform initialize then apply which will then actually implement your visualized infrastructure. Thank you for watching this video.