The steps below will help you migrate all the resources in an Azure resource group into a Terraform state and configuration file.
1. Install Terraform, if using Windows following the steps here.
2. Download and install the "Azure Export for Terraform" tool from here.
3. Create a directory in which to import.
4. Open the command prompt and navigate to the new directory.
5. [Optional] To not send telemetry data, run aztfexport config set telemetry_enabled false.
6. Run the command aztfexport resource-group --hcl-only <resource group name> replacing the "<resource group name>" with the resource group that contains all the resources. "--hcl-only" flag is used because we want to first verify the configuration files.
7. After the tool initializes, a list of the resources to be exported is displayed. Each line has an Azure resourceID matched to the corresponding AzureRM resource type. The list of available commands displays at the bottom of the display. Using one of the commands, scroll to the bottom and verify that the expected Azure resources are properly mapped to their respective Terraform resource types.
8. Press "w" to run the export.
9. Review the generated files and refactor if required to meet the best practices.
Note: 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.
Links
- GitHub repo
- Azure doc