次の方法で共有


ARM テンプレートのデプロイ関数

Azure Resource Manager には、Azure Resource Manager テンプレート (ARM テンプレート) の現在のデプロイに関連する値を取得するための次の関数が用意されています。

リソース、リソース グループ、またはサブスクリプションから値を取得するには、 リソース関数を参照してください。

Tip

Bicep は ARM テンプレートと同じ機能を提供し、構文の方が使いやすいため、推奨されます。 詳細については、 deployment 関数に関するページを参照してください。

deployer

deployer()

現在のデプロイ プリンシパルに関する情報を返します。

Bicep で、 deployer 関数を使用します。

戻り値

この関数は、テナント ID、オブジェクト ID、ユーザー プリンシパル名など、現在のデプロイ プリンシパルに関する情報を返します。

{
  "objectId": "",
  "tenantId": "",
  "userPrincipalName": ""
}

Example

次の例では、配置元オブジェクトを返します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "developerOutput": {
      "type": "object",
      "value": "[deployer()]"
    }
  }
}

前の例では、次のオブジェクトが返されます。

{
  "objectId":"aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb",
  "tenantId":"aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
  "userPrincipalName":"john.doe@contoso.com"
}

デプロイ

deployment()

現在のデプロイ操作に関する情報を返します。

Bicep で、 deployment 関数を使用します。

戻り値

この関数は、デプロイ中に渡されるオブジェクトを返します。 返されるオブジェクトのプロパティは、次の場合によって異なります。

  • テンプレートまたはテンプレート スペックのデプロイ。
  • ローカル ファイルであるテンプレートをデプロイする、または URI を介してアクセスされるリモート ファイルであるテンプレートをデプロイする。
  • リソース グループへのデプロイ、または他のスコープ (Azure サブスクリプション管理グループ、または テナント) へのデプロイ。

ローカル テンプレートをリソース グループにデプロイすると、関数は次の形式を返します。

{
  "name": "",
  "properties": {
    "template": {
      "$schema": "",
      "contentVersion": "",
      "parameters": {},
      "variables": {},
      "resources": [],
      "outputs": {}
    },
    "templateHash": "",
    "parameters": {},
    "mode": "",
    "provisioningState": ""
  }
}

テンプレートがリモートの場合、 templateLink プロパティは返されたオブジェクトに含まれます。 templateLink プロパティには、テンプレートの URI が含まれています。 形式は次のようになります:

{
  "name": "",
  "properties": {
    "templateLink": {
      "uri": ""
    },
    "template": {
      "$schema": "",
      "contentVersion": "",
      "parameters": {},
      "variables": {},
      "resources": [],
      "outputs": {}
    },
    "templateHash": "",
    "parameters": {},
    "mode": "",
    "provisioningState": ""
  }
}

詳細については、「 変数を使用してテンプレートをリンクする」を参照してください。

テンプレート スペックをリソース グループにデプロイすると、関数は次の形式を返します。

{
  "name": "",
  "properties": {
    "templateLink": {
      "id": ""
    },
    "template": {
      "$schema": "",
      "contentVersion": "",
      "parameters": {},
      "variables": {},
      "resources": [],
      "outputs": {}
    },
    "templateHash": "",
    "parameters": {},
    "mode": "",
    "provisioningState": ""
  }
}

Azure サブスクリプション、管理グループ、またはテナントにデプロイする場合は、返されるオブジェクトに location プロパティが含まれています。 ローカル テンプレートまたは外部テンプレートのいずれかをデプロイする場合は、場所プロパティが含まれています。 形式は次のようになります:

{
  "name": "",
  "location": "",
  "properties": {
    "template": {
      "$schema": "",
      "contentVersion": "",
      "resources": [],
      "outputs": {}
    },
    "templateHash": "",
    "parameters": {},
    "mode": "",
    "provisioningState": ""
  }
}

languageVersion 2.0 テンプレートをデプロイすると、deployment関数はプロパティの限られたサブセットを返します。

{
  "name": "",
  "location": "",
  "properties": {
    "template": {
      "contentVersion": ""
    },
    "templateLink": {
      "id": "",
      "uri": ""
    }
  }
}

Remarks

deployment()を使用して、親テンプレートの URI に基づいて別のテンプレートにリンクできます。

"variables": {
  "sharedTemplateUrl": "[uri(deployment().properties.templateLink.uri, 'shared-resources.json')]"
}

ポータル内のデプロイ履歴からテンプレートを再デプロイすると、テンプレートがローカル ファイルとしてデプロイされます。 デプロイ関数の中では、templateLink プロパティは返されません。 お使いのテンプレートが templateLink に依存して別のテンプレートへのリンクを構成している場合は、ポータルを使用して再デプロイしないでください。 代わりに、最初にテンプレートのデプロイに利用したコマンドを使用してください。

Example

次の例では、配置オブジェクトを返します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "deploymentOutput": {
      "type": "object",
      "value": "[deployment()]"
    }
  }
}

前の例では、次のオブジェクトが返されます。

{
  "name": "deployment",
  "properties": {
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [],
      "outputs": {
        "deploymentOutput": {
          "type": "Object",
          "value": "[deployment()]"
        }
      }
    },
    "templateHash": "13135986259522608210",
    "parameters": {},
    "mode": "Incremental",
    "provisioningState": "Accepted"
  }
}

サブスクリプションのデプロイの場合、次の例はデプロイ オブジェクトを返します。

{
  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {},
  "resources": [],
  "outputs": {
    "exampleOutput": {
      "type": "object",
      "value": "[deployment()]"
    }
  }
}

環境

environment()

デプロイに使用される Azure 環境に関する情報を返します。 environment()関数はリソース構成を認識していません。 返すことができる既定の DNS サフィックスは、リソースの種類ごとに 1 つだけです。

Bicep で、 environment 関数を使用します。

Remarks

アカウントの登録済み環境の一覧を表示するには、 az cloud list または Get-AzEnvironmentを使用します。

戻り値

この関数では、現在の Azure 環境のプロパティが返されます。 次の例は、グローバル Azure のプロパティを示しています。ソブリン クラウドは、少し異なるプロパティを返す場合があります。

{
  "name": "",
  "gallery": "",
  "graph": "",
  "portal": "",
  "graphAudience": "",
  "activeDirectoryDataLake": "",
  "batch": "",
  "media": "",
  "sqlManagement": "",
  "vmImageAliasDoc": "",
  "resourceManager": "",
  "authentication": {
    "loginEndpoint": "",
    "audiences": [
      "",
      ""
    ],
    "tenant": "",
    "identityProvider": ""
  },
  "suffixes": {
    "acrLoginServer": "",
    "azureDatalakeAnalyticsCatalogAndJob": "",
    "azureDatalakeStoreFileSystem": "",
    "azureFrontDoorEndpointSuffix": "",
    "keyvaultDns": "",
    "sqlServerHostname": "",
    "storage": ""
  }
}

Example

次のテンプレート例は、環境オブジェクトを返します。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "environmentOutput": {
      "type": "object",
      "value": "[environment()]"
    }
  }
}

前の例では、グローバル Azure にデプロイされる場合は、次のオブジェクトが返されます。

{
  "name": "AzureCloud",
  "gallery": "https://gallery.azure.com/",
  "graph": "https://graph.windows.net/",
  "portal": "https://portal.azure.com",
  "graphAudience": "https://graph.windows.net/",
  "activeDirectoryDataLake": "https://datalake.azure.net/",
  "batch": "https://batch.core.windows.net/",
  "media": "https://rest.media.azure.net",
  "sqlManagement": "https://management.core.windows.net:8443/",
  "vmImageAliasDoc": "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/arm-compute/quickstart-templates/aliases.json",
  "resourceManager": "https://management.azure.com/",
  "authentication": {
    "loginEndpoint": "https://login.microsoftonline.com/",
    "audiences": [
      "https://management.core.windows.net/",
      "https://management.azure.com/"
    ],
    "tenant": "common",
    "identityProvider": "AAD"
  },
  "suffixes": {
    "acrLoginServer": ".azurecr.io",
    "azureDatalakeAnalyticsCatalogAndJob": "azuredatalakeanalytics.net",
    "azureDatalakeStoreFileSystem": "azuredatalakestore.net",
    "azureFrontDoorEndpointSuffix": "azurefd.net",
    "keyvaultDns": ".vault.azure.net",
    "sqlServerHostname": ".database.windows.net",
    "storage": "core.windows.net"
  }
}

parameters

parameters(parameterName)

パラメーター値を返します。 指定したパラメーター名は、テンプレートの parameters セクションで定義する必要があります。

Bicep では、シンボリック名を使用して パラメーター を直接参照します。

Parameters

Parameter Required タイプ Description
parameterName Yes 文字列 返されるパラメーターの名前。

戻り値

指定したパラメーターの値。

Remarks

通常、パラメーターを使ってリソースの値を設定します。 次の例では、Web サイトの名前を、デプロイ時に渡されるパラメーターの値に設定します。

"parameters": {
  "siteName": {
    "type": "string"
  }
}, "resources": [
  {
    "type": "Microsoft.Web/Sites",
    "apiVersion": "2016-08-01",
    "name": "[parameters('siteName')]",
    ...
  }
]

Example

次の例は、 parameters 関数の簡単な使用を示しています。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stringParameter": {
      "type": "string",
      "defaultValue": "option 1"
    },
    "intParameter": {
      "type": "int",
      "defaultValue": 1
    },
    "objectParameter": {
      "type": "object",
      "defaultValue": {
        "one": "a",
        "two": "b"
      }
    },
    "arrayParameter": {
      "type": "array",
      "defaultValue": [ 1, 2, 3 ]
    },
    "crossParameter": {
      "type": "string",
      "defaultValue": "[parameters('stringParameter')]"
    }
  },
  "variables": {},
  "resources": [],
  "outputs": {
    "stringOutput": {
      "type": "string",
      "value": "[parameters('stringParameter')]"
    },
    "intOutput": {
      "type": "int",
      "value": "[parameters('intParameter')]"
    },
    "objectOutput": {
      "type": "object",
      "value": "[parameters('objectParameter')]"
    },
    "arrayOutput": {
      "type": "array",
      "value": "[parameters('arrayParameter')]"
    },
    "crossOutput": {
      "type": "string",
      "value": "[parameters('crossParameter')]"
    }
  }
}

前の例の既定値の出力は次のとおりです。

Name タイプ Value
stringOutput String オプション 1
intOutput Int 1
objectOutput Object {"one": "a", "two": "b"}
arrayOutput Array [1, 2, 3]
crossOutput String オプション 1

パラメーターの使用の詳細については、 ARM テンプレートのパラメーターを参照してください。

variables

variables(variableName)

変数の値を返します。 指定した変数名は、テンプレートの variables セクションで定義する必要があります。

Bicep では、シンボリック名を使用して 変数 を直接参照します。

Parameters

Parameter Required タイプ Description
variableName Yes String 返す変数の名前。

戻り値

指定した変数の値。

Remarks

通常、変数を使って、複雑な値を 1 回だけ作成することによりテンプレートを簡略化します。 次の例では、ストレージ アカウントの一意の名前を作成します。

"variables": {
  "storageName": "[concat('storage', uniqueString(resourceGroup().id))]"
},
"resources": [
  {
    "type": "Microsoft.Storage/storageAccounts",
    "name": "[variables('storageName')]",
    ...
  },
  {
    "type": "Microsoft.Compute/virtualMachines",
    "dependsOn": [
      "[variables('storageName')]"
    ],
    ...
  }
],

Example

次の例では、さまざまな変数値が返されます。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {
    "var1": "myVariable",
    "var2": [ 1, 2, 3, 4 ],
    "var3": "[ variables('var1') ]",
    "var4": {
      "property1": "value1",
      "property2": "value2"
    }
  },
  "resources": [],
  "outputs": {
    "exampleOutput1": {
      "type": "string",
      "value": "[variables('var1')]"
    },
    "exampleOutput2": {
      "type": "array",
      "value": "[variables('var2')]"
    },
    "exampleOutput3": {
      "type": "string",
      "value": "[variables('var3')]"
    },
    "exampleOutput4": {
      "type": "object",
      "value": "[variables('var4')]"
    }
  }
}

前の例の既定値の出力は次のとおりです。

Name タイプ Value
exampleOutput1 String myVariable
exampleOutput2 Array [1, 2, 3, 4]
exampleOutput3 String myVariable
exampleOutput4 Object {"property1": "value1", "property2": "value2"}

変数の使用の詳細については、 ARM テンプレートの変数を参照してください。

次のステップ

ARM テンプレートのセクションの詳細については、ARM テンプレート の構造と構文を参照してください。