Registry
Ccodemod avatar

codemod/arm-hardcoded-apiversion

Inline statically resolvable Azure Resource Manager (ARM) template resource apiVersion expressions as hard-coded string literals.

codemod0 executions

  • transformation
  • migration
  • azure
  • arm
  • json
Connect a repo
npx codemod @codemod/arm-hardcoded-apiversion

@codemod/arm-hardcoded-apiversion

Inline statically resolvable Azure Resource Manager (ARM) template resource apiVersion expressions as hard-coded string literals.

Installation

bash
# Install from registry
codemod run @codemod/arm-hardcoded-apiversion

# Or run locally
codemod run -w workflow.yaml

Usage

This codemod targets ARM template JSON files and rewrites resource apiVersion values when the value can be resolved to a concrete string at codemod time.

  • Rewrites "apiVersion": "[parameters('name')]" when the referenced parameter has a string defaultValue
  • Rewrites "apiVersion": "[variables('name')]" when the referenced variable resolves to a string literal
  • Rewrites "apiVersion": "[concat(...)]" when every concat segment resolves to a string literal
  • Leaves unresolved expressions unchanged, including references without a string default and expressions that depend on runtime-only ARM functions

Example:

json
{
  "parameters": {
    "storageApiVersion": {
      "type": "string",
      "defaultValue": "2023-01-01"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "[parameters('storageApiVersion')]"
    }
  ]
}

becomes:

json
{
  "parameters": {
    "storageApiVersion": {
      "type": "string",
      "defaultValue": "2023-01-01"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2023-01-01"
    }
  ]
}

Development

bash
# Test the transformation
pnpm test

# Validate the workflow
codemod workflow validate -w workflow.yaml

License

MIT

Ready to evolve your codebase?

Build tailored, compiler-aware skills to assess, plan, and automate complex codebase changes.