Import existing Azure resources into Terraform using Azure CLI discovery and Azure Verified Modules (AVM). Use when asked to reverse-engineer live Azure infrastructure, generate Infrastructure as Code from existing subscriptions/resource groups/resource IDs, map dependencies, derive exact import addresses from downloaded module source, prevent configuration drift, and produce AVM-based Terraform files ready for validation and planning across any Azure resource type.
Convert existing Azure infrastructure into maintainable Terraform code using discovery data and Azure Verified Modules.
Use this skill when the user asks to:
azurerm_* resourcesaz login)| Parameter |
|---|
| Required |
|---|
| Default |
|---|
| Description |
|---|
subscription-id | No | Active CLI context | Azure subscription used for subscription-scope discovery and context setting |
resource-group-name | No | None | Azure resource group used for resource-group-scope discovery |
resource-id | No | None | One or more Azure ARM resource IDs used for specific-resource-scope discovery |
At least one of subscription-id, resource-group-name, or resource-id is required.
Request one of these scopes before running discovery commands:
<subscription-id><resource-group-name><resource-id> valuesScope handling rules:
/subscriptions/.../providers/...) as cloud resource identifiers, not local file system paths.--ids arguments (for example az resource show --ids <resource-id>).cat, ls, read_file, glob searches) unless the user explicitly says they are local file paths.If scope is missing, ask for it explicitly and stop.
Run only the commands required for the selected scope.
For subscription scope:
az login
az account set --subscription <subscription-id>
az account show --query "{subscriptionId:id, name:name, tenantId:tenantId}" -o json
Expected output: JSON object with subscriptionId, name, and tenantId.
For resource group or specific resource scope, az login is still required but az account set is optional if the active context is already correct.
When using specific resource scope, prefer direct --ids-based commands first and avoid extra discovery prompts for subscription or resource group unless needed for a concrete command.
Discover resources using the selected scopes. Ensure to fetch all necessary information for accurate Terraform generation.
# Subscription scope
az resource list --subscription <subscription-id> -o json
# Resource group scope
az resource list --resource-group <resource-group-name> -o json
# Specific resource scope
az resource show --ids <resource-id-1> <resource-id-2> ... -o json
Expected output: JSON object or array containing Azure resource metadata (id, type, name, location, tags, properties).
Parse exported JSON and map:
propertiesIMPORTANT: Generate the following documentation and save it to a docs folder in the root of the project.
exported-resources.json with all discovered resources and their metadata, including dependencies and references.EXPORTED-ARCHITECTURE.MD file with a human-readable architecture overview based on the discovered resources and their relationships.Use the latest AVM version for each resource type.
Note: The following links always point to the latest version of the CSV files on the main branch. As intended, this means the files may change over time. If you require a point-in-time version, consider using a specific release tag in the URL.
https://raw.githubusercontent.com/Azure/Azure-Verified-Modules/refs/heads/main/docs/static/module-indexes/TerraformResourceModules.csvhttps://raw.githubusercontent.com/Azure/Azure-Verified-Modules/refs/heads/main/docs/static/module-indexes/TerraformPatternModules.csvhttps://raw.githubusercontent.com/Azure/Azure-Verified-Modules/refs/heads/main/docs/static/module-indexes/TerraformUtilityModules.csvUse the web tool or another suitable MCP method to get module information if not available locally in the .terraform folder.
Use AVM sources:
https://registry.terraform.io/modules/Azure/<module>/azurerm/latesthttps://github.com/Azure/terraform-azurerm-avm-res-<service>-<resource>Prefer AVM modules over handwritten azurerm_* resources when an AVM module exists.
When fetching module information from GitHub repositories, the README.md file in the root of the repository typically contains all detailed information about the module, for example: https://raw.githubusercontent.com/Azure/terraform-azurerm-avm-res-<service>-<resource>/refs/heads/main/README.md
This step is not optional. Before writing a single line of HCL for a module, fetch and
read the full README for that module. Do not rely on knowledge of the raw azurerm provider
or prior experience with other AVM modules.
For each selected AVM module, fetch its README: