カタログにないサービスをデプロイする
カタログに、あるクラウドサービスの Component がない場合は、そのサービスのリソースタイプについてベンダー自身が公開している記述で代用できます。aggrega import はその記述(クラウドベンダーがリソースタイプ向けに公開しているスキーマ)を読み取り、そこから 2 つのファイルをドラフトします。1 つは、そのタイプの設定を Aggrega が読み取るピラーで宣言する Component、もう 1 つは、そのタイプのリソースをちょうど 1 つ書き出すことで、その Component をプロバイダー向けに実現する Recipe です。ドラフトをレビューし、それらを使う記述を Aggregate と Release に追加して、ビルドします。
3 つのフォーマットを読み取ります。それぞれを担当するコアインポーターが読み込みます。
| フォーマット | エクスポートするスキーマ | Recipe のプロバイダー |
|---|---|---|
cloudformation-schema | CloudFormation のリソースタイプ。aws cloudformation describe-type またはプロバイダースキーマファイルから取得します | cloudformation |
terraform-schema | Terraform または OpenTofu プロバイダーのスキーマ。terraform providers schema -json から取得します | terraform |
arm-schema | Azure リソースプロバイダーの Bicep タイプファイル types.json | arm |
このページでは Azure の場合を最初から最後まで通して説明し、続いて CloudFormation と Terraform の場合、およびカタログがすでに保持している Component に対して Recipe だけをドラフトするバリエーションを示します。以下の Azure の部分のコマンドと出力は、これらのインポーターと arm プロバイダーを搭載したコンパイラのリリースのビルドを実行したときのものです。
こちらで勝手に取得されるものはありません。スキーマはベンダー自身のツールでエクスポートするため、インポートは手元にあるファイルを読み取り、クラウドアカウントにはアクセスしません。
スキーマをエクスポートする
各ベンダーのツールは、スキーマをファイルに書き出します。使用するクラウド向けのツールを、ワークスペースの中で実行します。
# CloudFormation: any registered type, third-party and private ones included.aws cloudformation describe-type --type RESOURCE --type-name AWS::SQS::Queue > sqs-queue.json
# Terraform or OpenTofu: in a directory whose configuration requires the provider.terraform init && terraform providers schema -json > schema.json
# Azure: no export is needed. Bicep's type files are published in the# Azure/bicep-types-az repository, one for each resource provider and API# version, at generated/<namespace>/<provider>/<apiVersion>/types.json.以下の Azure の場合は、API バージョン 2024-11-30 の Microsoft.ManagedIdentity のファイルを使います。このファイルは、Bicep が付ける名前 types.json のまま、msi という名前のフォルダーに置かれています。
Azure のスキーマファイルとそのライセンス
2024-11-30 の Microsoft.ManagedIdentity の types.json は、Azure/bicep-types-az リポジトリのファイルです。著作権は Microsoft Corporation にあり、MIT License のもとで配布されています。以下のドラフトが引用する説明文は Microsoft のものであり、ライセンスの表示がそれらに適用されます。
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWAREワークスペースは、workspace キーを持つ .aggrega-config.yaml があるフォルダーで、そのファイルを置いた msi フォルダーを含みます。
.aggrega-config.yamlmsi/types.jsonドラフトするタイプを一覧表示する
1 つのスキーマファイルに複数のリソースタイプが含まれることがあり、インポートは指定したものだけをドラフトします。ファイルに含まれるものを一覧表示します。
jq -r '.[] | select(."$type" == "ResourceType") | .name' msi/types.jsonMicrosoft.ManagedIdentity/userAssignedIdentities@2024-11-30Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials@2024-11-30Microsoft.ManagedIdentity/identities@2024-11-30次に、.aggrega-config.yaml のインポーターのエントリの resource_types 設定に、必要なものを指定します。どのワークスペースもすでにこのインポーターを提供しているため、このエントリが必要になるのは resource_types を渡すときだけです。その uri はインポーターと、aggrega version が表示するコンパイラのバージョンを指定します。インポーターは、このようなエントリを通じて設定を受け取ります。詳しくはソースをドラフトに変換するインポーターを参照してください。
workspace: {}default_registry: hub.aggrega.aiplugins: importer: - uri: importer/arm-schema:<compiler version> with: settings: resource_types: - Microsoft.ManagedIdentity/userAssignedIdentities名前は、CloudFormation(AWS::SQS::Queue)と Terraform(aws_sqs_queue)では完全一致で、Azure では大文字小文字を区別せずに照合されます。Azure では、名前の後ろに @ に続けて API バージョンを付けることができます。ちょうど 1 つのタイプを含むファイルには一覧は不要です。複数のタイプを含み、一覧のないファイルをインポートすると、インポートは停止してそれらの名前を示します。
halt: the sources hold 3 resource types and the resource_types setting names none: write the types to draft in it, one of Microsoft.ManagedIdentity/userAssignedIdentities, Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials, Microsoft.ManagedIdentity/identities一覧に挙げたタイプがファイルに含まれていない場合も、インポートは停止し、ファイルに含まれている最も近い名前を示します。停止した場合は何もドラフトされないため、ファイルは書き込まれません。
インポートを実行する
フォルダーまたはファイルを指定します。
aggrega import msi標準出力には書き出したものが一覧表示されます:
wrote catalog/component/imported/security/microsoft-managedidentity-userassignedidentities/0.1.0/component.yamlwrote catalog/recipe/arm/microsoft-managedidentity-userassignedidentities/0.1.0/recipe.yamlwrote .aggrega-import.json標準エラーには次のように出力されます(<workspace> は実行したフォルダーを表します):
read as the arm-schema format, with drafted paths relative to <workspace>mapped Microsoft.ManagedIdentity/userAssignedIdentities@2024-11-30 (Microsoft.ManagedIdentity/userAssignedIdentities) to imported/security/microsoft-managedidentity-userassignedidentities as a draft, NONE at 0.05aggrega import は、Azure/bicep-types-az が付ける名前である types.json という名前の Bicep タイプファイルを認識します。別の名前のファイルには、--format arm-schema でフォーマットを指定します。--format は、プロバイダーの Terraform スキーマ全体のような大きなエクスポートを、インポートに先に認識させることなくインポートする方法でもあります。
mapped の行は、そのリソースタイプが、近いカタログ Component のない独自のドラフトになったことを示します。ドラフトはワークスペースがカタログとして読み込むフォルダー catalog/ の下に書き込まれるため、設定なしで次の検証とビルドから解決されます。記録 .aggrega-import.json がそれらを一覧にしているため、aggrega import --sync は、あなたが加えた編集を上書きすることなく、スキーマの変更に合わせてそれらを更新できます。
ドラフトの内容
Component component.yaml は、リソースタイプの各プロパティを 1 つのピラーに振り分け、各キーの横のコメントがそれを配置した規則を示します。
- 読み戻しプロパティ、つまりクラウドが設定し、あなたが設定できないものは、入力ではありません。スカラーは、コンシューマーが読み取れる
providesキーになります。 - シークレットは、値の取得元への参照としてドラフトされ、値そのものとしては決してドラフトされません。詳しくは下のシークレットを参照してください。
- リソースが置かれる場所を表す配置、たとえば Azure の
locationは、オペレーターが環境ごとに指定するピラーであるinfraに入ります。 - リソース自身の名前である識別情報は、開発者が記述するピラーである
valuesに入ります。 - その他の必須プロパティは
infraに入ります。 - その他の書き込み可能なプロパティはすべて
infra.overridesの下に入ります。これは、各名前をベンダー自身の綴りのまま保持するオープンなマップです。
このリソースタイプでは、Component は次のようになります。
apiVersion: aggrega.ai/v1beta1kind: Componentmetadata: name: imported/security/microsoft-managedidentity-userassignedidentities version: 0.1.0 description: "Draft Component of the resource type Microsoft.ManagedIdentity/userAssignedIdentities@2024-11-30, imported from a source in the arm-schema format." labels: component.aggrega.ai/type: resource component.aggrega.ai/category: security component.aggrega.ai/hosting: managedspec: schema: values: type: object properties: # identity: the resource's own name or identifier # [vendor schema text] The resource name name: type: string description: "[vendor schema text] The resource name" required: true additionalProperties: false infra: type: object properties: # placement: where the resource is deployed # [vendor schema text] The geo-location where the resource lives location: type: string description: "[vendor schema text] The geo-location where the resource lives" 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.ManagedIdentity/userAssignedIdentities@2024-11-30, 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 provides: type: object properties: # read back: published under provides # [vendor schema text] The resource id id: type: string description: "[vendor schema text] The resource id" # … client_id, principal_id and tenant_id, each read back the same way additionalProperties: falseドラフトがベンダーのスキーマから取り込んだテキストはすべて [vendor schema text] で始まるため、Component がワークスペースの外に出る前に、それらを見つけて自分の言葉で書き直せます。インポートが組み立てたテキストにはマーカーが付きません。
Recipe recipe.yaml は、arm プロバイダー上で Component を実現します。そのヘッダーコメントは、読み取るすべてのキーを規則と型とともに一覧にし、読み取らないものも示します。
spec: # This Recipe realizes imported/security/microsoft-managedidentity-userassignedidentities with one resource of the type Microsoft.ManagedIdentity/userAssignedIdentities@2024-11-30. It reads the keys below, each with its type, its rule and the first sentence of the vendor's description; any other key under infra.overrides halts the build naming it. # infra.location: string, required; placement: where the resource is deployed # [… omitted: the first sentence of the vendor's description of the key above, marked as vendor schema text, as below each key] # values.name: string, required; identity: the resource's own name or identifier # [… omitted: the vendor's description of the key] # infra.overrides.tags: object; override: writable, set under infra.overrides in the vendor's spelling # [… omitted: the vendor's description of the key] # infra.overrides.isolationScope: string; override: writable, set under infra.overrides in the vendor's spelling # [… omitted: the vendor's description of the key, then a line saying template.yaml declares the resource under the symbolic name locals.symbol holds] capability: arm implements: imported/security/microsoft-managedidentity-userassignedidentities:0.1.0 locals: # [… omitted: a comment saying what the symbolic name is made of] symbol: "{{ capitalizedWords .context.instance_id }}" provides: # [… omitted: a comment saying each value is one whole ARM expression, evaluated when the template is deployed] id: "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities'{{ range splitList \"/\" (toString (index .values \"name\")) }}, '{{ replace \"'\" \"''\" . }}'{{ end }})]" client_id: "[reference('{{ .locals.symbol }}').clientId]" # … principal_id and tenant_id the same way assertions: overrides_this_recipe_reads: | # halts naming any key under infra.overrides the header does not list artifacts: template.yaml: | # … the resource, written under the symbolic name locals.symbol holdsRecipe が書き出すリソースは、そのタイプが指定する 1 つだけで、それ以外は何も書き出しません。リソースグループも、ネットワークも、宣言していない識別情報もありません。各 provides の値は、テンプレートのデプロイ時に Azure が評価する式全体で、文字列そのままの形でコンシューマーに渡されます。ヘッダーに一覧のない infra.overrides のキーがあると、ビルドはそのキーの名前を示して停止するため、綴りを間違えた設定は何かがデプロイされる前に見つかります。
ビルドする前に、両方のファイルをレビューしてください。設定をピラー間で移動することは、Component と、Recipe によるその読み取りの編集であり、ファイルはあなたのものです。ビルドが依存するものは、他の場所には保持されていません。
ドラフトを Aggregate と Release で使う
インポートは Aggregate も Manifest も Release もドラフトしないため、ドラフトされた Component を使う記述はあなたが書きます。Aggregate aggregate.yaml には、ドラフトされたタイプの component を 1 つ書き、values ピラーが保持する識別情報を持たせます。
apiVersion: aggrega.ai/v1beta1kind: Aggregatemetadata: name: identities version: 1.0.0spec: components: deploy-identity: type: imported/security/microsoft-managedidentity-userassignedidentities:0.1.0 values: name: deploy-identityManifest manifest.yaml には、どの Recipe がそのタイプを実現するかを示す 1 行を書きます。
apiVersion: aggrega.ai/v1beta1kind: Manifestmetadata: name: identities version: 1.0.0spec: mappings: components: type: imported/security/microsoft-managedidentity-userassignedidentities:0.1.0: arm/microsoft-managedidentity-userassignedidentities:0.1.0Release release.yaml には、component が置かれる境界と、Recipe が必要とする infra ピラー、つまり配置を書きます。
apiVersion: aggrega.ai/v1beta1kind: Releasemetadata: name: identities version: 1.0.0 environment: productionspec: aggregate: ./aggregate.yaml manifest: ./manifest.yaml boundaries: azure: directory: azure components: deploy-identity: infra: location: westeurope検証とビルド
aggrega validate --release release.yamlrelease dependency validation passed: release.yaml (schema-pillar + dependency pillars)Release が依存するものを pull してから、ビルドします。
aggrega pull --release release.yamlaggrega build --release release.yamlPull complete: release.lock (entities=…, source_artifacts=…, external_inputs=…)[… omitted: the build's elapsed time]Build completed: 1 file written to <workspace>/distビルドは azure 境界の 1 つのテンプレート dist/azure/arm/arm-template.json を書き出し、そのインスタンスが与えるシンボリック名で 1 つのリソースを含めます。リソース自身のメンバーの隣に、ビルドはどの Aggregate、Release、Recipe がそれを生成したかを metadata の下に記録します。
{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "languageVersion": "2.0", "resources": { "DeployIdentity": { "apiVersion": "2024-11-30", "location": "westeurope", "metadata": { "aggrega.ai/provenance": { "aggrega.ai/aggregate-name": "identities", "aggrega.ai/boundary-path": "azure", "aggrega.ai/compiler-version": "<compiler version>", "aggrega.ai/component-id": "deploy-identity", "aggrega.ai/environment": "production", "aggrega.ai/provider": "arm", "aggrega.ai/provider-version": "<compiler version>", "aggrega.ai/recipe-uri": "microsoft-managedidentity-userassignedidentities:0.1.0" } }, "name": "deploy-identity", "type": "Microsoft.ManagedIdentity/userAssignedIdentities" } }}テンプレートは Azure に渡すものです。arm プロバイダーでは、それをリソースグループスコープでデプロイするコマンドを説明しています。サブスクリプションまたは管理グループのスコープでのみ書き込み可能なリソースタイプは、そのスコープ向けのフラグメントとしてドラフトされ、その Recipe のヘッダーは Release が設定する境界アノテーションを示します。詳しくはサブスクリプションスコープでのデプロイと管理グループスコープでのデプロイを参照してください。テナントスコープでのみ書き込み可能なタイプ、または別のリソースの拡張としてのみ書き込み可能なタイプは、名前を示して拒否されます。
シークレット
シークレットプロパティの値がドラフトに書き込まれることはなく、そのためのデフォルトもドラフトされません。値がリソースに届く方法は、プロバイダーによって異なります。
- Azure: テンプレートのトップレベルの
securestringパラメーターで、インスタンスとプロパティにちなんで名付けられ、デプロイ時に指定します。ベンダーがオプションとしてマークしたシークレットは、必須パラメーターになります。 - CloudFormation:
NoEchoが付いたテンプレートのParametersエントリで、同じ方法で名付けられます。ベンダーがオプションとしているシークレットも、必須パラメーターになります。 - Terraform: Component 上の Feature スロットと、
sensitive: trueが付いたモジュール変数です。値は、Release がそのスロットにアタッチするシークレットを通じて渡されます。
リソースのトップにあるプロパティだけがシークレットになります。Azure ではルートのキーまたは properties のメンバーです。その下にある機密メンバー、たとえば Azure の osProfile 内の adminPassword や Terraform ブロック内の password は、シークレットとしてはドラフトされません。Release は、その親がドラフトされるキーの内側に通常の値として設定し、インポートはそれぞれについて constraint-dropped の下でパスとそのキーを示して警告します。
CloudFormation のプロパティは、名前に認証情報を表す語(password、secret、token、credential、private key、API key、passphrase)を含み、かつ Arn、Id、Name、Ref で終わらない場合に、シークレットとして読み取られます。この読み取りはドラフトの慣例であり、Recipe のヘッダーはシークレットとして読み取った各プロパティを示すため、レビューで確認してください。
CloudFormation と Terraform での同じインポート
手順は同じで、異なるのはエクスポートと Recipe の形だけです。以下の 2 つの場合は合成スキーマからドラフトされたもので、そのベンダーのテキストは以下では省略しています。
CloudFormation
aws cloudformation describe-type --type RESOURCE --type-name AWS::Example::Ledger > ledger.jsonaggrega import ledger.jsonインポートは Component と Recipe を書き出し、引き継げないベンダー制約ごとに 1 つの警告を出します。
wrote catalog/component/imported/component/aws-example-ledger/0.1.0/component.yamlwrote catalog/recipe/cloudformation/aws-example-ledger/0.1.0/recipe.yamlwrote .aggrega-import.jsonread as the cloudformation-schema format, with drafted paths relative to <workspace>warn: the property "LedgerName" does not carry the vendor schema's pattern "…": the catalog reads a pattern as an RE2 regular expression, which refuses it: …warn: the property "Rules[].Children[]" does not carry the vendor schema's shape below it: the vendor schema's definitions refer back to themselves there, so it is drafted as an open objectmapped AWS::Example::Ledger (AWS::Example::Ledger) to imported/component/aws-example-ledger as a draft, NONE at 0.0167Recipe の template.yaml は、インスタンスが与える論理 ID でリソースを宣言し、シークレットは NoEcho パラメーターとし、各 provides キーは !Ref または !GetAtt で書かれ、cloudformation プロバイダーがそれをスタックの Outputs に射影できるように、provides の下で繰り返されます。
artifacts: template.yaml: | Parameters: {{ .locals.logical_id }}MasterPassword: Type: String NoEcho: true Resources: {{ .locals.logical_id }}: Type: AWS::Example::Ledger Properties: # … one line for each key the header lists MasterPassword: !Ref {{ .locals.logical_id }}MasterPassword provides: arn: !GetAtt {{ .locals.logical_id }}.ArnTerraform
terraform init && terraform providers schema -json > schema.jsonaggrega import schema.jsonwrote catalog/component/imported/component/aws-example-ledger/0.1.0/component.yamlwrote catalog/recipe/terraform/aws-example-ledger/0.1.0/recipe.yamlwrote catalog/recipe/terraform/aws-example-ledger/0.1.0/module/main.tf.jsonwrote .aggrega-import.jsonTerraform のエクスポートには、構成が必要とするプロバイダーの名前は含まれますが、そのバージョンは含まれないため、インポートは警告を出します。
warn: no version of the provider hashicorp/aws is known, so the module drafted for aws_example_ledger requires it without a version constraint: set terraform.required_providers.aws.version in the module/main.tf.json beside the Recipe, then run aggrega pin on the RecipeTerraform のドラフトは、モジュールを伴う Recipe です。module/main.tf.json は、入力ごとに 1 つの変数、1 つのリソース this(各引数はその変数から読み取られます)、そしてエクスポートが指定するプロバイダーを宣言します。Recipe の spec.source はそのモジュールを指し、その valuesMapping は Component のピラーから各変数を埋め、オプションの入力は Release が設定した場合にのみ書き込みます。最初の pull の前にモジュールをピン留めして、ロックがそのダイジェストを記録するようにします。
aggrega pin catalog/recipe/terraform/aws-example-ledger/0.1.0/recipe.yamlPinned Recipe "aws-example-ledger": wrote <workspace>/catalog/recipe/terraform/aws-example-ledger/0.1.0/entity.lock (remote source pins: 0, imported file pins: 0, local source file pins: 1). Commit it beside the entityピン留めされていない Recipe は pull を停止させ、aggrega pin を示します。モジュールを編集するたびに、もう一度ピン留めしてください。
Aggregate、Manifest、Release の記述は Azure の場合と同じで、ドラフトされた名前とプロバイダー固有の infra を使います。Terraform の Release は、Component が宣言している場合に、region のようなプロバイダーの配置キーを指定します。
カタログがすでに保持している Component
カタログにそのサービスの Component があり、お使いのプロバイダー向けの Recipe だけがない場合は、その Component を設定で指定します。すると、インポートは Component のピラーに対して書かれた Recipe だけをドラフトします。resource_types の各エントリは、タイプ名か、タイプと Component を持つオブジェクトです。
plugins: importer: # The entry passes resource_types; the importer is served without it. - uri: importer/arm-schema:<compiler version> with: settings: resource_types: - type: Microsoft.ManagedIdentity/userAssignedIdentities component: acme/security/identityRecipe には、Component にちなんだ名前 identity-microsoft-managedidentity-userassignedidentities が付くため、カタログがすでに保持している Recipe の名前を取ることはありません。タイプのプロパティと同じ名前の values キーを宣言するカタログの Component は、そのプロパティを values から読み取ります。ベンダーが必須としていて、Component にキーがないプロパティは infra.overrides から読み取られ、Release がそれを設定するまでビルドを停止させるアサーションが付きます。Component が提供するキーのうち、名前が読み戻し属性と一致するものは書き出されます。それ以外のすべてについては、ドラフトはキーの名前を示して失敗するテンプレートを書き出すため、対応付けるまでビルドは停止し、インポートは警告を出します。
warn: the Component acme/security/identity provides principal_id, and no attribute Microsoft.ManagedIdentity/userAssignedIdentities@2024-11-30 reads back carries its name, so the drafted Recipe's provides.principal_id halts the build until it is mapped: map it to an attribute Microsoft.ManagedIdentity/userAssignedIdentities@2024-11-30 reads back, one of id, properties.clientId, properties.principalId, properties.tenantIdAzure はこの属性を properties の下に入れ子にするため、書く行は、そのタイプの完全なドラフトが持つものになります。
provides: principal_id: "[reference('{{ .locals.symbol }}').principalId]"その行を書いたら、Release は上記と同様に、Aggregate で Component を、Manifest で Recipe を指定し、infra.overrides.location の下に配置を設定すれば、検証とビルドで同じテンプレートが得られます。
カタログに Component がない名前は、その名前の新しい Component としてドラフトされ、インポートは警告を出します。これにより、Component の名前を打ち間違えたものが、新しい Component と取り違えられることはありません。
次のステップ
- コアインポーターでは、各インポーターが何を読み取るか、複数のタイプや複数のプロバイダーの中からどのように選ぶか、その分割の詳細、各ターゲットが何をドラフトするか、そして 3 つが報告する診断を説明しています。
- arm プロバイダーでは、Azure のドラフトがマージされるテンプレートと、デプロイされるスコープを説明しています。
- aggrega import は、このコマンドの完全なリファレンスです。