コンテンツにスキップ
AggregaAggregaAggregaAggrega
言語の選択: 日本語
このページは機械翻訳されています。英語の原文を読む。

Azure Resource Manager テンプレートのインポート

このウォークスルーでは、小さな Azure Resource Manager テンプレート(Azure Verified Modules のモジュールを通じてデプロイされる Event Hubs 名前空間、コンテナーを実行する App Service サイト、静的 Web アプリ、そのサイトが参加する予定の仮想ネットワーク)をインポートし、その結果を 1 つの Azure Resource Manager テンプレートとしてビルドします。インポートは Aggregate、Release、Manifest をドラフトします。名前空間とサイトは標準ライブラリの Components への参照になり、どの Component も該当しない静的 Web アプリはテンプレートからドラフトされ、テンプレートが Release で扱える形で記述している値は引き継がれます。そうでない一部の値は作成者に任され、どの値がどこにあるかはこのページで示します。以下のすべてのファイルとすべての出力ブロックは実際の実行から得たものです。テンプレートとウォークスルーの各段階は import-arm の例にあり、そこではチェックスクリプトがインポートを再度実行し、書き込んだ内容、出力した内容、このページが引用するブロックを、そこに保存されたファイルと比較し、ドラフトがこのページの述べる箇所で停止することを確認し、レビュー済みの Release をビルドします。

サンプルのドラフトを作成する

このインポートは、このページのコマンドで実行することも、AI アシスタントに実行させることもできます。

例の名前を付けた新しいフォルダーに例を書き出します。

Terminal window
aggrega draft --example import-arm

その後、次に実行するコマンドを表示します。最初のコマンドは新しいフォルダーに移動します。それに続く以下のコマンドは、新しいフォルダーの source フォルダーに移動します。このフォルダーには、このページがインポートするものが入っており、インポートはここで実行します:

Terminal window
cd import-arm

テンプレート

main.json はテンプレートのコンパイル済みの形式で、Bicep のビルドが書き出す JSON であり、Azure Resource Manager がデプロイします。パラメーターはリージョンで、サイトが参加するサブネットを持つ仮想ネットワークから始まります:

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

Event Hubs 名前空間は、Azure Verified Modules のモジュール avm/res/event-hub/namespace の 0.15.3 を通じてデプロイされます。これは Microsoft.Resources/deployments リソースで、その template メンバーにはモジュール自身のコンパイル済みテンプレート(3,700 行を超えます)が入っており、parameters はテンプレートがそのモジュールに設定する値です:

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

モジュールのコンパイル済みテンプレートは、Microsoft Container Registry がそのバージョンとして提供しているもので、MIT ライセンスです。例の README に通知が記載されています。インポートはモジュールを認識するためにこれを読み取ります。そのテレメトリのプレフィックスとバージョンが、Azure Verified Modules のモジュールと、それがデプロイするリソースタイプを示します。

サイトは通常のリソースです。すでに存在する App Service プランで実行され、テンプレートのサブネットに参加し、linuxFxVersion に指定されたコンテナーを実行し、モジュールの name 出力を読み取り、変数をもう 1 つ設定します:

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

静的 Web アプリも通常のリソースです。テンプレートの隣にあるパラメーターファイルが、唯一のパラメーターを提供します:

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

2 つのファイルはフォルダー notes にあり、そのフォルダーの隣にある .aggrega-config.yaml がこのディレクトリをワークスペースにするため、インポートはドラフトをそこに書き込みます。

# 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

インポートは、テンプレートとそのパラメーターファイルをコメント付き JSON として読み取り、テンプレートは $schema と resources によって、パラメーターファイルは $schema と parameters によって認識します。各リソースを、インポートの実行の仕組みの説明どおりに読み取ったワークスペースのカタログの Components と照らして評価します。クラウドアカウントは読み取りません。デプロイ中にテンプレートが計算する値は、それを計算する式のまま引き継がれ、参照して取得されることはありません。

source に移動します:

Terminal window
cd source

インポートを実行する

テンプレートを保持するフォルダーを指定します。インポーターは、テンプレートとそのパラメーターファイルをそれぞれの内容から認識します。

Terminal window
aggrega import notes

--target は指定していません。標準ライブラリの Azure Resource Manager 向け Recipes がそれに結び付いているため、インポーターは arm を既定のターゲットとして宣言しており、インポートはそのための Manifest をドラフトします。--target でターゲットを指定したインポートは、代わりにそのターゲット向けにドラフトします。インポートがドラフトの隣に書き込む記録にはターゲットが保持され、--sync はそれを再利用します。

標準出力には書き出したものが一覧表示されます:

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

標準エラーには次のように出力されます(<workspace> は実行したフォルダーを表します):

[… 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)
  • info 行は、インポーターが確認なしに決めたことを示します。1 行目は、ドラフトが arm 向けであることを示します。2 行目はモジュールを認識したことを示します。リソース ehmodule は Event Hubs 名前空間の Azure Verified Modules のモジュールであり、テンプレートがそれに設定するパラメーターはモジュール自身のものと読めるため、ドラフトはこれを、読み取るべき入れ子のテンプレートではなく 1 つの名前空間として扱います。3 行目は、静的 Web アプリがテンプレートからドラフトされることを示します。
  • warn 行は、ドラフトが引き継がないものを示します。1 行目は、サイトがモジュールの name 出力から読み取る変数です。ドラフトは Component が公開するものについてのみ接続を配線しますが、名前空間はその名前のためのキーを公開しないため、接続は依存関係のためだけに存在します。2 行目は、テンプレートが作成する仮想ネットワークを示しており、ドラフトが任せるもので説明するとおり、ドラフトはこれを作成者に委ねます。3 行目は、サイトが設定する変数のうち、ドラフトのどの接続も渡さないものを示します。
  • mapped 行は、各リソースが何になったかを示します。ehmodule は標準ライブラリの core/messaging/azure-event-hubs のインスタンスであり、notes-api は汎用サーバー core/compute/server のインスタンスです。どちらも高いティアで一致し、参照されています。notes-site はどの Component にも一致しないため、一致なしのドラフトになります。made no choice 行は、ドラフトが何も決めないものを示します。仮想ネットワークと、Release が空のままにするサブネットのポインターです。
  • プルは、aggrega pull と同じように、ドラフトされた Release が依存するものをインポートが取得して release.lock に書き込む処理です。Manifest が名前空間とサイトに指定する Recipes は、自分でリソースを書き込み、何もソースとして取得しないため、source_artifacts は 0 であり、プルはカタログの外に何も取りにいきません。その後、インポートはビルドが取得する入力を見つけるために Release のレンダリングを試みますが、App Service の Recipe がこれを停止させます。ドラフトにはまだサブネットが指定されていないためです。それでもインポートは、ロックファイルを書き込んだうえで終了し、外部入力が完全には検出されなかったことを報告します。この停止は、次に検証が報告するものと同じです。

書き出される内容

Aggregate、Release、Manifest の名前は imported/notes で、インポートが読み取ったフォルダーにちなんでいます。ファイルとしてインポートされたテンプレートは、そのファイル名 main にちなんで名付けられます。名前空間は、インポーターの target_namespace 設定が定めるもので、別のものを設定しない限り imported です(設定)。

aggregate.yaml — リソースごとに 1 エントリと、サイトが描く接続:

# 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

静的 Web アプリは、インポートがドラフトした型 imported/compute/microsoft-web-staticsites のコンポーネントです。サイトから名前空間への接続には inject ブロックがありません。ドラフトは、Component が値を公開する場合にのみ接続から変数を渡すためで、その上のコメントには、どの変数を配線しないか、およびその理由が書かれています。

release.yaml — 環境と、各リソースの設定:

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

環境 development は、テンプレートが環境を指定していないためインポートが書き込む既定値です。テンプレートの location パラメーターは、パラメーターファイルが提供する値 northeurope として、静的 Web アプリとサイトのエントリに渡ります。サイトの service_plan_id は、テンプレートが書いているリテラルな識別子としてそのまま引き継がれます。名前空間のエントリは空で、その上のコメントには、ドラフトが変換しないモジュールパラメーターが列挙されています。

1 つのキーが空であり、そのコメントが理由を説明しています。virtual_network_subnet_id はリソースへのポインターで、標準ライブラリの Azure Resource Manager 向け Recipes は、これをリソースのリテラルな /subscriptions/… 識別子として受け取ります。テンプレートはサイトのサブネットを、テンプレート自身のリソースを指す resourceId 式として記述しており、式は Recipe が受け取れる識別子ではないため、ドラフトはキーを空のままにし、式をコメントに記します。一方、ドラフトされたリソースは、テンプレートの式をすべてそのまま保持します。

コンテナーイメージはエントリにありません。テンプレートはこれを linuxFxVersion の中に書いており、ドラフトはこのプロパティをどこにも配置しません。エントリの上のコメントは、配置しないプロパティとして kind と linuxFxVersion を挙げています。

manifest.yaml — arm 上で各コンポーネントを実現する Recipe:

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

静的 Web アプリには標準ライブラリの Component がないため、インポートはワークスペースの catalog フォルダーの下に、Recipe 付きで 1 つドラフトします。Component imported/compute/microsoft-web-staticsites は、テンプレートがサイトに与える name、location、そしてテンプレートが記述するすべてのプロパティを、ベンダー自身の名前で持つ overrides オブジェクトを宣言します。Recipe microsoft-web-staticsites は、そのタイプと API バージョンの Microsoft.Web/staticSites リソースを 1 つ書き出します。ドラフトは、読んで編集できる通常のファイルです。

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 は、Release が解決したカタログエンティティをダイジェスト付きで記録します。.aggrega-import.json はインポートが書き出した内容の記録で、後の aggrega import --sync がこれを読み取ります。

検証

Terminal window
aggrega validate --release release.yaml

検証は停止します。ドラフトにはサイトのサブネットが指定されておらず、App Service の Recipe は、サイトを作成者自身のネットワークのサブネットに、その識別子によってのみ参加させるためです:

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

拒否は、変更すべき内容と場所を、変更するドキュメント内で示します。ここでは release.yaml の notes-api エントリであり、サブネットの次にビルドは 2 つ目の値であるコンテナーイメージを示します。テンプレートはこれを、ドラフトが配置しない linuxFxVersion に書いており、App Service 向けの汎用サーバーの Recipe は独自のイメージを持たないため、ビルドは、Release が infra.image を設定していないというメッセージとともに停止します。イメージは Release で作成者が指定します。

名前空間のコメントには skuName、skuCapacity、location が列挙されています。これらはモジュールがテンプレートから受け取る値ですが、ドラフトはこれらも配置しません。これらがない場合は Recipe 自身の既定値が使われ、テンプレートの値は infra.overrides.sku_name、infra.overrides.sku_capacity、infra.overrides.location が引き継ぎます。例の reviewed フォルダーには、これらをすべて書き込んだ release.yaml があります:

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

そして、イメージとサブネットを含むサイトのエントリです:

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

例のチェックスクリプトは、この Release をビルドし、ドラフトが上記のメッセージで停止することを確認します。

ビルド

レビュー済みの Release を保持するフォルダーに移動するか、source の release.yaml を同じように編集して、ビルドします。

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

Release はインポートが書き込んだ release.lock と一致しなくなっているため、ビルドには、これを再解決する --auto-pull が必要です。これがない場合、ビルドは停止し、aggrega pull を名指しします。検証は次のように出力します。

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

そしてビルドは次のとおりです(<workspace> は実行したフォルダーを表します):

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

arm-template.json を読む

ビルドは 1 つのファイル dist/arm/arm-template.json を書き出します。これは組み立てられたテンプレートで、言語バージョンは 2.0 であり、resources の下にコンポーネントが書き出すリソースごとに 1 つのエントリがあります。エントリ名は、コンポーネントのインスタンス ID を単語にまとめたものです:

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

名前空間のエントリには、Recipe が書き出す名前空間が入っており、Release が持つ設定(ティア、スループットユニット、リージョン)が反映され、残りは 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"
},

サイトのエントリには、プラン、サブネット、サイトが実行するコンテナーとしてのイメージ、汎用サーバーが宣言するポートが入っています:

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

サイトが受け取るのは WEBSITES_PORT だけで、テンプレートが設定したものは含まれません。EVENTHUB_NAMESPACE と EVENTHUB_NAME はドラフトが渡さなかった変数で、warn 行とコメントがそれらを示しています。名前空間の名前は、テンプレートでは evh-notes でしたが、ここではコンポーネントの名前である ehmodule になっています。モジュールの name は Recipe が設定するもので、エントリの上のコメントは、ドラフトが変換しないパラメーターの 1 つとしてこれを挙げています。

デプロイする

このテンプレートはリソースグループのテンプレートです。ビルドはパラメーターファイルを書き出さず、Azure に対して何も実行しません。コマンドの実行はユーザー自身が行います。まずテンプレートが何を変更するかをプレビューし、その後デプロイします:

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

ARM プロバイダーのページに、これらのコマンド、管理を止めたものを削除しないスタック、各フラグが決めることが説明されています。テンプレートをデプロイする前に、Release が名指ししていてもテンプレートがデプロイしないリソースが存在している必要があります。サイトが参加する App Service プランとサブネットで、サブネットは Microsoft.Web/serverFarms に委任されています。

AI アシスタントを使う

Aggrega のツールでセットアップした AI アシスタントでも同じことができます。次のプロンプトを貼り付けてください。

Aggrega のツールだけを使い、フォルダは自分で作成しないでください。Workspace フォルダにまだ `import-arm` フォルダがない場合は、`draft` ツールを `example` を `import-arm` に設定し、`dir` を指定せずに 1 回呼び出してください。これにより例が新しい `import-arm` フォルダに書き込まれます。次に、`import` ツールを `workspace_root` を `import-arm/source`、`source` を `notes` に設定して呼び出してください。これはドラフトを `import-arm/source` に書き込み、ドラフトが必要とするものをプルします。次に、`build` ツールを `workspace_root` を `import-arm/reviewed`、`release` を `release.yaml`、`auto_pull` を true、`write` を true に設定して呼び出してください。ビルドが書き出したファイルを教えてください。それらは `import-arm/reviewed/dist/` の下にあります。

reviewed フォルダーには、検証に挙げた値を書き込んだドラフトが入っています。ご自身のドラフトをレビューするには、まずアシスタントに import-arm/source を検証させ、どこで停止するかを教えてもらってください。

VS Code で開く

Visual Studio Code 用の Aggrega 拡張機能をインストールした状態で、インポートがドラフトを書き込んだフォルダ import-arm/source を VS Code で開きます。このフォルダには Release が 1 つ、ドラフトされた release.yaml だけがあるため、エディターがそれを自動で選択し、ドラフトを編集するたびにその Release に照らしてチェックして、見つかった内容をファイル内と問題パネルに表示します。コマンドパレットの Aggrega: Show topology graph は、Release のコンポーネントとそれらの間の接続を描画します。Aggrega: Build、Aggrega: Preview build、Aggrega: Pull は同じ Release に対して動作し、それぞれアクティビティバーの Aggrega ビューにある Commands パネルのボタンとしても使えます。Build はフォルダの dist/ にファイルを書き出します。その他については Visual Studio Code で Aggrega を使うを参照してください。

テンプレートが変更されたとき

.aggrega-import.json をドラフトの隣に残しておき、テンプレートが変更されたら次を実行します:

Terminal window
aggrega import notes --sync

記録が保持しているターゲット arm を読み取り、インポートが書き込んだものだけを変更します。main.json で静的 Web アプリの outputLocation が dist から build に変わると、インポートは次のように表示します:

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

そして、その 1 行だけを変更した release.yaml を書き出します。その隣に書いた値はそのまま残ります。ソースが変更しなかった部分は、編集されているかどうかにかかわらずディスク上のまま残ります。編集済みの部分をソースが変更した場合は、停止してその部分を示し、何も書き込まないため、手作業で調整します。ルールとすべてのフラグの詳細は aggrega import に説明されています。

テンプレートは、templateLink.relativePath が隣にあるファイルを指す Microsoft.Resources/deployments リソースを通じて、別のテンプレートをデプロイできます。インポートは、インポートしたディレクトリ内のリンクされたテンプレートを読み取ります。1 つのテンプレートであるルートから始め、ルートがリンクする各テンプレートを読み取り、それらすべてのリソースを 1 つの Aggregate としてドラフトします。

複数のテンプレートを含むディレクトリでは、どれがどれにリンクしているかによってルートが決まります。ルートとは、ほかのどのテンプレートからもリンクされていない 1 つのテンプレートです。リンクのない 2 つのテンプレートを含むディレクトリには 1 つのルートがなく、インポートは停止して両方を示します:

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

root 設定は、ワークスペース設定のインポーターのエントリで、開始するテンプレートを指定します。uri は、インポーターをその識別子と、実行中のコンパイラのバージョンで指定します。これは aggrega plugin add importer が書き込む形式です(どのインポーターがソースをドラフトに変換するか):

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

root を設定すると、インポートは site.json とそれがリンクするテンプレートを読み取り、network.json は読み取りません。

インポートしたディレクトリの外へ出るリンク(../shared/dns.json)は読み取られません。インポートは、渡されたディレクトリの外にあるファイルを決して開きません。リソースとパスを示して警告し、そのリソースを独立した 1 つのリソースとしてドラフトします。そのテンプレートの各出力のうちテンプレートが読み取るものは、テンプレートのデプロイ時にそれを評価する式として引き継がれます:

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

リンクされたテンプレートをインポートするディレクトリの中に置けば、次のインポートで読み取られます。

名前がすでに使われているとき

ドラフトが Component にするリソースには、インポートがその型から選ぶ名前が付きます。静的 Web アプリの場合は imported/compute/microsoft-web-staticsites です。その名前の Component がすでにワークスペースのカタログフォルダまたは hub に存在し、今回のインポートがドラフトしたものではない場合、インポートはそれを上書きせず、推測もしません。そのリソースを保留し、ドラフトも参照もせずに警告します。最初のインポートが Component をワークスペースの catalog フォルダに書き込んだ後、同じワークスペースの別のフォルダに --output-dir second を付けて例を 2 回目にインポートすると、次のようになります:

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

インポーターのエントリの mapping_overrides 設定は、フォーマット arm、次いでリソースタイプをキーとして、そのタイプを既存の Component に対応付けます。警告が表示するエントリが、書くべきものです(設定)。これを設定すると、次のインポートはその Component を参照します。notes-site は参照としてマッピングされ、Release 内のそのエントリには、テンプレートが書くプロパティを示すコメント以外にキーはありません:

notes-site: {}

Component は必須の name と location を宣言していますが、ドラフトはどちらも書き込まないため、インポートはドラフトを書き込んだうえで、それぞれが不足していると報告して終了します。これらと、コメントが挙げるプロパティを、Component の宣言どおりに Release に書いてください。

ドラフトに残される作業

インポートは、テンプレートが記述している内容とカタログが決定する内容をドラフトし、どこで停止したかを示します。テンプレートについては、次のものが残されます:

  • テンプレートが他のものに提供するために作成する基盤。 仮想ネットワーク vnet-notes とそのサブネットは、サイトのためにテンプレート内に存在します。ドラフトはネットワークを作成しません。カタログの Component は、実行されるネットワークを infra.overrides の下でリソース ID によって受け取り、そのネットワークはユーザー側のものです。warn 行はそのようなリソースをそれぞれ示し、それを参照していたポインターは Release の空のキーになります。Release のデプロイ先では、ネットワークとサブネットがすでに存在しているか、インポートしたテンプレートでデプロイします。
  • ドラフトが配置しない値。 Release の各エントリのコメントには、ドラフトが配置しないモジュールパラメーターとリソースプロパティが列挙されています。ここでは名前空間のティア、スループットユニット、リージョン、名前と、サイトの kind と linuxFxVersion がそれに当たります。これにより、テンプレートの設定は黙って破棄されることなく明示されます。Component にそれを置く場所がある場合は、検証のセクションが行っているように、ユーザーが書き込みます。
  • どの接続も渡さない環境変数。 サイトの EVENTHUB_NAMESPACE と EVENTHUB_NAME は、Aggregate と Release のコメントに示され、それぞれ warn 行にも示されています。サイトが Release で設定される場合は、これらをユーザーが設定します。
  • コンテナーイメージ。 ドラフトがイメージを引き継ぐのは、テンプレートがドラフトの配置するプロパティでイメージを指定している場合だけです。このテンプレートはイメージを linuxFxVersion に書いているため、ドラフトは何も引き継がず、ビルドは infra.image を示して停止します。イメージは Release でユーザーが指定します。

標準ライブラリが何もマッピングしないモジュールは、そのまま保持されます。テンプレートが、インポーターのどの行もマッピングしていないリソースタイプの Azure Verified Modules モジュールをデプロイする場合、インポートは、そのモジュールを oci://mcr.microsoft.com/bicep/<path> としてソースとし、テレメトリをオフにした Component と Recipe をドラフトします。シークレットから値を受け取るモジュールパラメーターは省かれ、警告されます。どの行もマッピングしていないタイプのリソースは、静的 Web アプリと同様にテンプレートからドラフトされます。ドラフトの切り替えのヒントには aggrega import --format arm-schema が示されており、これはカタログにないサービスをデプロイするで説明しているとおり、同じ Component をベンダーのスキーマから代わりにドラフトします。

複数行にまたがって書かれた文字列

JSON では文字列の中に生の改行を含められず、インポーターはテンプレートを JSON として読み取ります。生の改行を含むテンプレート(scriptContent の値に複数行にわたって書かれたスクリプトなど)は、読み取りに失敗するため認識されません:

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

そして --format arm を指定すると、インポートは場所を示して停止します:

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

各文字列を 1 行に書き、テキストが改行される位置に \n を入れれば、インポートで読み取られます。