Salta ai contenuti
AggregaAggregaAggregaAggrega
Seleziona lingua: Italiano
Questa pagina è stata tradotta automaticamente. Leggi l’originale in inglese.

Importare un template Azure Resource Manager

Questa guida passo passo importa un piccolo template Azure Resource Manager — un namespace Event Hubs distribuito tramite il modulo di Azure Verified Modules, un sito App Service che esegue un container, una web app statica e la rete virtuale a cui il sito deve unirsi — ed esegue la build del risultato come un template Azure Resource Manager. L’importazione abbozza l’Aggregate, la Release e il Manifest: il namespace e il sito diventano riferimenti ai Components della libreria standard, la web app statica, che nessun Component rappresenta, viene abbozzata a partire dal template, e i valori che il template dichiara in una forma che una Release possa accogliere vengono riportati. Alcuni valori per cui non è così sono lasciati a te, e la pagina mostra quali e dove. Ogni file e ogni blocco di output riportati di seguito provengono da un’esecuzione reale; il template e ogni fase della guida si trovano nell’esempio import-arm, dove uno script di controllo esegue di nuovo l’importazione, confronta ciò che scrive, ciò che stampa e i blocchi citati in questa pagina con i file conservati lì, conferma che la bozza si ferma dove dice questa pagina, ed esegue la build della Release rivista.

Creare la bozza dell’esempio

Puoi eseguire questa importazione con i comandi di questa pagina, oppure farla eseguire al tuo assistente AI.

Scrivi l’esempio in una nuova cartella che porta il suo nome:

Terminal window
aggrega draft --example import-arm

Poi stampa i prossimi comandi da eseguire. Il primo ti porta nella nuova cartella; quello successivo, qui sotto, ti porta nella cartella source della nuova cartella, che contiene ciò che questa pagina importa ed è dove viene eseguita l’importazione:

Terminal window
cd import-arm

Il template

main.json è la forma compilata di un template: il JSON che scrive una build di Bicep e che Azure Resource Manager distribuisce. Il suo parametro è la regione, e inizia con una rete virtuale che contiene la subnet a cui si unisce il sito:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "westeurope"
}
},
"resources": [
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2023-11-01",
"name": "vnet-notes",
"location": "[parameters('location')]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.20.0.0/16"
]
},
"subnets": [
{
"name": "snet-app",
"properties": {
"addressPrefix": "10.20.1.0/24",
"delegations": [
{
"name": "web",
"properties": {
"serviceName": "Microsoft.Web/serverFarms"
}
}
]
}
}
]
}
},
[… omitted: the rest of the template]

Il namespace viene distribuito tramite il modulo avm/res/event-hub/namespace di Azure Verified Modules alla versione 0.15.3: una risorsa Microsoft.Resources/deployments il cui membro template contiene il template compilato proprio del modulo, più di 3.700 righe, e i cui parameters sono ciò che il template imposta per il modulo:

{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "ehModule",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"name": {
"value": "evh-notes"
},
"location": {
"value": "[parameters('location')]"
},
"skuName": {
"value": "Standard"
},
"skuCapacity": {
"value": 2
},
"publicNetworkAccess": {
"value": "Enabled"
},
"enableTelemetry": {
"value": true
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
[… omitted: the module's compiled template, and the rest of the resource]

Il template compilato del modulo è quello che il Microsoft Container Registry serve per quella versione, con licenza MIT, e il README dell’esempio riporta la nota. L’importazione lo legge per riconoscere il modulo: il suo prefisso di telemetria e la sua versione indicano il modulo di Azure Verified Modules e il tipo di risorsa che distribuisce.

Il sito è una risorsa semplice. Gira su un piano App Service che esiste già, si unisce alla subnet del template, esegue il container indicato in linuxFxVersion, legge l’output name del modulo e imposta un’altra variabile:

{
"type": "Microsoft.Web/sites",
"apiVersion": "2023-12-01",
"name": "notes-api",
"location": "[parameters('location')]",
"kind": "app,linux,container",
"dependsOn": [
"[resourceId('Microsoft.Resources/deployments', 'ehModule')]",
"[resourceId('Microsoft.Network/virtualNetworks', 'vnet-notes')]"
],
"properties": {
"serverFarmId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes",
"virtualNetworkSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app')]",
"siteConfig": {
"linuxFxVersion": "DOCKER|ghcr.io/example/notes-api:2.3.0",
"appSettings": [
{
"name": "EVENTHUB_NAMESPACE",
"value": "[reference('ehModule').outputs.name.value]"
},
{
"name": "EVENTHUB_NAME",
"value": "notes"
}
]
}
}
},

Anche la web app statica è una risorsa semplice. Accanto al template, un file dei parametri fornisce l’unico parametro:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": { "value": "northeurope" }
}
}

I due file si trovano nella cartella notes, e un .aggrega-config.yaml accanto a quella cartella rende la directory un workspace, così l’importazione scrive lì le sue bozze:

# The workspace key marks this directory as the workspace root, so an import run
# here writes its drafts beside the notes folder.
workspace: {}
# The registry the importer is fetched from the first time an import needs it.
default_registry: hub.aggrega.ai

L’importazione legge un template e il suo file dei parametri come JSON con commenti, riconoscendo un template dal suo $schema e dalle sue resources, e un file dei parametri dal suo $schema e dai suoi parameters. Valuta ogni risorsa rispetto ai Components del catalogo del workspace, che legge come descrive Come si svolge un’importazione, e non legge alcun account cloud: un valore che il template calcola durante la distribuzione viene riportato come l’espressione che lo calcola, mai cercato.

Entra in source:

Terminal window
cd source

Eseguire l’importazione

Indica la cartella che contiene il template. L’importatore riconosce il template e il suo file dei parametri dal loro contenuto:

Terminal window
aggrega import notes

Non viene indicato alcun --target. L’importatore dichiara arm come destinazione predefinita, perché le Recipes della libreria standard per Azure Resource Manager vi si legano, e l’importazione abbozza un Manifest per essa; un’importazione che nomina una destinazione, con --target, abbozza invece per quella. Il registro che l’importazione scrive accanto alle sue bozze conserva la destinazione, e --sync lo riutilizza.

Sullo standard output elenca ciò che ha scritto:

wrote aggregate.yaml
wrote release.yaml
wrote manifest.yaml
wrote catalog/component/imported/compute/microsoft-web-staticsites/0.1.0/component.yaml
wrote catalog/recipe/arm/microsoft-web-staticsites/0.1.0/recipe.yaml
wrote .aggrega-import.json

Sullo standard error, dove <workspace> sta per la cartella in cui l’hai eseguita:

[… omitted: a warning that the importer runs unverified, printed where its module is read from beside its Plugin entity in a catalog folder rather than fetched]
read as the arm format, with drafted paths relative to <workspace>
info: the drafts are for the target "arm", the importer's declared default; an import naming a target drafts for that one
info: ehmodule deploys the Azure Verified Modules resource module avm/res/event-hub/namespace, of telemetry prefix 46d3xbcp.res.962075c, version 0.15.3, named "Event Hub Namespaces" in its metadata: it is one node of the resource type Microsoft.EventHub/namespaces, the parameters it sets read as the module's, and the module's telemetry is not carried, as whether a Recipe sends telemetry is the Recipe's to set
warn: notes-api sets the variable EVENTHUB_NAMESPACE at properties.siteConfig.appSettings.0.value from ehmodule's outputs.name.value, and the drafted Aggregate does not wire it: ehmodule publishes no provides key for it; the instance notes-api is connected to ehmodule for the dependency alone, a comment above the connection saying why; write the value where the instance is configured
info: the resource notes-site of the type Microsoft.Web/staticSites@2023-01-01 is drafted from the source as the Component imported/compute/microsoft-web-staticsites and the Recipe microsoft-web-staticsites on arm, carrying the properties the source writes; the decision's swap hint names the import drafting it from the vendor's schema
warn: the source creates substrate the draft leaves to the operator and drafts nothing for: vnet-notes (Microsoft.Network/virtualNetworks), of which the format says the network a component runs in is the operator's: a component of the catalog takes it by its resource ID under infra.overrides, reading the parameter location at location; provide each where the Release deploys, and fill the pointers the Release leaves for them
warn: notes-api sets the variable EVENTHUB_NAME in the environment of the instance notes-api, and the draft delivers an instance's environment from its connections alone, so the variable is not carried: the instance's Release entry names it, for the author to set where the instance is configured
mapped ehmodule (Microsoft.EventHub/namespaces) to core/messaging/azure-event-hubs as a reference, HIGH at 0.8656
mapped notes-site (Microsoft.Web/staticSites) to imported/compute/microsoft-web-staticsites as a draft, NONE at 0.05
made no choice for vnet-notes (Microsoft.Network/virtualNetworks)
mapped notes-api (Microsoft.Web/sites) to core/compute/server as a reference, HIGH at 0.9
made no choice for resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app') ()
[… omitted: what the pull could not render yet, a stop of the App Service Recipe's assertion that the Release names the subnet, which the sections below explain]
external inputs: dependency pins were written and are complete; 0 external input(s) pinned, and any this Release also needs are still unpinned
external inputs: a build of this Release halts naming the unpinned URL; fixing what stopped the render and resolving again pins it
Pull complete: <workspace>/release.lock (entities=8, source_artifacts=0, external_inputs=0)
External inputs were not fully discovered: dependency pins are complete, external-input pins may not be (see the diagnostics above)
  • Le righe info indicano ciò che l’importatore ha deciso senza fare domande. La prima dice che le bozze sono per arm. La seconda riconosce il modulo: la risorsa ehmodule è il modulo di Azure Verified Modules del namespace Event Hubs, e i parametri che il template imposta per esso si leggono come propri del modulo, così la bozza lo tratta come un unico namespace e non come un template annidato da leggere. La terza dice che la web app statica viene abbozzata a partire dal template.
  • Le righe warn nominano ciò che la bozza non riporta. La prima è la variabile che il sito legge dall’output name del modulo: la bozza collega una connessione solo per ciò che un Component pubblica, e il namespace non pubblica alcuna chiave per il suo nome, quindi la connessione esiste solo per la dipendenza. La seconda nomina la rete virtuale che il template crea, che la bozza lascia a te, come spiega Ciò che la bozza lascia a te. La terza nomina la variabile che il sito imposta e che nessuna connessione della bozza fornisce.
  • Le righe mapped dicono che cosa è diventata ogni risorsa. ehmodule è un’istanza di core/messaging/azure-event-hubs della libreria standard, e notes-api un’istanza del server generico, core/compute/server, ciascuna corrisposta nella fascia alta e referenziata. notes-site non corrisponde ad alcun Component, quindi è una bozza, senza corrispondenza. Le righe made no choice nominano ciò per cui la bozza non decide nulla: la rete virtuale e il puntatore alla subnet che la Release lascia vuoto.
  • Il pull è l’importazione che recupera ciò da cui dipende la Release abbozzata, come fa aggrega pull, in release.lock. Le Recipes che il Manifest nomina per il namespace e il sito scrivono da sole le proprie risorse e non recuperano alcuna sorgente, quindi source_artifacts è 0 e il pull non esce dal catalogo per nulla. L’importazione prova poi a eseguire il rendering della Release per trovare gli input che la build recupererebbe, e la Recipe App Service la ferma: la bozza non nomina ancora alcuna subnet. L’importazione termina comunque, con il lockfile scritto, e dice che gli input esterni non sono stati scoperti per intero; l’arresto è quello che la convalida riporta subito dopo.

Cosa scrive

L’Aggregate, la Release e il Manifest si chiamano imported/notes, dalla cartella che l’importazione ha letto — un template importato come file prende il nome del file, main — nel namespace definito dall’impostazione target_namespace dell’importatore, imported a meno che tu non ne imposti un altro (Impostazioni).

aggregate.yaml — una voce per risorsa e la connessione che il sito traccia:

# Sources read: main.json, main.parameters.json.
# Substrate the source creates, left to the operator: vnet-notes (Microsoft.Network/virtualNetworks).
apiVersion: aggrega.ai/v1beta1
kind: Aggregate
metadata:
name: imported/notes
version: 0.1.0
description: Draft Aggregate imported from a source in the arm format.
spec:
components:
ehmodule:
type: core/messaging/azure-event-hubs
notes-site:
type: imported/compute/microsoft-web-staticsites
values:
name: "notes-site"
notes-api:
type: core/compute/server
uses:
# Not wired: notes-api sets the variable EVENTHUB_NAMESPACE at properties.siteConfig.appSettings.0.value from ehmodule's outputs.name.value; ehmodule publishes no provides key for it.
ehmodule:
ehmodule:
target: ehmodule

La web app statica è un componente di un tipo che l’importazione ha abbozzato, imported/compute/microsoft-web-staticsites. La connessione del sito al namespace non porta alcun blocco inject, poiché la bozza fornisce una variabile da una connessione solo quando il Component pubblica il valore, e il commento sopra dice quale variabile non collega e perché.

release.yaml — l’ambiente e le impostazioni di ciascuna risorsa:

apiVersion: aggrega.ai/v1beta1
kind: Release
metadata:
name: imported/notes
# environment is a drafted default, since no source names the environment this Release deploys to; change it to name the one it deploys to.
environment: development
version: 0.1.0
description: Draft Release imported from a source in the arm format.
spec:
aggregate: imported/notes
manifest: imported/notes
components:
# Module parameters the source sets and the draft does not translate: location, name, publicNetworkAccess, skuCapacity, skuName.
ehmodule: {}
notes-site:
infra:
# From the template parameter location, the value the parameters file supplies.
location: "northeurope"
overrides:
appLocation: "/"
outputLocation: "dist"
name: "Free"
tier: "Free"
# Properties the source writes and the draft does not place: kind, properties.siteConfig.linuxFxVersion.
# Environment variables the source sets and no connection delivers: EVENTHUB_NAME = notes.
notes-api:
infra:
overrides:
service_plan_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes"
# From the template parameter location, the value the parameters file supplies.
location: "northeurope"
# Left for the Release, since the source cannot supply it: infra.overrides.virtual_network_subnet_id, the pointer to the resource "resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app')", which the draft leaves to the operator and the source names as "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'vnet-notes', 'snet-app')]"; the catalog Recipe takes the resource's literal identifier: write it
virtual_network_subnet_id: ""

L’ambiente, development, è un valore predefinito che l’importazione scrive perché nessun template ne nomina uno. Il parametro location del template arriva alle voci della web app statica e del sito come il valore che il file dei parametri fornisce, northeurope. Il service_plan_id del sito è riportato come l’identificatore letterale che il template scrive. La voce del namespace è vuota, e il commento sopra elenca i parametri del modulo che la bozza non traduce.

Una chiave è vuota, e il suo commento dice perché: virtual_network_subnet_id è un puntatore a una risorsa, che le Recipes della libreria standard per Azure Resource Manager accettano come identificatore letterale /subscriptions/… della risorsa. Il template scrive la subnet del sito come un’espressione resourceId che nomina una risorsa del template stesso, e un’espressione non è un identificatore che la Recipe possa accettare, così la bozza lascia la chiave vuota e nomina l’espressione in un commento. Una risorsa abbozzata, invece, mantiene intera ogni espressione del template.

L’immagine del container non è nella voce. Il template la scrive dentro linuxFxVersion, una proprietà che la bozza non colloca da nessuna parte, e il commento sopra la voce elenca kind e linuxFxVersion tra le proprietà che non colloca.

manifest.yaml — la Recipe con cui ogni componente viene realizzato su arm:

apiVersion: aggrega.ai/v1beta1
kind: Manifest
metadata:
name: imported/notes
version: 0.1.0
spec:
mappings:
components:
type: {}
name:
ehmodule: arm/azure-event-hubs
notes-site: arm/microsoft-web-staticsites
notes-api: arm/server-app-service

L’app web statica non ha alcun Component nella libreria standard, quindi l’importazione ne abbozza uno con una Recipe nella cartella catalog del workspace: il Component imported/compute/microsoft-web-staticsites dichiara il name che il template dà al sito, una location e un oggetto overrides per ogni proprietà che il template scrive, con i nomi propri del fornitore, e la Recipe microsoft-web-staticsites scrive una risorsa Microsoft.Web/staticSites di quel tipo e di quella versione di API. Le bozze sono semplici file che puoi leggere e modificare:

apiVersion: aggrega.ai/v1beta1
kind: Component
metadata:
name: imported/compute/microsoft-web-staticsites
version: 0.1.0
description: "Draft Component of the resource type Microsoft.Web/staticSites@2023-01-01, imported from a source in the arm format."
labels:
component.aggrega.ai/type: resource
component.aggrega.ai/category: compute
component.aggrega.ai/hosting: managed
spec:
schema:
values:
type: object
properties:
# identity: the resource's own name or identifier
# The source writing the resource gives no description of name.
name:
type: string
required: true
additionalProperties: false
infra:
type: object
properties:
# placement: where the resource is deployed
# The source writing the resource gives no description of location.
location:
type: string
required: true
# override: every writable property no other rule places, each under the vendor's own name
overrides:
type: object
description: "Writable settings of Microsoft.Web/staticSites@2023-01-01, each under the vendor's own name, which the Recipe passes to the resource as written; its header lists the names it reads."
additionalProperties: true
additionalProperties: false
[… omitted: the values the Component publishes, id and name]

release.lock registra le entità del catalogo a cui la Release è stata risolta, per digest; .aggrega-import.json è il registro di ciò che l’importazione ha scritto, che un successivo aggrega import --sync legge.

Convalidare

Terminal window
aggrega validate --release release.yaml

La convalida si ferma. La bozza non nomina alcuna subnet per il sito, e la Recipe App Service unisce un sito a una subnet della tua rete solo tramite il suo identificatore:

[CATALOG_ERROR E0033]
Recipe/FeatureRecipe assertions
[… omitted: the line beginning "caused by: Recipe "server-app-service" instance "notes-api" assertion "placement_supplied"", which ends with the Recipe's message: … infra.overrides.virtual_network_subnet_id is "", and this Recipe takes the subnet the app joins by virtual network integration as the subnet's resource ID: set it to /subscriptions/<subscription>/resourceGroups/<group>/providers/Microsoft.Network/virtualNetworks/<network>/subnets/<subnet>, a subnet delegated to Microsoft.Web/serverFarms, or remove it]
release dependency validation failed: 1 diagnostic(s)

Un rifiuto nomina cosa cambiare e dove, nel documento che modifichi. Qui è la voce notes-api di release.yaml, e dopo la subnet la build nomina un secondo valore: l’immagine del container. Il template la scrive in linuxFxVersion, che la bozza non colloca, e la Recipe del server generico per App Service non contiene alcuna immagine propria, quindi la build si ferma con un messaggio che dice che la Release non imposta infra.image. L’immagine sei tu a doverla fornire nella Release.

Il commento del namespace elenca skuName, skuCapacity e location, che il modulo prende dal template e che nemmeno la bozza colloca. Senza di essi valgono i valori predefiniti della Recipe; infra.overrides.sku_name, infra.overrides.sku_capacity e infra.overrides.location portano quelli del template. La cartella reviewed dell’esempio contiene il release.yaml con tutti scritti:

# Module parameters the source sets and the draft does not translate: location, name, publicNetworkAccess, skuCapacity, skuName.
ehmodule:
infra:
overrides:
# Where the template sets skuName and skuCapacity, which the draft places nowhere: the namespace's tier and its throughput units.
sku_name: "Standard"
sku_capacity: 2
# Where the template sets location, which the draft places nowhere on a module: the namespace's region.
location: "northeurope"

e la voce del sito, con l’immagine e la subnet:

# Properties the source writes and the draft does not place: kind, properties.siteConfig.linuxFxVersion.
# Environment variables the source sets and no connection delivers: EVENTHUB_NAME = notes.
notes-api:
infra:
# The template writes the container image in properties.siteConfig.linuxFxVersion, which the draft places nowhere: the image the site runs.
image: "ghcr.io/example/notes-api:2.3.0"
overrides:
service_plan_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes"
# From the template parameter location, the value the parameters file supplies.
location: "northeurope"
# The subnet the template's virtual network holds, as the literal ID the Recipe takes, in the resource group the network is deployed to.
virtual_network_subnet_id: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-network/providers/Microsoft.Network/virtualNetworks/vnet-notes/subnets/snet-app"

Lo script di controllo dell’esempio esegue la build di questa Release e conferma che la bozza si ferma con il messaggio riportato sopra.

Build

Spostati in una cartella che contiene la Release rivista, oppure modifica release.yaml in source allo stesso modo, ed esegui la build:

Terminal window
aggrega validate --release release.yaml
aggrega build --release release.yaml --auto-pull

La Release non corrisponde più al release.lock scritto dall’importazione, quindi la build richiede --auto-pull, che lo risolve di nuovo; senza di esso la build si ferma e nomina aggrega pull. La convalida stampa:

release dependency validation passed: release.yaml (schema-pillar + dependency pillars)

e la build, dove <workspace> indica la cartella in cui l’hai eseguita:

[… omitted: the pull's line reporting the lockfile it wrote]
[… omitted: a total build time, which differs per run]
Build completed: 1 file written to <workspace>/dist

Leggere arm-template.json

La build scrive un solo file, dist/arm/arm-template.json: il template assemblato, nella versione di linguaggio 2.0, con una voce sotto resources per ogni risorsa che un componente scrive, denominata in base all’id di istanza del componente ridotto a parole:

Ehmodule the Event Hubs namespace, in a nested template
NotesApi the App Service site
NotesApiFtpPublishing the site's FTP publishing policy, which the Recipe turns off
NotesApiScmPublishing the site's SCM publishing policy, which the Recipe turns off
NotesSite the static web app, the resource the draft Recipe writes

La voce del namespace contiene il namespace che la Recipe scrive, con le impostazioni che la Release porta — il livello, le unità di throughput e la regione — e quelle proprie della Recipe per il resto:

"Ehmodule": {
"apiVersion": "2025-04-01",
"metadata": {
"aggrega.ai/provenance": {
"aggrega.ai/aggregate-name": "imported/notes",
"aggrega.ai/boundary-path": "default",
[… omitted: a compiler-version entry, which moves with the build]
"aggrega.ai/component-id": "ehmodule",
"aggrega.ai/environment": "development",
"aggrega.ai/provider": "arm",
[… omitted: a provider-version entry, which moves with the build]
"aggrega.ai/recipe-uri": "azure-event-hubs:1.0.0"
}
},
"name": "[format('Ehmodule-{0}', uniqueString(deployment().name))]",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {
"serviceBusEndpoint": {
"type": "string",
"value": "[reference(resourceId('Microsoft.EventHub/namespaces', 'ehmodule'), '2026-01-01').serviceBusEndpoint]"
}
},
"resources": [
{
"apiVersion": "2026-01-01",
"location": "northeurope",
"name": "ehmodule",
"properties": {
"disableLocalAuth": true,
"isAutoInflateEnabled": false,
"minimumTlsVersion": "1.2",
"publicNetworkAccess": "Enabled"
},
"sku": {
"capacity": 2,
"name": "Standard",
"tier": "Standard"
},
"type": "Microsoft.EventHub/namespaces"
}
]
}
},
"type": "Microsoft.Resources/deployments"
},

La voce del sito porta il piano, la subnet, l’immagine come il container che il sito esegue, e la porta che il server generico dichiara:

"NotesApi": {
"apiVersion": "2025-03-01",
"kind": "app,linux,container",
"location": "northeurope",
"metadata": {
"aggrega.ai/provenance": {
"aggrega.ai/aggregate-name": "imported/notes",
"aggrega.ai/boundary-path": "default",
[… omitted: a compiler-version entry, which moves with the build]
"aggrega.ai/component-id": "notes-api",
"aggrega.ai/environment": "development",
"aggrega.ai/provider": "arm",
[… omitted: a provider-version entry, which moves with the build]
"aggrega.ai/recipe-uri": "server-app-service:1.0.0"
}
},
"name": "notes-api",
"properties": {
"clientAffinityEnabled": false,
"httpsOnly": true,
"publicNetworkAccess": "Disabled",
"serverFarmId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-platform/providers/Microsoft.Web/serverfarms/plan-notes",
"siteConfig": {
"alwaysOn": true,
"appSettings": [
{
"name": "WEBSITES_PORT",
"value": "8080"
}
],
"ftpsState": "Disabled",
"linuxFxVersion": "DOCKER|ghcr.io/example/notes-api:2.3.0",
"minTlsVersion": "1.2",
"vnetRouteAllEnabled": true
},
"virtualNetworkSubnetId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/notes-network/providers/Microsoft.Network/virtualNetworks/vnet-notes/subnets/snet-app"
},
"type": "Microsoft.Web/sites"
},

Il sito riceve WEBSITES_PORT e nulla di ciò che il template ha impostato: EVENTHUB_NAMESPACE e EVENTHUB_NAME sono variabili che la bozza non ha fornito, che le righe warn e i commenti nominano. Il nome del namespace è ehmodule, il nome del componente, dove il template lo chiamava evh-notes: il name del modulo spetta alla Recipe, e il commento sopra la voce lo elenca tra i parametri che la bozza non traduce.

Eseguire il deploy

Il template è un template di gruppo di risorse. La build non scrive alcun file di parametri e non esegue nulla su Azure: i comandi sono tuoi. Visualizza in anteprima ciò che il template cambierebbe, poi esegui il deploy:

Terminal window
az deployment group what-if --resource-group <group> --template-file dist/arm/arm-template.json
az deployment group create --resource-group <group> --name <name> --template-file dist/arm/arm-template.json

La pagina del provider ARM espone questi comandi, lo stack che non elimina mai ciò che smette di gestire, e ciò che decide ogni opzione. Prima del deploy del template, le risorse che la Release nomina ma che il template non distribuisce devono esistere: il piano App Service e la subnet a cui il sito si unisce, che è delegata a Microsoft.Web/serverFarms.

Con un assistente AI

Un assistente AI configurato con gli strumenti di Aggrega può fare lo stesso: incollaci questo prompt.

Usa solo gli strumenti di Aggrega e non creare tu alcuna cartella. Se la cartella del Workspace non contiene ancora una cartella `import-arm`, chiama una volta lo strumento `draft` con `example` impostato a `import-arm` e nessun `dir`: scrive l’esempio in una nuova cartella `import-arm`. Poi chiama lo strumento `import` con `workspace_root` impostato a `import-arm/source` e `source` impostato a `notes`: scrive le sue bozze in `import-arm/source` e scarica ciò di cui hanno bisogno. Poi chiama lo strumento `build` con `workspace_root` impostato a `import-arm/reviewed`, `release` impostato a `release.yaml`, `auto_pull` impostato a true e `write` impostato a true. Dimmi quali file ha scritto la build; si trovano in `import-arm/reviewed/dist/`.

La cartella reviewed contiene la bozza con i valori scritti, come li elenca Convalidare; per rivedere la tua bozza, chiedi all’assistente di convalidare prima import-arm/source e di dirti dove si ferma.

Aprilo in VS Code

Con l’estensione Aggrega per Visual Studio Code installata, apri in VS Code la cartella import-arm/source, dove l’importazione ha scritto le sue bozze. La cartella contiene una sola Release, il release.yaml redatto, quindi l’editor la seleziona per te e controlla le bozze rispetto a quella Release mentre le modifichi, segnalando ciò che trova nel file e nel pannello Problemi. Aggrega: Show topology graph, nel riquadro comandi, disegna i componenti della Release e le connessioni tra di essi. Aggrega: Build, Aggrega: Preview build e Aggrega: Pull agiscono sulla stessa Release, e ciascuno è anche un pulsante nel pannello Commands della vista Aggrega nella barra delle attività; Build scrive i propri file in dist/ della cartella. Usare Aggrega in Visual Studio Code copre il resto.

Quando il template cambia

Tieni .aggrega-import.json accanto alle bozze e, dopo che il template è cambiato, esegui:

Terminal window
aggrega import notes --sync

Il comando legge il target che il record conserva, arm, e modifica solo ciò che l’importazione ha scritto. Dopo che outputLocation della web app statica passa da dist a build in main.json, l’importazione dice:

changed spec.components.notes-site.infra.overrides.outputLocation in release.yaml

e scrive release.yaml con quell’unica riga modificata; i valori che hai scritto accanto restano come sono. Una parte che la sorgente non ha toccato resta com’è su disco, modificata o no; dove la sorgente ha cambiato una parte che hai modificato, il comando si ferma, indica la parte e non scrive nulla, perché tu la riconcili a mano. aggrega import descrive le regole e ogni opzione per intero.

Un template può distribuirne un altro tramite una risorsa Microsoft.Resources/deployments il cui templateLink.relativePath indica un file accanto a sé. L’importazione legge i template collegati dentro la directory importata: parte da un template, la radice, legge ogni template che la radice collega e redige le risorse di tutti come un solo Aggregate.

Una directory che contiene più template indica la propria radice in base a cosa collega cosa: la radice è l’unico template che nessun altro collega. Una directory che contiene due template senza collegamento tra loro non ha un’unica radice, e l’importazione si ferma e indica entrambi:

halt: the sources network.json, site.json are each linked by no other source, and the root setting names none of them: set root to the path of the one to start from

L’impostazione root indica il template da cui partire, nella voce dell’importer della configurazione del workspace. L’uri indica l’importer tramite la sua identità e la versione del compilatore che esegui, come la scrive aggrega plugin add importer (Quale importer trasforma una sorgente in bozze):

plugins:
importer:
- uri: importer/arm:<version>
with:
settings:
root: site.json

Con root impostato, l’importazione legge site.json e i template che collega, e lascia fuori network.json.

Un collegamento che esce dalla directory importata — ../shared/dns.json — non viene letto: l’importazione non apre mai un file fuori dalla directory che le è stata data. Emette un avviso che indica la risorsa e il percorso, e redige la risorsa come risorsa a sé, portando ogni output di quel template che il template legge come l’espressione che lo valuta quando il template viene distribuito:

warn: dns is a Microsoft.Resources/deployments resource of main.json whose template is linked by a relative path leaving the imported directory, which the import does not read: no resource of that template is drafted, and each of its outputs the template reads is carried as text evaluated when the template deploys; to draft its resources, place the linked template inside the imported directory and link it by templateLink.relativePath

Metti il template collegato dentro la directory importata e la prossima importazione lo legge.

Quando un nome è già in uso

Una risorsa di cui la bozza fa un Component riceve il nome che l’importazione sceglie per essa in base al suo tipo: imported/compute/microsoft-web-staticsites per la web app statica. Dove esiste già un Component con quel nome in una cartella di catalogo del workspace o nell’hub, e questa importazione non lo ha redatto, l’importazione non lo sovrascrive e non tira a indovinare. Trattiene la risorsa, senza redigerla né farvi riferimento, ed emette un avviso. Importare l’esempio una seconda volta in un’altra cartella dello stesso workspace, con --output-dir second, dopo che la prima importazione ha scritto il Component nella cartella catalog del workspace, dice:

warn: notes-site (Microsoft.Web/staticSites) is held back: the catalog holds the Component imported/compute/microsoft-web-staticsites a draft of it takes, which this import did not draft, so the resource is neither drafted nor referenced; to reference it, write in the importer's settings the entry {"mapping_overrides":{"arm":{"Microsoft.Web/staticSites":{"component":"imported/compute/microsoft-web-staticsites","category":"compute","traits":{"component.aggrega.ai/hosting":"managed","component.aggrega.ai/type":"resource"},"vendor":"staticsites"}}}}, then fill the instance's infra in the Release

L’impostazione mapping_overrides della voce dell’importer, indicizzata per formato, arm, e poi per tipo di risorsa, associa il tipo al Component che esiste, e la voce che l’avviso stampa è quella da scrivere (Settings). Con essa, la prossima importazione fa riferimento al Component: notes-site è associato come riferimento, e la sua voce nella Release non contiene chiavi tranne un commento che nomina le proprietà che il template scrive:

notes-site: {}

Il Component dichiara un name e un location obbligatori e la bozza non scrive né l’uno né l’altro, quindi l’importazione termina segnalando ciascuno come mancante, con le bozze scritte. Scrivili, insieme alle proprietà che il commento elenca, nella Release, come li dichiara il Component.

Ciò che la bozza lascia a te

L’importazione redige ciò che il template dichiara e ciò che il tuo catalogo determina, e dice dove si è fermata. Per un template lascia questi:

  • Il substrato che il template crea per servire altri. La rete virtuale vnet-notes e la sua subnet esistono nel template per il sito. La bozza non crea alcuna rete: un Component del catalogo prende la rete in cui gira tramite il suo ID di risorsa, sotto infra.overrides, e la rete è tua. La riga warn nomina ogni risorsa di questo tipo, e i puntatori che vi si riferivano sono le chiavi vuote della Release. Dove la Release viene distribuita, la rete e la subnet esistono già, oppure le distribuisci con il template che hai importato.
  • Valori che la bozza non colloca. Il commento di ogni voce della Release elenca i parametri del modulo e le proprietà della risorsa che la bozza non colloca, tra cui qui il livello, le unità di throughput, la regione e il nome del namespace, e il kind e il linuxFxVersion del sito, così l’impostazione del template è dichiarata e non scartata in silenzio. Dove un Component ha un posto per uno di essi, lo scrivi tu, come fa la sezione Convalidare.
  • Variabili d’ambiente che nessuna connessione fornisce. EVENTHUB_NAMESPACE e EVENTHUB_NAME del sito sono nominate nei commenti dell’Aggregate e della Release e in una riga warn ciascuna. Dove il sito è configurato nella Release, le imposti tu.
  • L’immagine del container. La bozza porta un’immagine solo dove il template la dichiara in una proprietà che la bozza colloca. Questo template la scrive in linuxFxVersion, quindi la bozza non ne porta alcuna, e la build si ferma indicando infra.image: l’immagine sei tu a doverla fornire nella Release.

Un modulo per cui la libreria standard non associa nulla viene conservato per intero. Dove un template distribuisce un modulo di Azure Verified Modules di un tipo di risorsa che nessuna riga dell’importer associa, l’importazione redige un Component e una Recipe che reperiscono il modulo come oci://mcr.microsoft.com/bicep/<path> con la telemetria disattivata, e un parametro del modulo alimentato da un secret viene omesso e segnalato con un avviso. Una risorsa di un tipo che nessuna riga associa viene redatta dal template come lo è la web app statica; il suggerimento di scambio delle bozze indica aggrega import --format arm-schema, che redige lo stesso Component dallo schema del fornitore, come descrive Distribuire un servizio che il catalogo non ha.

Una stringa scritta su più righe

JSON non ammette un’interruzione di riga grezza dentro una stringa, e l’importer legge il template come JSON. Un template che ne contiene una — uno script scritto su più righe in un valore scriptContent — non viene riconosciuto, perché la lettura fallisce:

[E0350]
no importer recognises the source (source "main.json"). Pass --format to name it explicitly (for example --format agent-framework, --format arm-schema, --format arm, --format cloudformation-schema, --format compose, --format crewai, --format dify, --format flowise, --format google-adk, --format langflow, --format langgraph, --format mcp, --format n8n or --format terraform-schema)

e con --format arm, l’importazione si ferma indicando il punto:

halt: could not parse source "main.json" as arm: json parse: invalid character '\n' in string literal at line 14, column 35

Scrivi ogni stringa su una sola riga, con \n dove il testo va a capo, e l’importazione la legge.