Terraform has become the lingua franca of DevOps. As Terraform's popularity grew, the surrounding ecosystem matured to help solve common challenges. Two great examples are Terratest which provides a modular testing framework for your IaC, and Terraformer which helps you quickly get existing infrastructure managed by Terraform. In the project's own words, Terraformer is reverse terraform. It provides a CLI tool to generate terraform files from existing infrastructure. Let's see it in action...
While you can install from source, installation is usually as easy as reaching for a cold brew...
Since Homebrew works on Linux these days, this likely works for most readers... If you do prefer a manual install, one advantage is being able to select providers in the process:
Whatever the approach, you should see the help message once successful:
Terraformer supports a number of Terraform's providers – but not all. Out of the box, you get support for every major IaaS and common things you may have heard of like GitHub and Kubernetes. 😁 The nice thing is this is all open source, so if your favorite provider isn't supported you have the power to contribute!
For a simple example, we'll use the Datadog provider to import a dashboard and synthetic test. In my professional life, we like to view monitoring as IaC just like the infrastructure itself. However, monitoring often evolves organically. Some times it's just easier to prove something out in a UI. Either way, it's nice to be able to import your work of art rather than starting with a clean slate. Terraformer to the rescue...
Let's create a work directory to experiment, and import a resource... Similar to Terraform, Terraformer has a
plan step. That will spit out a
plan.json you can review before doing the actual import. Files are created in
Wait a minute, an error message? It's not very helpful either, but at least it mentions plugins... Let's see if configuring the Datadog provider stops harshing our buzz:
Now that we've wired up the provider, try our plan again:
That went a lot better! We're able to plan and import a resource. We could also import several resources at once... It won't make a mess, but simply pull in any changes or the same resources idemotently:
Now we've got our dashboard and synthetic resources in
generated/datadog. This is a great starting point, but before committing you'll usually want to organize a bit and do some cleanup to integrate with your project:
Does it work as expected?
"Legacy" services which don't fit nicely into the latest toolchain du'jour are a common problem in larger infrastructures. Even in smaller, hipper, more agile shops you often have organic growth or PoCs-turned-production that you'd like to whip into shape. Terraformer can help wrangle existing infrastructure, quickly importing resources from supported providers. While the provider list is not as extensive as Terraform's out of the box, common IaaS and DevOps tools are covered.
Since it's an open source project, you have complete visiblity into what you are running and can help the community by contributing code. Terraformer can easily import individual resources, or an entire service at once – perhaps you want to write automation to generate the import commands? Importing is low-stress, with plans that can be reviewed and idempotency which allows building up plans slowly without stomping on existing resources.