Hi Khandu Shinde,
You can use aztfexport (tool developed by Microsoft Azure), the best option automatically . Additionally you can do a mix of manual and automatically import:
- login to azure :
az login
- run azcli first to get all IDs and types from resources on your resource group:
az resource list --resource-group <Your Resource Group> --query "[].{id:id, type:type}" -o tsv
- Create the blocks required for the IDs on your terraform code, current implementation of Terraform import can only import resources into the state. It does not generate configuration.Therefore it is necessary to write a resource configuration block before running
terraform import
, Here you hace two options :- Create resource manually from microsoft indications and terraform registry:
https://learn.microsoft.com/en-us/azure/templates/<Resource Typee from the output> https://registry.terraform.io/
- Create automatically code with aztfexport: install
aztfexport
from the release (https://github.com/Azure/aztfexport), run aztfexport: Open a command prompt on path where you want to export the resources. Then, run the following command :
aztfexport resource-group --name <resource-group-name>
- Now you can import the configurations into your Terraform state file:
# Example: terraform import azurerm_data_factory_integration_runtime_azure.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.DataFactory/factories/example/integrationruntimes/example
- Finally, you can run
terraform plan
to ensure that the import was successful and that your Terraform state matches your actual infrastructure.
Let me know if this help you. Luis