ARM 模板中的 Azure 订阅名称

Azure subscription name in ARM template

我正在尝试使用以下模板在 ARM 模板中获取 Azure 订阅名称

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {  },
  "variables": {
    "subscriptionName": "[subscription().displayName]"
  },
  "resources": [  ],
  "outputs": {
    "exampleOutput": {
        "value": "[variables('subscriptionName')]",
        "type" : "object"
    }
  }
}

运行 以上模板使用以下 powershell 命令

New-AzureRmResourceGroupDeployment -Name MyTest -ResourceGroupName EnvDev -TemplateFile C:\Users\xyz\test.json

但是出现以下错误

New-AzureRmResourceGroupDeployment : 2:04:11 PM - {
"code": "DeploymentOutputEvaluationFailed",
"message": "Unable to evaluate template outputs: 'exampleOutput'. Please see error details and deployment operations. Please see https://aka.ms/arm-debug for usage details.",
"details": [
 {
  "code": "DeploymentOutputEvaluationFailed",
  "target": "exampleOutput",
  "message": "The template output 'exampleOutput' is not valid: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.."
 }
]}
At line:1 char:1
+ New-AzureRmResourceGroupDeployment -Name SentienceTest -ResourceGroup ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

我如何在 ARM 模板中获取订阅名称,订阅将在该模板下部署?

有人知道这里出了什么问题吗?

根据您操作的错误判断,建议您尝试以下操作:

  "outputs": {
    "exampleOutput": {
        "value": "[variables('subscriptionName')]",
        "type" : "string"
    }
  }

因此将 "type" 更改为字符串。