'Import existing Azure resources into local Terraform state file

We have an extremely large number of Azure resources that were manually created a while ago, before our move to adopt Terraform. Obviously, this now means we have a huge amount of reconciliation to do, as far as synching our terraform state file with our Azure resources is concerned.

Importing the existing resources individually through the Terraform Import command isn't even an option we want to consider, as it's not only cumbersome but will be time-consuming due to the sheer number of resources at stake here.

Is there another way we could sync/import those existing resources to our local state file in bulk or in one single operation?



Solution 1:[1]

To be honest, this is one of the downfalls with Terraform at the moment. I would suggest creating a spreadsheet that has all the resource import commands,

like terraform import azurerm_xxx.xxx /subscriptions/XXXXXXXXX/resource/example and then the next line is the same and over and over. Then you can copy the entire sequential list and paste it 1 time in the terminal (where you are performing the terraform import) and just hit enter. It will take a while, but it will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 aseb