Migrate with terraform Import

A DevOps Engineer manually created infrastructure on Azure, and now there is a requirement to use Terraform to manage it. How would you import these resources in Terraform code?

Hi @Deba-73,

The specifics on how you import are going to be different for the individual resource types. The overall process however would be the same for anything; you can see the current documentation for importing here: Import - Configuration Language | Terraform | HashiCorp Developer

I’ve only used the Azure provider a little, but if memory serves, sometimes you’ll need to get the UUID and / or full resource path for the resources to import; the Azure CLI is likely going to be very helpful in that case.

If you’re trying to migrate a lot of existing infra, none of which is managed by Terraform or some kind of IAC tool, I think the trickier part is to figure out your overall state layout, whether to use any kind of third party tools like terragrunt, etc, and the actual import shouldn’t be so bad.

If there’s already an existing Terraform setup / layout and you just need to add a small number of manually created resources, that should be relatively simple.

Each resource in the provider docs should give an example of valid import syntax at the bottom. For example, for azurerm_resource_group:
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group

terraform import azurerm_resource_group.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/group1