Compartir a través de

Bicep 的部署函数

本文介绍用于获取与当前部署相关的值的 Bicep 函数。

部署

deployment()

返回有关当前部署操作的信息。

命名空间:az

返回值

此函数返回部署期间传递的对象。 返回的对象中的属性因以下情况而异:

将本地 Bicep 文件部署到资源组时,该函数返回以下格式:

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

当部署到 Azure 订阅、管理组或租户时,返回对象包含 location 属性。 部署本地 Bicep 文件时,不包括 location 属性。 格式为:

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

示例

下面的示例返回部署对象:

output deploymentOutput object = 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"
  }
}

环境

environment()

返回有关用于部署的 Azure 环境的信息。 environment() 函数不知道资源配置。 它只能为每个资源类型返回单个默认 DNS 后缀。

命名空间:az

备注

若要查看帐户的已注册环境的列表,请使用 az cloud listGet-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": ""
  }
}

示例

以下示例 Bicep 文件返回环境对象。

output environmentOutput object = environment()

前面的示例在部署到 Azure 中国云时返回以下对象:

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

后续步骤

  • 若要从资源、资源组或订阅获取值,请参阅 Resource functions(资源函数)。