This guide will walk you through the process of using Terrify to export an existing Azure resource group.
Prerequisites
Before you begin, make sure you have the following:
- Terrify installed on your machine.
- An Azure subscription with an existing resource group that you want to export.
Steps
-
Log in to Azure using the Azure CLI:
1
az login
-
Set the active subscription to the one that contains the resource group you want to export:
1
az account set --subscription <subscription-id>
Replace
<subscription-id>with the ID of your desired subscription. -
Export the Azure resource group:
1
aztfexport resource-group <resource-group-name> --output <output-directory>Replace
<resource-group-name>with the name of your Azure resource group, and<output-directory>with the directory where you want to save the exported files. -
Wait for the export process to complete. Terrify will generate a set of Terraform configuration files and save them in the specified output directory.
-
(Optional) Customize the generated Terraform configuration files according to your needs.
-
Deploy the exported resource group using Terraform:
1 2 3
cd <output-directory> terraform init terraform applyThis will apply the Terraform configuration and create the resources in your Azure subscription.
Conclusion
By following these steps, you should be able to export an existing Azure resource group using Terrify and deploy it using Terraform. It’s not perfect and does not generate the most maintainable configs but this can be a useful way to manage your infrastructure as code and automate the deployment of resources in Azure when you have existing resources and don’t want to start from scratch.
References
Microsoft Tech Community - Azure Terrify: Import your existing Azure infrastructure into Terraform
Microsoft Tech Community - Announcing Azure Terrify and AzAPI Terraform Provider Previews
Microsoft Learn - Export resources from Azure for Terraform in HCL