Importing ARM Templates
The Azure lexicon can parse existing ARM template JSON and generate equivalent chant TypeScript code.
Import workflow
Section titled “Import workflow”# Import an existing ARM templatechant import template.json
# This creates src/main.ts with typed resource declarationsHow it works
Section titled “How it works”The import pipeline has two stages:
- Parser (
ArmParser) — Parses ARM JSON into an intermediate representation (IR) - Generator (
ArmGenerator) — Converts IR to idiomatic TypeScript
What gets parsed
Section titled “What gets parsed”- Resources — All resources with their types, names, and properties
- Parameters — Converted to
CoreParameterdeclarations - Resource-level fields —
sku,kind,identity,tags,zones,plan,location - Bracket expressions — Converted to intrinsic function calls:
[resourceId(...)]→ResourceId(...)[reference(...)]→Reference(...)[parameters('name')]→ parameter reference[resourceGroup().location]→Azure.ResourceGroupLocation[subscription().subscriptionId]→Azure.SubscriptionId[concat(...)]→Concat(...)[uniqueString(...)]→UniqueString(...)
- dependsOn — Preserved as dependency declarations
Example
Section titled “Example”Input ARM template:
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "storageName": { "type": "string", "metadata": { "description": "Storage account name" } } }, "resources": [ { "type": "Microsoft.Storage/storageAccounts", "apiVersion": "2023-05-01", "name": "[parameters('storageName')]", "location": "[resourceGroup().location]", "kind": "StorageV2", "sku": { "name": "Standard_LRS" }, "properties": { "supportsHttpsTrafficOnly": true } } ]}Generated TypeScript:
import { StorageAccount, Azure } from "@intentius/chant-lexicon-azure";
export const storage = new StorageAccount({ location: Azure.ResourceGroupLocation, kind: "StorageV2", sku: { name: "Standard_LRS" }, supportsHttpsTrafficOnly: true,});Template detection
Section titled “Template detection”The lexicon automatically detects ARM templates by checking for:
- A
$schemaproperty containingdeploymentTemplate - A
resourcesarray
# Auto-detect and importchant import template.json # detects ARM format automaticallyRound-trip workflow
Section titled “Round-trip workflow”- Import an existing ARM template → TypeScript
- Modify the TypeScript (add resources, apply composites, etc.)
- Build back to ARM JSON
- Deploy with Azure CLI
chant import legacy-template.json# Edit src/main.ts as neededchant build --output dist/template.jsonaz deployment group create --template-file dist/template.json