Marketplace 製品のプログラムによるデプロイ
この記事では、Azure CLI、Azure PowerShell、Terraform を使用して Marketplace 製品リソースを Azure にデプロイする方法について説明します。
前提 条件
Azure PowerShell をインストールし、Azure に接続する必要があります。
ローカル コンピューターに Azure PowerShell コマンドレットをインストールします。 詳細については、「Azure PowerShell の概要」を参照してください。
Connect-AZAccountを使用して Azure に接続します。
複数の Azure サブスクリプションがある場合は、Set-AzContext 実行する必要がある場合もあります。
詳細については、「複数の Azure サブスクリプションを使用する」を参照してください。
デプロイ コマンドは、Azure CLI バージョン 2.2.0 で変更されました。 この記事の例では、Azure CLI バージョン 2.20.0 以降 必要があります。
このサンプルを実行するには、Azure CLIの最新バージョンをインストールします。 開始するには、次を実行します
az login
Azureへの接続を作成するには。
発行元、オファー、プランの Marketplace 製品識別子を検索する方法
プログラムによって Marketplace 製品をデプロイするには、まず Marketplace 製品の一意の識別子を取得する必要があります。
一意の識別子を検索するには:
Azure portal を開き、Marketplace エクスペリエンスに移動します。
デプロイする Marketplace 製品を検索する
製品名を選択して、製品の詳細ページを開きます。
[使用状況情報とサポート] タブに移動します。[使用状況情報] に、発行元 ID、製品 ID、プラン ID が表示されます。
手記
一部の API では、製品 ID はオファー ID とも呼ばれ、プラン ID は SKU ID とも呼ばれます。
Azure Marketplace からの仮想マシン
Azure Marketplace からサード パーティの VM をデプロイするには、まず、デプロイされている VM イメージのエンド ユーザー ライセンス契約 (EULA) に同意する必要があります。 Azure サブスクリプションで EULA が 1 回受け入れられたら、条項に再度同意しなくても、同じ VM オファーをもう一度デプロイできます。 Azure portal から VM をデプロイする場合は、ここで使用条件に同意します。 ただし、プログラムでデプロイを行う場合は、az vm image terms accept --publisher X --offer Y --plan Z
を使用するか ARM を使用して使用条件に同意する必要があります。
使用条件がまだ受け入れられない場合は、次のエラーが表示されます。
Code : MarketplacePurchaseEligibilityFailed
Message: Marketplace purchase eligibility check returned errors. See inner errors for details
Details: Offer with PublisherId: '<PublisherId>', OfferId: '<OfferId>' cannot be purchased due to validation errors. For more information see details. Correlation Id: 'aaaa0000-bb11-2222-33cc-444444dddddd' You have not accepted the legal terms on this subscription: 'aaaa0000-bb11-2222-33cc-444444dddddd' for this plan. Before the subscription can be used, you need to accept the legal terms of the image. To read and accept legal terms, use the Azure CLI commands described at https://go.microsoft.com/fwlink/?linkid=2110637 or the PowerShell commands available at https://go.microsoft.com/fwlink/?linkid=862451. Alternatively, deploying via the Azure portal provides a UI experience for reading and accepting the legal terms.
Azure CLI を使用して Azure Marketplace から VM をデプロイする
条項に同意したら、ARM/Bicep テンプレート、Azure CLI、Terraform などの通常の方法を使用して VM をデプロイできます。
VM イメージの検索、使用条件への同意、CLI を使用した VM のデプロイの詳細については、「CLI を使用してマーケットプレース購入プラン情報を検索して使用するを参照してください。
Terraform を使用して Azure Marketplace から VM をデプロイする
Windows VM または Linux VM 用 Terraform を使用して仮想マシンデプロイする方法について説明します。
Terraform を使用して Marketplace VM をデプロイするには、次のアクションを実行する必要があります。
azurerm_marketplace_agreement を使用して VM 製品の法的条項に同意する
azurerm_virtual_machine プロバイダーで
plan
ブロックを指定する
手記
プラン ブロックが指定されていない場合、デプロイは次のエラーで失敗します。
Code: VMMarketplaceInvalidInput
Message: Creating a virtual machine from Marketplace image or a custom image sourced from a Marketplace image requires Plan information in the request. VM: '/subscriptions/<Subscription ID>/resourceGroups/myResourceGroup/providers/Microsoft.Compute/virtualMachines/myVM
手記
azurerm_marketplace_agreement は Terraform リソースとして扱われるため、最初に特定の Marketplace VM 製品を作成するときに、法的条件が受け入れられたという事実を表す一意のリソースが作成されます。 ただし、次に同じ Azure サブスクリプションに別の VM (同じパブリッシャー ID とオファー ID) をデプロイしようとすると、エラーが発生します。
A resource with the ID "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e /providers/Microsoft.MarketplaceOrdering/agreements/<Publisher ID>/offers/<Product ID>/plans/<Plan ID>" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_marketplace_agreement" for more information
Terraform state list
を実行して、azurerm_marketplace_agreement リソースの状態があるかどうかを確認してください。もしない場合は、そのリソースの状態を Terraform の状態にインポートする必要があります。
terraform import azurerm_marketplace_agreement.<TerraformResourceName> /subscriptions/<AzureSubscriptionId>/providers/Microsoft.MarketplaceOrdering/agreements/<Publisher ID>/offers/<Product ID>/plans/<Plan ID>
Azure Marketplace からの SaaS オファー
SaaS オファーは、通常、Azure portal を使用して顧客によってデプロイされます。 Azure portal を使用して SaaS オファーをデプロイした後、顧客は [今すぐアカウントの構成] ボタンを使用して SaaS ISV のランディング ページにアクセスし、SaaS オファーの構成を完了します。 オファーが構成されると、SaaS ISV によって SaaS Fulfillment API を使用してアクティブ化されます。
Azure portal を使用して SaaS オファーをデプロイすると、ARM テンプレートが作成され、デプロイの特定のパラメーター値が割り当てられます。 パラメーターの 1 つは termId であり、オファーのサブスクリプション期間を識別します。 termId 値は静的ではありませんが、オファーの構成とデプロイの時刻によって異なります。 そのため、ARM テンプレートで termId に固定値を使用することはできません。 代わりに、次の手順に従って、現在の termId 値を確認する必要があります。
- Azure portal を使用してオファーを手動でデプロイします。
- オファーがデプロイされているリソース グループに移動します。
- [デプロイ] セクションでデプロイ名を選択します。
- 入力パラメーターを表示し、termId の値をコピーします。
特定の SaaS オファーが Azure サブスクリプションにデプロイされなかった場合、プログラムによるデプロイは失敗し、次のようなエラーが表示されます。
code: DeploymentFailed
message: At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage
Details: Failed to process eligibility check with error Purchase has failed due to signature verification on Marketplace legal agreement. Please retry. If error persists use different Azure subscription, or contact support with correlation-id 'aaaa0000-bb11-2222-33cc-444444dddddd' and this error message
ARM テンプレートと Azure CLI を使用して SaaS オファーをデプロイする
ARM サンプル テンプレートを参照してください。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"planId": {
"type": "string"
},
"offerId": {
"type": "string"
},
"publisherId": {
"type": "string"
},
"quantity": {
"type": "int"
},
"termId": {
"type": "string"
},
"azureSubscriptionId": {
"type": "string"
},
"publisherTestEnvironment": {
"type": "string",
"defaultValue": ""
},
"autoRenew": {
"type": "bool"
}
},
"resources": [
{
"type": "Microsoft.SaaS/resources",
"apiVersion": "2018-03-01-beta",
"name": "[parameters('name')]",
"location": "global",
"properties": {
"saasResourceName": "[parameters('name')]",
"publisherId": "[parameters('publisherId')]",
"SKUId": "[parameters('planId')]",
"offerId": "[parameters('offerId')]",
"quantity": "[parameters('quantity')]",
"termId": "[parameters('termId')]",
"autoRenew": "[parameters('autoRenew')]",
"paymentChannelType": "SubscriptionDelegated",
"paymentChannelMetadata": {
"AzureSubscriptionId": "[parameters('azureSubscriptionId')]"
},
"publisherTestEnvironment": "[parameters('publisherTestEnvironment')]",
"storeFront": "AzurePortal"
}
}
]
}
- 上記を
SaaS-ARM.json
として保存します - 次のコマンドを実行します。
az group create --resource-group <ResourceGroupName> --location <Location>
az deployment group create --resource-group <Resource Group Name> --template-file ./SaaS-ARM.json --parameters name=<SaaS Resource Name> publisherId=<Publisher ID> offerId=<Product ID> planId=<Plan ID> termId=<termId> quantity=1 azureSubscriptionId=11111111-1111-1111-1111-11111111 autoRenew=true
SaaS オファー リソースがプロビジョニングされたら、次の ARM API を呼び出して、そのプロパティを表示できます。
az rest --method get --uri /subscriptions/<AzureSubscriptionId>/resourceGroups/<ResourceGroupName>/providers/Microsoft.SaaS/resources/<SaaS Resource Name>?api-version=2018-03-01-beta -o json
これで、POST
呼び出しを行って、マーケットプレース トークンとランディング ページの URL を取得できるようになりました。 この URL を使用すると、SaaS ISV のランディング ページを参照して、SaaS オファーの構成とアクティブ化を完了できます。
az rest --method post --uri /subscriptions/<AzureSubscriptionId>/resourceGroups/<ResourceGroupName> /providers/Microsoft.SaaS/resources/<SaaS Resource Name>/listAccessToken?api-version=2018-03-01-beta -o json
詳細については、Microsoft.SaaS リソース プロバイダーの仕様 を参照してください。
Terraform を使用して Azure Marketplace から SaaS オファーをデプロイする
Terraform デプロイでは ARM テンプレートの使用と同じものが使用されるため、ARM を使用して SaaS オファーをデプロイする方法については、上記のセクションを参照してください。
Azure Marketplace からの Azure アプリケーション
Azure Application 製品の種類は、完全に機能するマルチ リソース アプリケーションを提供するようにバンドルおよび構成された一連の Azure リソースと Marketplace 製品を含む ARM テンプレートをパブリッシャーが作成できるようにする一意のオファリングです。Azure Application には、次の 3 つのプランの種類があります。
- ソリューション テンプレート - 無料のオファリング、ARM テンプレートのデプロイ
- マネージド アプリケーションは、無料または有料のオファリングとして、Microsoft.Solutions/applications リソース タイプを生成します。
Azure portal では、Azure アプリケーション (マネージド アプリケーション) デプロイ用の ARM テンプレートが生成されます。 この ARM テンプレートは、特定のプランをポイントし、顧客が Azure portal で入力する UI フィールドからアプリケーション固有のパラメーターを渡す Microsoft.Solutions/applications
型のリソースを作成します。
Azure Managed App の使用条件に同意する
仮想マシン オファーと同様に、ARM テンプレートを使用して Azure アプリケーション (マネージド アプリケーション) をプログラムで Azure サブスクリプションにデプロイするには、サブスクリプションが Azure Managed App のプランの条件に同意する必要があります。 Azure portal を使用してデプロイすると、条件の同意は暗黙的に行われ、同じ Azure サブスクリプション内の同じプランの後のプログラムによるデプロイは問題なく機能します。
また、VM セクションで前述したのと同じ az vm image terms accept
を使用して、Azure アプリケーション (マネージド アプリケーション) オファーの条件に同意することもできます。
Azure アプリケーション (マネージド アプリケーション) 製品が有料製品である場合 (たとえば、毎月の課金や従量制課金を使用する場合)、デプロイに使用する Azure サブスクリプションは有効な支払い方法に関連付けられている必要があります (たとえば、無料またはスポンサー付きサブスクリプションにすることはできません)。
ARM テンプレートと Azure CLI を使用して Azure アプリケーション (マネージド アプリケーション) をデプロイする
マネージド アプリケーションをデプロイするための ARM テンプレートの例を次に示します。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"allowedValues": [
"westus2",
"westeurope",
"eastus",
"northeurope",
"centralus",
"eastus2",
"francecentral",
"uksouth"
]
},
"applicationResourceName": {
"type": "string"
},
"managedResourceGroupId": {
"type": "string",
"defaultValue": ""
},
"managedIdentity": {
"type": "object",
"defaultValue": {}
},
"initialConsulVersion": {
"type": "string",
"defaultValue": "v1.11.2"
},
"storageAccountName": {
"type": "string",
"defaultValue": "[concat('storage', uniqueString(resourceGroup().id, deployment().name))]"
},
"blobContainerName": {
"type": "string",
"defaultValue": "[concat('blob', uniqueString(resourceGroup().id, deployment().name))]"
},
"identityName": {
"type": "string",
"defaultValue": "[concat(parameters('clusterName'), '-identity')]"
},
"clusterMode": {
"type": "string",
"defaultValue": "PRODUCTION",
"allowedValues": [
"PRODUCTION",
"DEVELOPMENT"
]
},
"clusterName": {
"type": "string",
"defaultValue": "cluster"
},
"consulDataCenter": {
"type": "string",
"defaultValue": "dc1"
},
"numServers": {
"type": "string",
"defaultValue": "3"
},
"numServersDevelopment": {
"type": "string",
"defaultValue": "1"
},
"automaticUpgrades": {
"type": "string",
"defaultValue": "disabled"
},
"consulConnect": {
"type": "string",
"defaultValue": "enabled"
},
"externalEndpoint": {
"type": "string",
"defaultValue": "enabled"
},
"snapshotInterval": {
"type": "string",
"defaultValue": "1d"
},
"snapshotRetention": {
"type": "string",
"defaultValue": "1m"
},
"consulVnetCidr": {
"type": "string",
"defaultValue": "172.25.16.0/24"
},
"providerBaseURL": {
"defaultValue": "https://ama-api.hashicorp.cloud/consulama/2021-04-23",
"type": "String",
"metadata": {
"description": "The URI of the custom provider API"
}
},
"email": {
"type": "string"
},
"federationToken": {
"type": "string",
"defaultValue": ""
},
"sourceChannel": {
"type": "string",
"defaultValue": "azure-portal"
},
"auditLoggingEnabled": {
"type": "string",
"defaultValue": "disabled",
"allowedValues": [
"enabled",
"disabled"
]
},
"auditLogStorageContainerURL": {
"type": "string",
"defaultValue": ""
}
},
"variables": {
},
"resources": [
{
"type": "Microsoft.Solutions/applications",
"apiVersion": "2017-09-01",
"name": "[parameters('applicationResourceName')]",
"location": "[parameters('location')]",
"kind": "MarketPlace",
"identity": "[if(empty(parameters('managedIdentity')),json('null'),parameters('managedIdentity'))]",
"plan": {
"name": "<Plan ID>",
"product": "<Product ID>",
"publisher": "<Publisher ID>",
"version": "<Version>"
},
"properties": {
"managedResourceGroupId": "[parameters('managedResourceGroupId')]",
"parameters": {
"initialConsulVersion": {
"value": "[parameters('initialConsulVersion')]"
},
"storageAccountName": {
"value": "[parameters('storageAccountName')]"
},
"blobContainerName": {
"value": "[parameters('blobContainerName')]"
},
"identityName": {
"value": "[parameters('identityName')]"
},
"clusterMode": {
"value": "[parameters('clusterMode')]"
},
"clusterName": {
"value": "[parameters('clusterName')]"
},
"consulDataCenter": {
"value": "[parameters('consulDataCenter')]"
},
"numServers": {
"value": "[parameters('numServers')]"
},
"numServersDevelopment": {
"value": "[parameters('numServersDevelopment')]"
},
"automaticUpgrades": {
"value": "[parameters('automaticUpgrades')]"
},
"consulConnect": {
"value": "[parameters('consulConnect')]"
},
"externalEndpoint": {
"value": "[parameters('externalEndpoint')]"
},
"snapshotInterval": {
"value": "[parameters('snapshotInterval')]"
},
"snapshotRetention": {
"value": "[parameters('snapshotRetention')]"
},
"consulVnetCidr": {
"value": "[parameters('consulVnetCidr')]"
},
"location": {
"value": "[parameters('location')]"
},
"providerBaseURL": {
"value": "[parameters('providerBaseURL')]"
},
"email": {
"value": "[parameters('email')]"
},
"federationToken": {
"value": "[parameters('federationToken')]"
},
"sourceChannel": {
"value": "[parameters('sourceChannel')]"
},
"auditLoggingEnabled": {
"value": "[parameters('auditLoggingEnabled')]"
},
"auditLogStorageContainerURL": {
"value": "[parameters('auditLogStorageContainerURL')]"
}
},
"jitAccessPolicy": null
}
}
]
}
次に、次のコマンドを実行します。
az group create --resource-group <Resource Group Name> --location <location>
az deployment group create --resource-group avmanagedapp100 --template-file <ARM Template JSON file> --parameters location=<location> applicationResourceName=<Resource Group Name> managedResourceGroupId=/subscriptions/<Subscription ID>/resourceGroups/<Resource Group Name> email=<email address>
Terraform を使用して Azure Marketplace から Azure Managed App をデプロイする
Terraform デプロイでは同じ ARM テンプレートが使用されるため、ARM を使用して Azure Managed App オファーをデプロイする方法については、上記のセクションを参照してください。
Azure Marketplace のソリューション テンプレート
Azure Marketplace から (Azure Managed App ではなく) オファー ソリューション テンプレート をデプロイする場合、デプロイは単に、ISV が発行した ARM テンプレートであり、対応する UI フィールドがパラメーターとして渡されます。 ソリューション テンプレート オファーをプログラムでデプロイするには、Azure portal を使用してデプロイを行い、ARM テンプレートをコピーして、以降のデプロイで使用します。 ソリューション テンプレートは "有料" オファーではないため、受け入れる必要がある特別な条件はありません。 ただし、ソリューション テンプレート ARM テンプレートが Azure Marketplace の VM イメージを参照している場合は、まず、VM オファー の説明に従って、VM オファーの条件に同意する必要があります。