Marketplace 製品のプログラムによるデプロイ

この記事では、Azure CLI、Azure PowerShell、Terraform を使用して Marketplace 製品リソースを Azure にデプロイする方法について説明します。

前提条件

Azure PowerShell をインストールし、Azure に接続する必要があります。

デプロイ コマンドは Azure CLI バージョン 2.2.0 で変更されました。 この記事の例には、Azure CLI バージョン 2.20.0 以降が必要です。

このサンプルを実行するには、最新バージョンの Azure CLI をインストールします。 開始するには、az sign-in を実行して Azure との接続を作成します。

発行元、オファー、プランの Marketplace 製品識別子を検索する方法

プログラムによって Marketplace 製品をデプロイするには、まず Marketplace 製品の一意の識別子を取得する必要があります。

一意の識別子を検索するには:

  1. Azure portal を開き、Marketplace エクスペリエンスに移動します。
  2. デプロイする Marketplace 製品を検索する
  3. 製品名を選択して製品の詳細ページを開きます。
  4. [使用状況情報とサポート] タブに移動します。[使用状況情報] に、発行元 ID、製品 ID、プラン ID が表示されます。

製品 ID ページのスクリーンショット。

Note

一部の API では、製品 ID はオファー ID とも呼ばれ、プラン ID は SKU ID とも呼ばれます。

Azure Marketplace からの仮想マシン

Azure Marketplace からサード パーティの VM をデプロイするには、まず、デプロイされている VM イメージのエンド ユーザー ライセンス契約 (EULA) に同意する必要があります。 Azure サブスクリプションで EULA が 1 回受け入れられたら、条項に再度同意しなくても、同じ VM オファーをもう一度デプロイできます。 Azure portal から VM をデプロイする場合は、ここで使用条件に同意します。 ただし、プログラムでデプロイを行う場合は、ARM を使用して、または ARM を使用して条項に同意する az vm image terms accept --publisher X --offer Y --plan Z 必要があります。

使用条件がまだ受け入れられない場合は、次のエラーが表示されます。

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: '11111111-1111-1111-1111-111111111111' You have not accepted the legal terms on this subscription: '11111111-1111-1111-1111-111111111111' 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 をデプロイする

Terraform for Windows VM または Linux VM を使用して仮想マシンをデプロイする方法について説明します。

Terraform を使用して Marketplace VM をデプロイするには、次のアクションを実行する必要があります。

  1. azurerm_marketplace_agreementを使用して VM 製品の法的条項に同意する

  2. plan azurerm_virtual_machine プロバイダーでブロックを指定する

Note

プラン ブロックが指定されていない場合、デプロイは次のエラーで失敗します。

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

Note

azurerm_marketplace_agreementは Terraform リソースとして扱われるため、最初に特定の Marketplace VM 製品を作成するときに、法的条件が受け入れられたという事実を表す一意のリソースが作成されます。 ただし、次に同じ Azure サブスクリプションに別の VM (同じパブリッシャー ID とオファー ID) をデプロイしようとすると、エラーが発生します。

A resource with the ID "/subscriptions/11111111-1111-1111-1111-111111111111 /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

リソースの状態がazurerm_marketplace_agreementかどうか、およびリソースの状態を Terraform 状態にインポートする必要がない場合は、実行Terraform state listする必要があります。

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 値を確認する必要があります。

  1. Azure portal を使用してオファーを手動でデプロイします。
  2. オファーがデプロイされているリソース グループに移動します。
  3. [デプロイ] セクションでデプロイ名を選択します。
  4. 入力パラメーターを表示し、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 '11111111-1111-1111-1111-111111111111' 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

これで、マーケットプレース トークンとランディング ページの URL を取得するための呼び出しを行 POST うことができます。 この 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 アプリlication 製品の種類は、完全に機能するマルチ リソース アプリケーションを提供するようにバンドルおよび構成された一連の Azure リソースと Marketplace 製品を含む ARM テンプレートをパブリッシャーが作成できるようにする一意のオファリングAzure アプリ、次の 3 つのプランの種類があります。

  • ソリューション テンプレート - 無料のオファリング、ARM テンプレートのデプロイ
  • マネージド アプリケーション - 無料または有料のオファリングにより、Microsoft.Solutions/applications リソースの種類が作成されます

Azure portal では、Azure アプリlication (マネージド アプリケーション) デプロイ用の ARM テンプレートが生成されます。 この ARM テンプレートは、特定のプランを指し示し、顧客が Azure portal で入力する UI フィールドからアプリケーション固有のパラメーターを渡す、種類 Microsoft.Solutions/applications のリソースを作成します。

Azure マネージド アプリの使用条件に同意する

仮想マシン オファーと同様に、ARM テンプレートを使用してプログラムによって Azure アプリlication (マネージド アプリケーション) を Azure サブスクリプションにデプロイするには、サブスクリプションが Azure Managed App のプランの条件に同意する必要があります。 Azure portal を使用してデプロイすると、条件の同意は暗黙的に行われ、同じ Azure サブスクリプション内の同じプランの後のプログラムによるデプロイは問題なく機能します。

また、VM セクションで前述したのと同じものaz vm image terms acceptを使用して、Azure アプリlication (マネージド アプリケーション) オファーの条件に同意することもできます。

Azure アプリlication (マネージド アプリケーション) 製品が有料製品である場合 (たとえば、毎月の課金や従量制課金を使用する場合)、デプロイに使用する Azure サブスクリプションは有効な支払い方法に関連付けられている必要があります (たとえば、無料またはスポンサー付きサブスクリプションにすることはできません)。

ARM テンプレートと Azure CLI を使用して Azure アプリlication (マネージド アプリケーション) をデプロイする

マネージド アプリケーションをデプロイするための 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 マネージド アプリをデプロイする

Terraform デプロイでは同じ ARM テンプレートが使用されるため、ARM を使用して Azure Managed App オファーをデプロイする方法については、上記のセクションを参照してください。

Azure Marketplace のソリューション テンプレート

Azure Marketplace からソリューション テンプレート (Azure Managed App ではなく) オファーをデプロイする場合、デプロイは、パラメーターとして渡された対応する UI フィールドを使用して ISV が発行した ARM テンプレートにすぎません。 ソリューション テンプレート オファーをプログラムでデプロイするには、Azure portal を使用してデプロイを行い、ARM テンプレートをコピーして、以降のデプロイで使用します。 ソリューション テンプレートは "有料" オファーではないため、受け入れる必要がある特別な条件はありません。 ただし、ソリューション テンプレート ARM テンプレートが Azure Marketplace の VM イメージを参照している場合は、まず VM オファーの説明に従って VM オファーの条件に同意する必要があります。

次のステップ