All Content
Timespan
explore our new search
Comprehensive Guide: Using Azure Terrafys New Import Feature
Image Source: Shutterstock.com
Azure Analytics
Oct 19, 2022 5:32 PM

Comprehensive Guide: Using Azure Terrafys New Import Feature

by HubSite 365 about Microsoft

Software Development Redmond, Washington

Data AnalyticsAzure Analytics

Explore the newest import feature in Azure Terrafy, simplifying infrastructure management with streamlined Terraform integration.

Unpacking the New Azure Terrafy Import Feature

For those working with Infrastructure as Code (IaC) solutions, figuring out where to start can be a challenge. Traditionally, the two options have been to navigate through the Terraform on Azure documentation and craft Terraform templates, or utilize a convenient tool like NubesGen for creating Terraform and Bicep files. These options however have primarily catered for the creation of new infrastructure.

Previously, one could not import existing infrastructure into Terraform, until the introduction of Azure Terrafy. A groundbreaking feature release, this tool has piqued the interest of the community and fills a significant gap for customers managing legacy infrastructure.

Azure Terrafy simplifies the process of importing existing Azure infrastructure into Terraform HCL, and further introduces it into your Terraform state. To use this tool, one first needs to create a directory for generating Terraform code, install the tool locally and then initiate the command specifying the Azure resource group to import.

Run the aztfy command and specify the Azure resource group to import. It is important to note that the tool currently supports importing at the resource group level only.

When the 'aztfy' command is initiated, it begins importing resources, showing the progression via a progress bar. When the import completes, it displays the resources that are ready to be imported. Upon selecting the ‘w’ option, Azure Terrafy begins generating Terraform scripts, updates the state, and includes dependencies in the process. The completion of the process gives you newly created Terraform templates.

Things to Note While Utilizing Azure Terrafy

While Azure Terrafy makes imports more convenient, users need to be aware of renaming conventions and reusability. The resources naming need to be reconfigured, as many of them are defined in a static way. The templates are only made scalable and reusable by manually editing and declaring the variables.

Another concern entails State storage. Post importing the Terraform files, the state remains stored in the local file storage. To make it more reliable and secure, it needs to be stored remotely which requires further work.

Code refactoring is another area to be aware of, as Azure Terrafy generates all templates into one main.tf file. Splashing out the templates into different modules and cleaning up dependencies can make the new templates more reusable and scalable. :

Though not perfect, Azure Terrafy represents a vital advancement for managing resources encoded in Azure. The community is looking forward to additional features that could involve importing vNets or even whole subscriptions. Microsoft has truly done an amazing job creating this tool for users, and further refining it will only serve to bolster its reputation.

Read the full article New Import Feature in Azure Terrafy: A Comprehensive Guide

Azure Analytics - Comprehensive Guide: Using Azure Terrafys New Import Feature

Learn about New Import Feature in Azure Terrafy: A Comprehensive Guide

The world of Infrastructure as Code (IaC) can sometimes be daunting for beginners and experts alike. Previously, new infrastructure creation was the focus with tools available such as NubesGen for building Terraform files, and extensive Azure documentation to learn from. However, the ability to merge legacy infrastructure was notably absent. This has changed with the introduction of a new feature in Azure's toolkit, Azure Terrafy.

Terrafy, as the name implies, offers the capability to terraform your existing infrastructure. This new feature enables quick and hassle-free transition of your existing Azure infrastructure into Terraform HCL. Now, the infrastructure can be imported into your Terraform state, a request demanded by many in the IT community. This innovation greatly assists in the management of legacy systems, which are notorious for being the prime challenge in ITOps.

Using Azure's new functionality is fairly straightforward too. To begin with, a new directory must be created for generating the Terraform code. A folder named 'aztfy-demo' was crafted for the demonstration. Terrafy requires local installation and there are two options to achieve this – downloading the latest binaries or using the Go toolchain. The latter option, which uses the command ‘go install github.com/Azure/aztfy@latest’, was adopted.

Once installed, the Terrafy command must be run with the Azure resource group that is intended for import, specified. Currently, resource groups are the only level at which importing is supported by Terrafy. The import process now begins with displayed resource imports accompanied by a progress bar. At competition, it presents the resources ready for importation. Next, type 'w' to import all viewed resources. Terrafy then goes on to generate your Terraform scripts that include dependencies and update the state.

At this final step, the newly generated template files can be viewed. Verification of successful import can be done by visual check on the Azure portal for the resource names, dependencies and settings. Additionally, running 'Terraform Plan' can offer confirmation that the new configuration matches the original infrastructure. This would imply no changes need to be made.

Success in importing brings along some ensuing considerations though. The naming conventions and re-usability aspects might require reconfiguration. Manually editing and declaring your variables to uplift template reusability and scalability should be done. The Terraform files' state is saved locally, but safekeeping would warrant remote storage of the state. Furthermore, splitting of the templates into modules for making the new files reusable will necessitate some time devotion to VSCode. Lastly, much clean-up can be anticipated once modules and naming conventions are implemented, given the dependence on resource group dependencies.

Being a new tool, its scope is currently limited to resource groups import. It is however expected that the product team will explore its extension to vNets and even subscriptions. Though no tool may tout perfection, Terrafy is certainly a commendable effort in IaC.

You can read more about the Terrafy announcement and the AzAPI Terraform Provider – a new tool that provides day 0 support for all Azure resources - from the official page. You will also find the aztfy GitHub repository useful for tool operation and feature updates. All the best with your importing story!

More links on about New Import Feature in Azure Terrafy: A Comprehensive Guide

Import your existing Azure infrastructure into Terraform HCL
May 11, 2022 — Azure Terrafy allows you to easily and quickly import your existing Azure infrastructure into Terraform HCL AND import it into your Terraform ...
Import and Manage Existing Azure Resources with Terraform
Dec 27, 2022 — Azure Terrafy is a tool that makes it easy to import your existing Azure resources into Terraform modules. In this blog post, I will introduce ...

Keywords

Azure Terrafy, import feature, Azure Terrafy guide, comprehensive guide, Azure new feature, Terrafy new import, Azure Terrafy update, Azure Terrafy tutorial, using Azure Terrafy, Azure platform import feature.