Terraform Tips & Tricks, Issue 1: Format, Graph and State
The goal of Terraform Lightning Course is to introduce you to Terraform, so that you know how it works and how to use it. But there are many little features and nuances in day to day Terraform usage. In these bonus articles I will show some of them.
In this issue of Terraform Tips and Tricks, I will show you 3 more Terraform commands.
The first one is super easy: terraform fmt
, or terraform format. If you programmed in Go, it will be feel familiar to you. Let's look at our Template here.
It's nice, but it could be much nicer. Let me run terraform fmt
and open the Template again.
Now it's much nicer formatted and follows all the formatting best practices, automatically. You should run terraform fmt
before commiting your changes.
The second command is terraform graph
. What it does is outputs you the dependency graph of the resources in your template, in a DOT format.
You can even visualize it with GraphViz. It's not too useful, but helps to understand what we learn in the second part of the Terraform Lightning Course.
The last command for today is terraform state
. terraform state
has lots of subcommands to view and manipulate the Terraform state file.
Let's look at just one of them, terraform state list
.
Now we can see what is already in the state file.
That's it for this article.
DevOps consulting: DevOps is a cultural and technological journey. We'll be thrilled to be your guides on any part of this journey. About consulting
Here's the same article in video form for your convenience:
Series "Terraform Lightning Course"
- Infrastructure as Code and How Terraform Fits Into It
- Terraform Fundamentals: State Management and Dependency Graph, Creating the First Server
- Configuring Terraform Templates: Variables and Data Resources
- Terraform Tips & Tricks, Issue 1: Format, Graph and State
- Creating Multi-cloud Terraform environment with the help of remote state backends and AWS S3
- Refactor Terraform code with Modules
- Creating Kubernetes Clusters with Terraform: Learning Provisioners
- Terraform Tips & Tricks, Issue 2: Registry, Locals and Workspaces