·
Last changedVersion:
No hardening report available.
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)Reader built-in role is typically sufficient for all discovery operations this skill performs. The skill does not require Contributor or Owner. If az resource show returns authorization errors, confirm the identity has Reader on the target subscription or resource group — do not escalate to write-capable roles without explicit user approval.| Parameter | Required | Default | Description |
|---|---|---|---|
| No | Active CLI context | Azure subscription used for subscription-scope discovery and context setting |
| No | None | Azure resource group used for resource-group-scope discovery |
| 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.Input validation: Before inserting <subscription-id>, <resource-group-name>, or <resource-id> into any CLI command, validate the value against its expected format:
subscription-id must be a UUID ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}).resource-group-name must match ARM naming rules (alphanumeric, hyphens, underscores, 1–90 chars).resource-id must begin with /subscriptions/ and conform to the ARM resource ID path pattern.If a supplied value does not match its expected format, stop and report the validation failure to the user. Do not construct or run any CLI command with an unvalidated input.
If scope is missing, ask for it explicitly and stop.
Run only the commands required for the selected scope.
For subscription scope:
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.
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 (with secrets redacted as described above).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.
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/<version> (obtain <version> from the AVM index CSV as described below)https://github.com/Azure/terraform-azurerm-avm-res-<service>-<resource>Prefer AVM modules over handwritten azurerm_* resources when an AVM module exists.
Before constructing any per-module URL from a resource type string:
terraform-azurerm-avm-res-<service>-<resource>).microsoft.network/virtualnetworks → avm-res-network-virtualnetwork) appears verbatim in the CSV index.azurerm_* path (see non-AVM fallback below).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.
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 (after validating the slug exists in the AVM index CSV per the instructions above):
Or if the module is already downloaded after terraform init:
From the README, extract and record before writing code:
type.
Do not assume they match the raw azurerm provider argument names or block shapes.parent_id vs
resource_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. Never
create standalone avm-res-network-networkinterface modules alongside a VM module —
define every NIC inline under network_interfaces.secure_boot_enabled = true
and 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 the
separate boot_diagnostics_storage_account_uri variable if a storage URI is needed.extensions map. Do not create
standalone extension resources.avm-res-network-virtualnetwork (any version)
azurerm. Use parent_id (the full
resource 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.
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".
If child resources are managed in a sub-module (subnets, extensions, etc.), the import address must include every intermediate module label:
count vs for_eachAny 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 |
|
Subnet (nested, count-based) |
|
Linux VM (count-based) |
|
VM NIC |
|
VM extension (default deploy_sequence=5) |
|
VM extension (deploy_sequence=1–4) |
|
NSG-NIC association |
|
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; live
deployments 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:
Do not rely solely on az resource list output, which may omit nested or computed properties.
Pin module versions explicitly. The version number must be taken from the LatestVersion column of the AVM index CSV downloaded earlier. Do not use "latest" or guess the version:
Run:
Expected output: no syntax errors, no validation errors, and a plan that matches discovered infrastructure intent.
| Problem | Likely Cause | Action |
|---|---|---|
| Wrong tenant/subscription or missing RBAC role | Re-run |
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 |
| 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 | Read the module README |
Import block fails — resource not found at address | Wrong provider label ( | Run |
| Live value differs from AVM module default | Fetch live property with |
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 |
Tool tries to read ARM resource ID as file path or asks repeated scope questions | Resource ID not treated as | Treat ARM IDs strictly as cloud identifiers, use |
Input validation failure on scope value | Supplied subscription ID, resource group name, or resource ID does not match expected format | Report the validation failure to the user; do not run any CLI command with the unvalidated value |
When returning results, provide:
parent_id vs
resource_group_name). Skipping the README is the single most common cause of
code errors in AVM-based imports.terraform init, grep the downloaded
module 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.--ids
arguments and API queries, not file IO tools. Only read local files when a real workspace
path is provided.terraform plan shows 0 destroys and 0
unwanted changes. Telemetry + create resources are acceptable. Any ~ update or
- destroy on real infrastructure resources must be resolved.subscription-id is a UUID, resource-group-name matches ARM naming rules, and resource-id begins with /subscriptions/. Stop and report any validation failure rather than constructing CLI commands with unvalidated input.exported-resources.json. Never write plaintext credentials, connection strings, SAS tokens, or keys to disk. Replace with "[REDACTED]" and record the omission in _redaction_log.Need this version hardened?
Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.
—
—
MIT
HARDENING.md
LICENSE
SKILL.md