How do you import existing Azure resources into Terraform?
IntermediateConceptAzure DevOps, Bicep and Terraform
Answer
Use import blocks (Terraform 1.5+) and let Terraform generate config:
import {
to = azurerm_resource_group.shop
id = "/subscriptions/<sub>/resourceGroups/rg-shop-prod"
}
terraform plan -generate-config-out=generated.tf
The import ID is the full ARM resource ID; get it with az resource show ... --query id -o tsv. Note Azure IDs are case-sensitive in Terraform state comparisons, so copy them exactly. aztfexport can bulk-export an RG into HCL plus state.
More on Azure DevOps, Bicep and Terraform
What services make up Azure DevOps?BeginnerWhat are branch policies in Azure Repos?BeginnerExplain the YAML pipeline structure in Azure Pipelines.BeginnerWhat are service connections and how should they authenticate?IntermediateWhat are environments in Azure Pipelines?IntermediateWhat deployment strategies do deployment jobs support?Intermediate