How to Import an Existing Azure Resource in Terraform
In this story, we will learn how to import an existing Azure Resource in Terraform.
This allows us to use resources that we have created by some other means and bring it under Terraform management.
Update February 27, 2020: This procedure is valid for both AzureRM v1.x and AzureRM v2.x.
How to Import an Existing Azure Resource in Terraform
Terraform import can only import resources into the state. It does not generate configuration.
Importing an Existing Azure Resouce Group
We have an existing Azure Resource Group called late-motiv-rg, in the Azure Portal, we click on the properties and copy the Resource ID.
Or from the Azure Cloud Shell, we run the following command:
az group show --name late-motiv-rg --query id --output tsv
The result is the ID of the subscription:
az group show --name late-motiv-rg --query id --output tsv…