All Projects → Azure → aztfy

Azure / aztfy

Licence: MPL-2.0 License
A tool to bring existing Azure resources under Terraform's management

Programming Languages

go
31211 projects - #10 most used programming language
shell
77523 projects
Makefile
30231 projects

Projects that are alternatives of or similar to aztfy

viya4-iac-azure
This project contains Terraform configuration files to provision infrastructure components required to deploy SAS Viya 4+ VA/VS/VDMML products on Microsoft Azure Cloud.
Stars: ✭ 60 (+5.26%)
Mutual labels:  iac
Disruption
Terraform script to deploy AD-based environment on Azure
Stars: ✭ 34 (-40.35%)
Mutual labels:  iac
terraform-vsphere-single-vm
Deploy single vSphere VM with Terraform - template.
Stars: ✭ 21 (-63.16%)
Mutual labels:  iac
prancer-compliance-test
This repository includes cloud security policies for IaC and live resources.
Stars: ✭ 32 (-43.86%)
Mutual labels:  iac
maturity-models
Maturity models for IT, Agile, DevOps, TOGAF, Six Sigma, P3M3, etc.
Stars: ✭ 157 (+175.44%)
Mutual labels:  iac
terramate
Terramate is a tool for managing multiple Terraform stacks that comes with support for change detection and code generation.
Stars: ✭ 271 (+375.44%)
Mutual labels:  iac
headless-wordpress
Headless Wordpress - AWS - Easy Setup
Stars: ✭ 42 (-26.32%)
Mutual labels:  iac
azure-policy-as-code
Bicep and Terraform code examples for policy-as-code workflows. Azure governance guardrails and automation - by @jesseloudon
Stars: ✭ 101 (+77.19%)
Mutual labels:  terraform-azurerm
terraform-oci-vcn
A reusable and extensible Terraform module that provisions a VCN on Oracle Cloud Infrastructure
Stars: ✭ 22 (-61.4%)
Mutual labels:  iac
fauna-gql-upload
A tool for managing your FaunaDB database using files. Create resources such as functions by simply creating a new file.
Stars: ✭ 45 (-21.05%)
Mutual labels:  iac
terraform-provider-sonarqube
Terraform provider for managing Sonarqube configuration
Stars: ✭ 26 (-54.39%)
Mutual labels:  iac
awesome-iac-testing
A list of awesome IaC testing articles, speeches & links. Especially about Ansible.
Stars: ✭ 56 (-1.75%)
Mutual labels:  iac
terraform-aws-iam-user
A Terraform module to create and manage Identity and Access Management (IAM) Users on Amazon Web Services (AWS). https://aws.amazon.com/iam
Stars: ✭ 17 (-70.18%)
Mutual labels:  iac
terraform-modules
Terraform Modules by Peak
Stars: ✭ 16 (-71.93%)
Mutual labels:  iac
devops-infra-demo
Growing repository of Infrastructure as Code demos (initially created for DevOps Wall Street)
Stars: ✭ 31 (-45.61%)
Mutual labels:  iac
tfu
tfu is a terraform helper to update the providers.
Stars: ✭ 13 (-77.19%)
Mutual labels:  iac
azure-devops-terraform
Recipe to deploy Azure Infrastructure with Terraform via Azure DevOps
Stars: ✭ 18 (-68.42%)
Mutual labels:  iac
aws-cloudformation-templates
CloudFormation Templates
Stars: ✭ 15 (-73.68%)
Mutual labels:  iac
terraform-aws-account
🌳 A sustainable Terraform Package which creates Account & IAM resources on AWS
Stars: ✭ 18 (-68.42%)
Mutual labels:  iac
awesome-projen
P6M7G8's Awesome Projen
Stars: ✭ 39 (-31.58%)
Mutual labels:  iac

Azure Terrafy

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

Goal

Azure Terrafy imports the resources that are supported by the Terraform AzureRM provider within a resource group, 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.

Install

From Release

Precompiled binaries are available at Releases.

From Go toolchain

go install github.com/Azure/aztfy@latest

Usage

Follow the authentication guide from the Terraform AzureRM provider to authenticate to Azure.

Then you can go ahead and run aztfy [option] <resource group name>. The tool can run in two modes: interactive mode and batch mode, depending on whether -b is specified.

Interactive Mode

In interactive mode, aztfy list all the resources resides in the specified resource group. For each resource, user is expected to input the Terraform resource type (e.g. azurerm_linux_virtual_machine). Users can press r to see the possible resource type(s) for the selected import item (though this is not guaranteed to be 100% accurate). In case there is exactly one resource type match for the import item, that resource type will be automatically filled in the text input for the users, with a 💡 line prefix as an indication.

In some cases, there are Azure resources that have no corresponding Terraform resource (e.g. due to lacks of Terraform support), or some resource might be created as a side effect of provisioning another resource (e.g. the Disk resource is created automatically when provisioning a VM). In these cases, you can skip these resources without typing anything.

💡 Option -m can be used to specify a resource mapping file, either constructed manually or from other runs of aztfy (generated in the output directory with name: .aztfyResourceMapping.json).

After going through all the resources to be imported, users press w to instruct aztfy to proceed importing resources into Terraform state and generating the Terraform configuration.

💡 aztfy will run terraform import under the hood to import each resource. Then it will run terraform add -from-state to generate the Terraform template for each imported resource. Whereas there are kinds of limitations causing the output of terraform add to be an invalid Terraform template in most cases. aztfy will leverage extra knowledge from the provider (which is generated from the provider codebase) to further manipulate the template, to make it pass the Terraform validations against the provider.

As the last step, aztfy will leverage the ARM template to inject dependencies between each resource. This makes the generated Terraform template to be useful.

Batch Mode

In batch mode, instead of interactively specifying the mapping from Azurem resource id to the Terraform resource address, aztfy requires the user to provide that mapping via the resource mapping file (via -m), with the following format:

{
    "<azure resource id1>": "<terraform resource type1>.<terraform resource name>",
    "<azure resource id2>": "<terraform resource type2>.<terraform resource name>",
    ...
}

Example:

{
  "/subscriptions/0-0-0-0/resourceGroups/tfy-vm/providers/Microsoft.Network/virtualNetworks/example-network": "azurerm_virtual_network.res-0",
  "/subscriptions/0-0-0-0/resourceGroups/tfy-vm/providers/Microsoft.Compute/virtualMachines/example-machine": "azurerm_linux_virtual_machine.res-1",
  "/subscriptions/0-0-0-0/resourceGroups/tfy-vm/providers/Microsoft.Network/networkInterfaces/example-nic": "azurerm_network_interface.res-2",
  "/subscriptions/0-0-0-0/resourceGroups/tfy-vm/providers/Microsoft.Network/networkInterfaces/example-nic1": "azurerm_network_interface.res-3",
  "/subscriptions/0-0-0-0/resourceGroups/tfy-vm/providers/Microsoft.Network/virtualNetworks/example-network/subnets/internal": "azurerm_subnet.res-4"
}

Then the tool will import each specified resource in the mapping file (if exists) and skip the others.

In the batch import mode, users can further specify the -k option to make the tool continue even on hittng import error on any resource.

Demo

asciicast

Limitation

Some Azure resources are modeled differently in AzureRM provider, which means there might be N:M mapping between the Azure resources and the Terraform resources.

For example, the azurerm_lb_backend_address_pool_address is actually a property of azurerm_lb_backend_address_pool, whilst in the AzureRM provider, it has its own resource and a synthetic resource ID as /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/loadBalancers/loadBalancer1/backendAddressPools/backendAddressPool1/addresses/address1.

Another popular case is that in the AzureRM provider, there are a bunch of "association" resources, e.g. the azurerm_network_interface_security_group_association. These "association" resources represent the association relationship between two Terraform resources (in this case they are azurerm_network_interface and azurerm_network_security_group). They also have some synthetic resource ID, e.g. /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/mygroup1/providers/microsoft.network/networkInterfaces/example|/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1/providers/Microsoft.Network/networkSecurityGroups/group1.

Currently, this tool only works on the assumption that there is 1:1 mapping between Azure resources and the Terraform resources.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].