Bỏ qua để đến nội dung
AggregaAggregaAggregaAggrega
Chọn ngôn ngữ: Tiếng Việt
Trang này được dịch bằng máy. Đọc bản gốc tiếng Anh.

Nhập một template Azure Resource Manager

Hướng dẫn từng bước này nhập một template Azure Resource Manager nhỏ — một namespace Event Hubs được triển khai qua module Azure Verified Modules, một site App Service chạy container, một static web app và mạng ảo mà site dự định tham gia — rồi build kết quả thành một template Azure Resource Manager duy nhất. Lần nhập tạo bản nháp Aggregate, Release và Manifest: namespace và site trở thành các tham chiếu tới Components của thư viện chuẩn, static web app, vốn không có Component nào đại diện, được tạo bản nháp từ template, và các giá trị mà template nêu dưới dạng một Release có thể nhận được sẽ được đưa vào. Một vài giá trị mà nó không đưa vào được để lại cho bạn, và trang này chỉ ra giá trị nào và ở đâu. Mọi tệp và mọi khối đầu ra bên dưới đều đến từ một lần chạy thực; template và từng giai đoạn của hướng dẫn nằm trong ví dụ import-arm, nơi một script kiểm tra chạy lại lần nhập, so sánh những gì nó ghi, những gì nó in ra và các khối mà trang này trích dẫn với các tệp được lưu giữ ở đó, xác nhận bản nháp dừng đúng chỗ trang này nói, và build Release đã được xem xét.

Soạn bản nháp ví dụ

Bạn có thể chạy lần nhập này bằng các lệnh trên trang này, hoặc để trợ lý AI của bạn chạy giúp bạn.

Ghi ví dụ vào một thư mục mới đặt theo tên của nó:

Terminal window
aggrega draft --example import-arm

Sau đó nó in ra các lệnh cần chạy tiếp theo. Lệnh đầu tiên chuyển vào thư mục mới; lệnh tiếp sau đó, ở bên dưới, chuyển vào thư mục source của thư mục mới, nơi chứa những gì trang này nhập và là nơi chạy lệnh nhập:

Terminal window
cd import-arm

Template

main.json là dạng đã biên dịch của một template: JSON mà một lần build Bicep ghi ra, được Azure Resource Manager triển khai. Tham số của nó là vùng (region), và nó bắt đầu bằng một mạng ảo chứa subnet mà site tham gia:

{
"$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]

Namespace được triển khai qua module Azure Verified Modules avm/res/event-hub/namespace phiên bản 0.15.3: một resource Microsoft.Resources/deployments có thành viên template chứa template đã biên dịch riêng của module, hơn 3.700 dòng, và có parameters là những gì template đặt cho module:

{
"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]

Template đã biên dịch của module là bản mà Microsoft Container Registry phục vụ cho phiên bản đó, theo giấy phép MIT, và README của ví dụ có kèm thông báo. Lần nhập đọc nó để nhận ra module: tiền tố telemetry và phiên bản của nó nêu tên module Azure Verified Modules và loại resource mà nó triển khai.

Site là một resource thông thường. Nó chạy trên một App Service plan đã tồn tại, tham gia subnet của template, chạy container được nêu trong linuxFxVersion, đọc đầu ra name của module và đặt thêm một biến:

{
"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"
}
]
}
}
},

Static web app cũng là một resource thông thường. Bên cạnh template, một tệp tham số cung cấp tham số duy nhất:

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

Hai tệp nằm trong thư mục notes, và một .aggrega-config.yaml bên cạnh thư mục đó biến thư mục này thành một workspace, nên lần nhập ghi các bản nháp của nó ở đó:

# 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ần nhập đọc một template và tệp tham số của nó dưới dạng JSON có chú thích, nhận ra template qua $schema và resources của nó, và nhận ra tệp tham số qua $schema và parameters của nó. Nó cân nhắc từng resource so với các Components của danh mục workspace, mà nó đọc như Cách một lần nhập chạy mô tả, và không đọc tài khoản đám mây nào: một giá trị mà template tính trong lúc triển khai được mang theo dưới dạng biểu thức tính ra nó, không bao giờ được tra cứu.

Chuyển vào source:

Terminal window
cd source

Chạy lệnh nhập

Chỉ định thư mục chứa template. Importer nhận ra template và tệp tham số của nó qua nội dung của chúng:

Terminal window
aggrega import notes

Không có --target nào được chỉ định. Importer khai báo arm làm target mặc định, vì các Recipes của thư viện chuẩn cho Azure Resource Manager gắn với nó, và lần nhập tạo bản nháp Manifest cho target đó; một lần nhập chỉ định target, bằng --target, sẽ tạo bản nháp cho target kia thay vào đó. Bản ghi mà lần nhập ghi bên cạnh các bản nháp giữ lại target, và --sync dùng lại nó.

Trên đầu ra chuẩn, nó liệt kê những gì đã ghi:

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

Trên luồng lỗi chuẩn, với <workspace> đại diện cho thư mục nơi bạn đã chạy nó:

[… 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)
  • Các dòng info nêu những gì importer đã quyết định mà không cần hỏi. Dòng đầu cho biết các bản nháp dành cho arm. Dòng thứ hai nhận ra module: resource ehmodule là module Azure Verified Modules của namespace Event Hubs, và các tham số mà template đặt cho nó đọc như tham số của chính module, nên bản nháp xem nó là một namespace chứ không phải một template lồng nhau cần đọc. Dòng thứ ba cho biết static web app được tạo bản nháp từ template.
  • Các dòng warn nêu những gì bản nháp không mang theo. Dòng đầu là biến mà site đọc từ đầu ra name của module: bản nháp chỉ nối một kết nối cho những gì một Component công bố, và namespace không công bố khóa cho tên của nó, nên kết nối chỉ tồn tại vì sự phụ thuộc. Dòng thứ hai nêu mạng ảo mà template tạo, được bản nháp để lại cho bạn, như Những gì bản nháp để lại cho bạn giải thích. Dòng thứ ba nêu biến mà site đặt mà không kết nối nào của bản nháp chuyển giao.
  • Các dòng mapped cho biết mỗi resource đã trở thành gì. ehmodule là một thể hiện của core/messaging/azure-event-hubs thuộc thư viện chuẩn, và notes-api là một thể hiện của máy chủ chung, core/compute/server, mỗi cái khớp ở bậc cao và được tham chiếu. notes-site không khớp Component nào, nên nó là một bản nháp, không có kết quả khớp. Các dòng made no choice nêu những gì bản nháp không quyết định gì: mạng ảo, và con trỏ subnet mà Release để trống.
  • Bước pull là lần nhập lấy về những gì Release đã tạo bản nháp phụ thuộc vào, như aggrega pull làm, vào release.lock. Các Recipes mà Manifest nêu cho namespace và site tự ghi resource của chúng và không lấy gì từ nguồn, nên source_artifacts là 0 và bước pull không với tới thứ gì bên ngoài catalog. Sau đó lần nhập thử render Release để tìm các đầu vào mà bản build sẽ tải, và Recipe App Service chặn nó: bản nháp chưa nêu subnet nào. Lần nhập vẫn kết thúc, với lockfile đã được ghi, và cho biết các đầu vào bên ngoài chưa được phát hiện đầy đủ; điểm dừng đó chính là điểm dừng mà bước xác thực báo cáo tiếp theo.

Những gì được ghi

Aggregate, Release và Manifest được đặt tên imported/notes, theo thư mục mà lần nhập đã đọc — một template được nhập dưới dạng tệp thì được đặt tên theo tệp, main — dưới namespace mà thiết lập target_namespace của importer đặt ra, là imported trừ khi bạn đặt namespace khác (Thiết lập).

aggregate.yaml — một mục cho mỗi resource, và kết nối mà site vẽ ra:

# 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

Static web app là một thành phần thuộc một kiểu mà lần nhập đã soạn nháp, imported/compute/microsoft-web-staticsites. Kết nối của site tới namespace không có khối inject, vì bản nháp chỉ chuyển giao một biến từ một kết nối khi Component công bố giá trị đó, và chú thích phía trên nó nêu biến nào nó không nối và vì sao.

release.yaml — môi trường và các thiết lập của mỗi resource:

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: ""

Môi trường, development, là một giá trị mặc định mà lần nhập ghi vì không template nào nêu tên một môi trường. Tham số location của template đi vào các mục của static web app và của site dưới dạng giá trị mà tệp tham số cung cấp, northeurope. service_plan_id của site được mang theo như định danh nguyên văn mà template ghi. Mục của namespace để trống, và chú thích phía trên nó liệt kê các tham số module mà bản nháp không chuyển.

Một khóa để trống, và chú thích của nó giải thích lý do: virtual_network_subnet_id là một con trỏ tới một resource, mà các Recipes của thư viện chuẩn cho Azure Resource Manager nhận dưới dạng định danh nguyên văn /subscriptions/… của resource đó. Template viết subnet của site dưới dạng biểu thức resourceId nêu một resource của chính template, và một biểu thức không phải là định danh mà Recipe có thể nhận, nên bản nháp để trống khóa và nêu biểu thức trong một chú thích. Ngược lại, một resource được tạo bản nháp giữ nguyên vẹn mọi biểu thức của template.

Image container không có trong mục. Template viết nó bên trong linuxFxVersion, một thuộc tính mà bản nháp không đặt ở đâu cả, và chú thích phía trên mục liệt kê kind và linuxFxVersion trong số các thuộc tính mà nó không đặt.

manifest.yaml — Recipe mà mỗi thành phần được hiện thực hóa bằng trên 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

Static web app không có Component nào của thư viện chuẩn, nên lần nhập tạo bản nháp một Component cùng một Recipe dưới thư mục catalog của workspace: Component imported/compute/microsoft-web-staticsites khai báo name mà template đặt cho trang, một location và một đối tượng overrides cho mọi thuộc tính mà template viết, dưới tên riêng của nhà cung cấp, và Recipe microsoft-web-staticsites ghi một resource Microsoft.Web/staticSites thuộc loại và phiên bản API đó. Các bản nháp là những tệp thông thường để bạn đọc và chỉnh sửa:

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 ghi lại các thực thể danh mục mà Release đã phân giải tới, theo digest; .aggrega-import.json là bản ghi về những gì lần nhập đã ghi, được một lệnh aggrega import --sync sau đó đọc.

Xác thực

Terminal window
aggrega validate --release release.yaml

Bước xác thực dừng lại. Bản nháp không nêu subnet nào cho site, và Recipe App Service chỉ cho site tham gia một subnet của mạng riêng của bạn thông qua định danh của nó:

[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)

Một lời từ chối nêu những gì cần đổi và ở đâu, trong tài liệu mà bạn sửa. Ở đây đó là mục notes-api của release.yaml, và sau subnet, bản build nêu một giá trị thứ hai: image container. Template viết nó trong linuxFxVersion, mà bản nháp không đặt, và Recipe của máy chủ chung cho App Service không có image riêng, nên bản build dừng lại với thông báo rằng Release không đặt infra.image. Image do bạn cung cấp trong Release.

Chú thích của namespace liệt kê skuName, skuCapacity và location, mà module lấy từ template và bản nháp cũng không đặt. Không có chúng, các giá trị mặc định của chính Recipe được áp dụng; infra.overrides.sku_name, infra.overrides.sku_capacity và infra.overrides.location mang các giá trị của template. Thư mục reviewed của ví dụ chứa release.yaml với tất cả đã được viết:

# 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"

và mục của site, với image và 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"

Script kiểm tra của ví dụ build Release này, và xác nhận rằng bản nháp dừng với thông báo ở trên.

Build

Chuyển vào một thư mục chứa Release đã được xem xét, hoặc sửa release.yaml trong source theo cách tương tự, rồi build:

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

Release không còn khớp với release.lock mà lần nhập đã ghi, nên bản build cần --auto-pull, lệnh phân giải lại nó; không có nó, bản build dừng lại và nêu aggrega pull. Bước xác thực in ra:

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

và bản dựng, với <workspace> đại diện cho thư mục mà bạn đã chạy nó:

[… 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

Đọc arm-template.json

Bản build ghi một tệp, dist/arm/arm-template.json: template đã được lắp ráp, ở phiên bản ngôn ngữ 2.0, với một mục dưới resources cho mỗi resource mà một thành phần ghi, được đặt tên theo id thể hiện của thành phần đã chuyển thành các từ:

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

Mục của namespace chứa namespace mà Recipe ghi, với các thiết lập mà Release mang — tier, đơn vị thông lượng và vùng — còn phần còn lại là thiết lập của chính Recipe:

"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"
},

Mục của site mang plan, subnet, image dưới dạng container mà site chạy, và cổng mà máy chủ chung khai báo:

"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"
},

Site nhận WEBSITES_PORT và không có gì mà template đã đặt: EVENTHUB_NAMESPACE và EVENTHUB_NAME là các biến mà bản nháp không chuyển giao, được nêu tên bởi các dòng warn và các chú thích. Tên của namespace là ehmodule, tên của thành phần, trong khi template đặt tên nó là evh-notes: name của module do Recipe đặt, và chú thích phía trên mục liệt kê nó trong số các tham số mà bản nháp không chuyển.

Triển khai nó

Template là một template cấp resource group. Bản build không ghi tệp tham số và không chạy gì với Azure: các lệnh là việc của bạn. Xem trước những gì template sẽ thay đổi, rồi triển khai nó:

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

Trang provider ARM trình bày các lệnh này, stack không bao giờ xóa những gì nó thôi quản lý, và điều mà mỗi cờ quyết định. Trước khi template được triển khai, các resource mà Release nêu nhưng template không triển khai phải tồn tại: App Service plan và subnet mà site tham gia, được ủy quyền cho Microsoft.Web/serverFarms.

Với trợ lý AI

Một trợ lý AI được thiết lập với các công cụ của Aggrega có thể làm điều tương tự: dán prompt này vào nó.

Chỉ dùng các công cụ Aggrega, và không tự tạo thư mục nào. Nếu thư mục Workspace chưa có thư mục `import-arm`, hãy gọi công cụ `draft` một lần với `example` đặt thành `import-arm` và không có `dir`: nó ghi ví dụ vào một thư mục `import-arm` mới. Sau đó gọi công cụ `import` với `workspace_root` đặt thành `import-arm/source` và `source` đặt thành `notes`: nó ghi các bản nháp vào `import-arm/source` và kéo những gì chúng cần. Sau đó gọi công cụ `build` với `workspace_root` đặt thành `import-arm/reviewed`, `release` đặt thành `release.yaml`, `auto_pull` đặt thành true và `write` đặt thành true. Cho tôi biết bản build đã ghi những tệp nào; chúng nằm trong `import-arm/reviewed/dist/`.

Thư mục reviewed chứa bản nháp với các giá trị đã được ghi, như phần Xác thực liệt kê; để xem xét bản nháp của riêng bạn, hãy yêu cầu trợ lý xác thực import-arm/source trước và cho bạn biết nó dừng ở đâu.

Mở trong VS Code

Khi đã cài tiện ích mở rộng Aggrega cho Visual Studio Code, hãy mở thư mục import-arm/source trong VS Code, nơi lần nhập đã ghi các bản nháp. Thư mục chứa một Release, tức release.yaml được soạn nháp, vì vậy trình soạn thảo chọn nó cho bạn, và kiểm tra các bản nháp theo Release đó khi bạn chỉnh sửa, đánh dấu những gì nó tìm thấy trong tệp và trong bảng Problems. Aggrega: Show topology graph, trong Command Palette, vẽ các thành phần của Release và các kết nối giữa chúng. Aggrega: Build, Aggrega: Preview build và Aggrega: Pull hoạt động trên cùng Release đó, và mỗi lệnh cũng là một nút trên bảng Commands của chế độ xem Aggrega trong thanh hoạt động; Build ghi các tệp của nó vào dist/ của thư mục. Dùng Aggrega trong Visual Studio Code trình bày phần còn lại.

Khi template thay đổi

Giữ .aggrega-import.json bên cạnh các bản nháp, và sau khi template thay đổi hãy chạy:

Terminal window
aggrega import notes --sync

Nó đọc đích mà bản ghi lưu, arm, và chỉ thay đổi những gì quá trình nhập đã ghi. Sau khi outputLocation của static web app đổi từ dist sang build trong main.json, lần nhập cho biết:

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

và ghi release.yaml với đúng một dòng đó thay đổi; các giá trị bạn đã ghi bên cạnh nó giữ nguyên. Một phần mà nguồn không động đến vẫn giữ nguyên như trên đĩa, dù đã chỉnh sửa hay chưa; ở nơi nguồn thay đổi một phần mà bạn đã chỉnh sửa, nó dừng lại, nêu tên phần đó và không ghi gì, để bạn tự đối chiếu bằng tay. aggrega import mô tả đầy đủ các quy tắc và mọi cờ.

Một template có thể triển khai template khác qua một resource Microsoft.Resources/deployments mà templateLink.relativePath của nó nêu một tệp bên cạnh. Lần nhập đọc các template được liên kết bên trong thư mục được nhập: nó bắt đầu từ một template, gốc, đọc từng template mà gốc liên kết tới, và soạn nháp resource của tất cả chúng thành một Aggregate.

Một thư mục chứa nhiều template xác định gốc của nó theo việc cái nào liên kết tới cái nào: gốc là template duy nhất không template nào khác liên kết tới. Một thư mục chứa hai template không có liên kết giữa chúng thì không có một gốc duy nhất, và lần nhập dừng lại và nêu tên cả hai:

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

Thiết lập root nêu template để bắt đầu, trong mục của importer ở cấu hình workspace. uri nêu importer theo danh tính của nó và phiên bản trình biên dịch bạn đang chạy, như aggrega plugin add importer ghi (Importer nào biến một nguồn thành bản nháp):

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

Khi đặt root, lần nhập đọc site.json và các template mà nó liên kết, và bỏ network.json ra ngoài.

Một liên kết ra ngoài thư mục được nhập — ../shared/dns.json — không được đọc: lần nhập không bao giờ mở một tệp nằm ngoài thư mục được giao. Nó đưa ra cảnh báo, nêu resource và đường dẫn, và soạn nháp resource đó thành một resource riêng, mang mỗi đầu ra của template đó mà template đọc dưới dạng biểu thức đánh giá nó khi template được triển khai:

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

Đặt template được liên kết vào bên trong thư mục được nhập và lần nhập kế tiếp sẽ đọc nó.

Khi một tên đã bị dùng

Một resource mà bản nháp biến thành Component nhận tên mà lần nhập chọn cho nó, từ loại của nó: imported/compute/microsoft-web-staticsites cho static web app. Khi một Component có tên đó đã tồn tại trong một thư mục catalog của workspace hoặc trong hub, và lần nhập này không soạn nháp nó, lần nhập không ghi đè lên nó và không đoán. Nó giữ resource lại, không soạn nháp cũng không tham chiếu nó, và đưa ra cảnh báo. Nhập ví dụ lần thứ hai vào một thư mục khác của cùng workspace, với --output-dir second, sau khi lần nhập đầu ghi Component vào thư mục catalog của workspace, cho biết:

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

Thiết lập mapping_overrides của mục importer, được khóa theo định dạng, arm, rồi theo loại resource, ánh xạ loại đó tới Component đã tồn tại, và mục mà cảnh báo in ra chính là mục cần ghi (Thiết lập). Với nó, lần nhập kế tiếp tham chiếu Component: notes-site được ánh xạ như một tham chiếu, và mục của nó trong Release không có khóa nào ngoài một chú thích nêu các thuộc tính mà template ghi:

notes-site: {}

Component khai báo name và location bắt buộc và bản nháp không ghi cái nào, nên lần nhập kết thúc bằng việc báo từng cái là thiếu, với các bản nháp đã được ghi. Hãy ghi chúng, cùng các thuộc tính mà chú thích liệt kê, vào Release, như Component khai báo.

Bản nháp để lại gì cho bạn

Lần nhập soạn nháp những gì template nêu và những gì catalog của bạn xác định, và cho biết nó dừng ở đâu. Với một template, nó để lại những điều sau:

  • Nền tảng mà template tạo ra để phục vụ các thứ khác. Virtual network vnet-notes và subnet của nó tồn tại trong template cho site. Bản nháp không tạo mạng: một Component của catalog nhận mạng mà nó chạy trong đó qua resource ID của mạng, dưới infra.overrides, và mạng là của bạn. Dòng warn nêu từng resource như vậy, và các con trỏ từng tham chiếu tới nó là các khóa trống của Release. Nơi Release được triển khai, mạng và subnet đã tồn tại, hoặc bạn triển khai chúng cùng template bạn đã nhập.
  • Các giá trị mà bản nháp không đặt. Chú thích của mỗi mục Release liệt kê các tham số module và thuộc tính resource mà bản nháp không đặt, trong đó ở đây có tier, đơn vị thông lượng, vùng và tên của namespace, cùng kind và linuxFxVersion của site, nên thiết lập của template được nêu ra chứ không bị bỏ lặng lẽ. Khi một Component có chỗ cho một giá trị như vậy, bạn tự ghi nó, như phần Xác thực làm.
  • Các biến môi trường mà không kết nối nào truyền. EVENTHUB_NAMESPACE và EVENTHUB_NAME của site được nêu trong các chú thích của Aggregate và của Release và trong một dòng warn cho mỗi biến. Khi site được cấu hình trong Release, bạn đặt chúng.
  • Image container. Bản nháp chỉ mang một image khi template nêu nó trong một thuộc tính mà bản nháp đặt. Template này viết nó trong linuxFxVersion, nên bản nháp không mang gì, và bản build dừng lại, nêu infra.image: image do bạn cung cấp trong Release.

Một module mà thư viện chuẩn không ánh xạ gì được giữ nguyên toàn bộ. Khi một template triển khai module Azure Verified Modules của một loại resource mà không dòng nào của importer ánh xạ, lần nhập soạn nháp một Component và một Recipe lấy module đó từ oci://mcr.microsoft.com/bicep/<path> với telemetry tắt, và một tham số module được cấp bởi secret bị bỏ ra và có cảnh báo. Một resource của loại mà không dòng nào ánh xạ được soạn nháp từ template như static web app; gợi ý thay thế của các bản nháp nêu aggrega import --format arm-schema, lệnh soạn nháp cùng Component đó từ schema của nhà cung cấp, như Triển khai một dịch vụ mà catalog không có mô tả.

Một chuỗi được viết qua nhiều dòng

JSON không chấp nhận ngắt dòng thô bên trong một chuỗi, và importer đọc template dưới dạng JSON. Một template chứa một ngắt dòng như vậy — một script được viết qua nhiều dòng trong giá trị scriptContent — không được nhận diện, vì việc đọc nó thất bại:

[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)

và với --format arm, lần nhập dừng lại, nêu vị trí:

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

Hãy viết mỗi chuỗi trên một dòng, với \n ở chỗ văn bản ngắt, và lần nhập sẽ đọc được nó.