Home

Awesome

Microsoft Azure Export for Terraform

A tool to bring your existing Azure resources under the management of Terraform.

Video (v0.12.0)

Video

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.

It supports both the Terraform AzureRM provider and the Terraform AzAPI provider.

Non Goal

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.

From Go toolchain

go install github.com/Azure/aztfexport@latest

From Package Manager

Windows

winget install aztfexport

Homebrew (Linux/macOS)

brew install aztfexport

dnf (Linux)

Supported versions:

  1. Import the Microsoft repository key:

    rpm --import https://packages.microsoft.com/keys/microsoft.asc
    
  2. Add packages-microsoft-com-prod repository:

    ver=8 # or 9
    dnf install -y https://packages.microsoft.com/config/rhel/${ver}/packages-microsoft-prod.rpm
    
  3. Install:

    dnf install aztfexport
    

apt (Linux)

Supported versions:

  1. Import the Microsoft repository key:

    curl -sSL https://packages.microsoft.com/keys/microsoft.asc > /etc/apt/trusted.gpg.d/microsoft.asc
    
  2. Add packages-microsoft-com-prod repository:

    ver=20.04 # or 22.04
    apt-add-repository https://packages.microsoft.com/ubuntu/${ver}/prod
    
  3. 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.

Usage

Read the Azure Export documentation which covers scenarios and usage.

Config

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:

Currently, the following config items are supported:

Limitations

Visit this page on the Azure Export for Terraform documentation that discusses the currently known limitations of the tool.

Additional Resources