Terraform is an infrastructure automation tool developed by HashiCorp four years
ago and it is written in the Go programming language. It is the first multi-cloud
infrastructure tool that allows the user to automate and set up infrastructure elements
from several cloud vendors simultaneously, as well as custom in-house solutions
let's start by the definition, so what is Azure Terrafy?
Azure Terrafy allows you to easily and quickly import your existing Azure infrastructure into Terraform HCL AND import it into your Terraform state. This has been one of the BIGGEST and coolest feature releases.
It’s great to adopt new working tools and practices for when we start a new project, but every single customer I work with wants to know how to manage their legacy infrastructure. The biggest challenge we face in ITOps is managing that legacy infrastructure.
Note: Before using the tool I installed : Terraform, Golang, Choco on my Windows 10 Machine
1- To start using the aztfy tool, we need to install it locally. There are two options: the latest binaries or running the Go toolchain. You can run the Go toolchain using a single command
go install github.com/Azure/aztfy@latest
2- Once installed, run the aztfy command and specify the Azure resource group that you want to import
Note: Currently aztfy only supports importing at the resource group level)
3- Aztfy will now begin the import process:
it found 394 resources in my resource group along with their dependencies. From this view we can filter our results, show any errors/recommendations, or import our resources
4- Click W to start importing resources as it run, along with a progress bar
5- Once Azure Terrafy has completed, you can open your folder and see the newly generated template files:
6- The best way to validate the importing of your resources is by running ‘Terraform Plan
Congratulations! You’ve successfully imported your existing infrastructure in Azure into Terraform templates!
While this makes importing existing resources a breeze, there are some things to be conscious of at this point.
Mohammad Al Rousan is a Microsoft MVP (Azure), Microsoft Certified Solution Expert (MCSE) in Cloud Platform & Azure DevOps & Infrastructure, An active community blogger and speaker.
Al Rousan has over 8 years of professional experience in IT Infrastructure and very passionate about Microsoft technologies and products.
Top 10 Microsoft Azure Blogs