'How to import an entire Azure resource group in Terraform's state?

Is there a solution to import an entire Azure resource group into Terraform's state file with one command that would capture all resources within that resource group, without manually targeting each resource (which seems to be the only option based on my researches so far)?



Solution 1:[1]

Like @dan-monego mentioned, Terraformer is the way to go. I used it in the past and it's awesome. There is no official way to do this with Terraform, unfortunately.

If that's not an option for you, you would need to write custom code to list the resources in your group, parse the output and then run the terraform import command.

This command would output all the information you'll need to build your import statements az resource list -g <resource-group-name>

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 Regis Tremblay Lefrancois