Install any skill in seconds. Free to start, no credit card required.
Get Started Free →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.
.claude/skills/import-infrastructure-as-code/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-11 | ✗→✓ | ▲ Improved | — | — |
| case-12 | ✗→✓ | ▲ Improved | — | — |
| case-16 | ✗→✓ | ▲ Improved | — | — |
| case-10 | ✗→✓ | ▲ Improved | — | — |
| case-14 | ✗→✓ | ▲ Improved | — | — |
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:
bashaz 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.
bash# 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:
texthttps://raw.githubusercontent.com/Azure/terraform-azurerm-avm-res-<service>-<resource>/refs/heads/main/README.md
Or if the module is already downloaded after terraform init:
bashcat .terraform/modules/<module_key>/README.md
From the README, extract and record before writing code:
(NICs, extensions, subnets, public IPs) is managed inside the module. Do not create standalone module blocks for those resources.
type.Do not assume they match the raw azurerm provider argument names or block shapes.
parent_id vsresource_group_name), how child resources are expressed (inline map vs separate module), and what syntax each input expects.
Use the lessons below as examples of the type of mismatch that often causes imports to fail. Do not assume these exact names apply to every AVM module. Always verify each selected module's README and variables.tf.
avm-res-compute-virtualmachine (any version)
network_interfaces is a Required Input. NICs are owned by the VM module. Nevercreate standalone avm-res-network-networkinterface modules alongside a VM module — define every NIC inline under network_interfaces.
secure_boot_enabled = trueand vtpm_enabled = true. The security_type argument exists only under os_disk for Confidential VM disk encryption and must not be used for TrustedLaunch.
boot_diagnostics is a bool, not an object. Use boot_diagnostics = true; use theseparate boot_diagnostics_storage_account_uri variable if a storage URI is needed.
extensions map. Do not createstandalone extension resources.
avm-res-network-virtualnetwork (any version)
azurerm. Use parent_id (the fullresource group resource ID string) to specify the resource group, not resource_group_name.
parent_id; none show resource_group_name.Generalized takeaway for all AVM modules:
variables.tf.azurerm_* resources.After terraform init downloads the modules, inspect each module's source files to determine the exact Terraform resource addresses before writing any import {} blocks. Never write import addresses from memory.
bashgrep "^resource" .terraform/modules/<module_key>/main*.tf
This reveals whether the module uses azurerm_* or azapi_resource labels. For example, avm-res-network-virtualnetwork exposes azapi_resource "vnet", not azurerm_virtual_network "this".
bashgrep "^module" .terraform/modules/<module_key>/main*.tf
If child resources are managed in a sub-module (subnets, extensions, etc.), the import address must include every intermediate module label:
textmodule.<root_module_key>.module.<child_module_key>["<map_key>"].<resource_type>.<label>[<index>]
count vs for_eachbashgrep -n "count\|for_each" .terraform/modules/<module_key>/main*.tf
Any resource using count requires an index in the import address. When count = 1 (e.g., conditional Linux vs Windows selection), the address must end with [0]. Resources using for_each use string keys, not numeric indexes.
These are examples only. Use them as templates for reasoning, then derive the exact addresses from the downloaded source code for the modules in your current import.
| Resource | Correct import to address pattern | |---|---| | AzAPI-backed VNet | module.<vnet_key>.azapi_resource.vnet | | Subnet (nested, count-based) | module.<vnet_key>.module.subnet["<subnet_name>"].azapi_resource.subnet[0] | | Linux VM (count-based) | module.<vm_key>.azurerm_linux_virtual_machine.this[0] | | VM NIC | module.<vm_key>.azurerm_network_interface.virtualmachine_network_interfaces["<nic_key>"] | | VM extension (default deploy_sequence=5) | module.<vm_key>.module.extension["<ext_name>"].azurerm_virtual_machine_extension.this | | VM extension (deploy_sequence=1–4) | module.<vm_key>.module.extension_<n>["<ext_name>"].azurerm_virtual_machine_extension.this | | NSG-NIC association | module.<vm_key>.azurerm_network_interface_security_group_association.this["<nic_key>-<nsg_key>"] |
Produce:
providers.tf with azurerm provider and required version constraintsmain.tf with AVM module blocks and explicit dependenciesvariables.tf for environment-specific valuesoutputs.tf for key IDs and endpointsterraform.tfvars.example with placeholder valuesAfter writing the initial configuration, compare every non-zero property of each discovered live resource against the default value declared in the corresponding AVM module's variables.tf. Any property where the live value differs from the module default must be set explicitly in the Terraform configuration.
Pay particular attention to the following property categories, which are common sources of silent configuration drift:
idle_timeout_in_minutes defaults to 4; livedeployments often use 30)
private_endpoint_network_policies defaults to"Enabled"; existing subnets often have "Disabled")
sku, allocation_method)Retrieve full live properties with explicit az commands, for example:
bashaz network public-ip show --ids <resource_id> --query "{idleTimeout:idleTimeoutInMinutes, sku:sku.name, zones:zones}" -o json az network vnet subnet show --ids <resource_id> --query "{privateEndpointPolicies:privateEndpointNetworkPolicies, delegation:delegations}" -o json
Do not rely solely on az resource list output, which may omit nested or computed properties.
Pin module versions explicitly:
hclmodule "example" { source = "Azure/<module>/azurerm" version = "<latest-compatible-version>" }
Run:
bashterraform init terraform fmt -recursive terraform validate terraform plan
Expected output: no syntax errors, no validation errors, and a plan that matches discovered infrastructure intent.
| Problem | Likely Cause | Action | |---|---|---| | az command fails with authorization errors | Wrong tenant/subscription or missing RBAC role | Re-run az login, verify subscription context, confirm required permissions | | Discovery output is empty | Incorrect scope or no resources in scope | Re-check scope input and run scoped list/show command again | | No AVM module found for a resource type | Resource type not yet covered by AVM | Use native azurerm_* resource for that type and document the gap | | terraform validate fails | Missing variables or unresolved dependencies | Add required variables and explicit dependencies, then re-run validation | | Unknown argument or variable not found in module | AVM variable name differs from azurerm provider argument name | Read the module README variables.tf or Optional Inputs section for the correct name | | Import block fails — resource not found at address | Wrong provider label (azurerm_ vs azapi_), missing sub-module path, or missing [0] index | Run grep "^resource" .terraform/modules/<key>/main*.tf and grep "^module" to find exact address | | terraform plan shows unexpected ~ update on imported resource | Live value differs from AVM module default | Fetch live property with az <resource> show, compare to module default, add explicit value | | Child-resource module gives "provider configuration not present" | Child resources declared as standalone modules even though parent module owns them | Check Required Inputs in README, remove incorrect standalone modules, and model child resources using the parent module's documented input structure | | Nested child resource import fails with "resource not found" | Missing intermediate module path, wrong map key, or missing index | Inspect module blocks and count/for_each in source; build full nested import address including all module segments and required key/index | | Tool tries to read ARM resource ID as file path or asks repeated scope questions | Resource ID not treated as --ids input, or agent did not trust already-provided scope | Treat ARM IDs strictly as cloud identifiers, use az ... --ids ..., and stop re-prompting once one valid scope is present |
When returning results, provide:
which child resources the module owns. Optional Inputs document exact variable names and types. Usage examples show provider-specific conventions (parent_id vs resource_group_name). Skipping the README is the single most common cause of code errors in AVM-based imports.
any AVM module, treat child resources as parent-owned unless the README explicitly indicates a separate module is required. Check Required Inputs before creating sibling modules.
terraform init, grep the downloadedmodule source to discover the actual provider (azurerm vs azapi), resource labels, sub-module nesting, and count vs for_each usage before writing any import {} block.
--idsarguments and API queries, not file IO tools. Only read local files when a real workspace path is provided.
specific resource IDs are already provided, proceed with commands directly and only ask a follow-up when a command fails due to missing required context.
terraform plan shows 0 destroys and 0unwanted changes. Telemetry + create resources are acceptable. Any ~ update or - destroy on real infrastructure resources must be resolved.
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-06 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 19 counted toward the lift figure. The other 3 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +45 percentage points is the difference between those two pass rates over the 19 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.