ARM模板中的Azure订阅名称

时间:2016-11-14 19:13:20

标签: azure automation azure-resource-manager

我正在尝试使用以下模板

在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模板中获取订阅名称,在哪个订阅下部署它?

任何人都知道这里有什么不对吗?

1 个答案:

答案 0 :(得分:1)

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

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

所以改变"类型"串起来。