Use this command to install Microsoft Azure Export for Terraform:
winget install --id=Microsoft.Azure.AztfExport -e
Microsoft Azure Export for Terraform imports the resources that are supported by the Terraform AzureRM provider into the Terraform state, and generates the corresponding Terraform configuration.
Both the Terraform state and configuration are expected to be consistent with the resources' remote state, i.e., terraform plan shows no diff.
The user then is able to use Terraform to manage these resources.
Microsoft Azure Export for Terraform
Microsoft Azure Export for Terraform is a tool designed to import existing Azure resources into the Terraform state and generate corresponding configuration files. This facilitates seamless infrastructure management using Terraform, ensuring consistency with the remote state.
Key Features:
Azure Resource Import: Imports supported Azure resources into Terraform's state.
State Consistency: Ensures that the generated configuration matches the remote state, resulting in a terraform plan with no differences.
Seamless Integration: Facilitates ongoing management of resources using Terraform.
Audience & Benefit:
Ideal for DevOps engineers, cloud architects, and IT teams utilizing Azure and Terraform. This tool enables infrastructure as code practices, reduces manual errors, and enhances collaboration by providing a consistent foundation for Terraform operations. It can be installed via winget.
README
Microsoft Azure Export for Terraform
A tool to bring your existing Azure resources under the management of Terraform.
Video (v0.12.0)
Goal
Azure Export for Terraform exports supported resources into Terraform state and generate the corresponding Terraform configuration. Both the Terraform state and configuration are expected to be consistent with the resources' remote state, i.e., terraform plan shows no diff. The user then is able to use Terraform to manage these resources.
The Terraform configurations generated by aztfexport are not meant to be comprehensive and do not ensure that the infrastructure can be fully reproduced from said generated configurations. For details, please see limitations).
Install
From Release
Precompiled binaries and Window MSI are available at Releases.
ver=20.04 # or 22.04
apt-add-repository https://packages.microsoft.com/ubuntu/${ver}/prod
Install:
apt-get install aztfexport
AUR (Linux)
yay -S aztfexport
Prerequisites
aztfexport requires a terraform executable installed in the $PATH with version >= v0.12.
How it Works
aztfexport leverages aztft to identify the Terraform resource type corresponding to an Azure resource ID. Then it runs terraform import under the hood to import each resource. Afterwards, it runs tfadd to generate the Terraform HCL code for each imported resource.
aztfexport will create a configuration file at $HOME/.aztfexport/config.json. This file is aim to be managed by command aztfexport config [subcommand], which includes following subcommands:
get: Get a config item
set: Set a config item
show: Show the full configuration
Currently, the following config items are supported:
installation_id: A UUID created on first run. If there is Azure CLI or Azure Powershell installed on the current machine, the UUID will be the same value among these tools. Otherwise, a new one will be created. This is used as an identifier in the telemetry trace.
telemetry_enabled: Enables telemetry. We use telemetry to identify issues and areas for improvement, in order to optimize this tool for better performance, reliability, and user experience. If you wish to disable our telemetry, set this to false.
Limitations
Visit this page on the Azure Export for Terraform documentation that discusses the currently known limitations of the tool.
Additional Resources
The aztfexport Github Page: Everything about aztfexport, including comparisons with other existing import solutions.
aztft: A Go program and library for identifying the correct Terraform AzureRM provider resource type on the Azure resource id.
tfadd: A Go program and library for generating Terraform configuration from Terraform state.