3

我感兴趣的是读取不同资源组中另一个部署的输出参数。我的 ARM 模板类似于:

  1. platform.json - 设置 DNS、虚拟网络和安全性
  2. storage.json - 设置数据库和其他存储
  3. app.json - 设置 web 应用程序/api

每个都部署在不同的资源组中,因为它们具有不同的生命周期。但是,当我部署 app.json 时,我想提取最新平台和存储部署的输出并使用它们来配置应用程序。

链接模板不是解决方案,因为链接模板最终部署在与应用程序相同的资源组中,这违背了将资源隔离在资源组中的目的。

有什么方法可以从不同的资源组读取部署的输出参数?如果没有,Azure 是否计划支持它?

我知道有一种方法可以通过 id 获取资源,使用 resourceId 函数,并查看它们的属性,但我试图避免这样做,以免进入资源参考 spagetti。

4

3 回答 3

4

你是如何进行部署的?在 PowerShell 中,您可以执行以下操作:

(Get-AzureResourceGroupDeployment NameOfResourceGroup).Outputs.NameOfOuputProperty.Value

这将为您提供最新部署的输出。您还可以将整个部署对象放入一个 var 中并以这种方式使用它。

$d = Get-AzureResourceGroupDeployment NameOfResourceGroup

如果您需要许多输出属性,这会更快。

这种帮助?

AzureRM cmdlet 的更新

语法大致相同:

(Get-AzureRmResourceGroupDeployment -ResourceGroupName NameOfResourceGroup -Name NameOfDeployment).Outputs.NameOfOutputProperty.value

如果您有多个部署,您可以使用:

Get-AzureRmResourceGroupDeployment -ResourceGroupName NameOfResourceGroup 

看到它们,看看它们的名字是什么......

于 2015-08-20T19:57:00.827 回答
4

我知道这是一个老问题,但对于其他人来说,截至 2018 年 3 月 12 日,你绝对可以做到这一点。

您需要确保您的输出按照Microsoft 文档格式化输出变量,其格式大致为

"outputs": {
  "resourceID": {
    "type": "string",
    "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
  }
}

然后,您可以通过使用具有以下格式的资源引用引用部署来在模板中使用这些输出

reference(resourceName or resourceIdentifier, [apiVersion], ['Full'])

请注意,您需要提供 api 版本,因为部署可能使用与您的父模板使用的不同的 api 版本。

然后,您的参考将类似于以下内容

{
  "comments": "This would have an output named myOutput you want to use",
  "apiVersion": "2017-05-10",
  "type": "Microsoft.Resources/deployments",
  "name": "my-deployment",
  "resourceGroup": "...",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "...",
      "contentVersion": "1.0.0.0"
    },
    "parameters": { }
},
{
  "comments": "This makes use of myOutput from my-deployment",
  "apiVersion": "2017-05-10",
  "type": "Microsoft.Resources/deployments",
  "name": "my-dependent-deployment",
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "...",
      "contentVersion": "1.0.0.0"
    },
    "parameters": {
      "myValueFromAnotherDeployment": { "value": "[reference('my-deployment', '2017-05-10').outputs.myOutput.value]" }
    }
  }
}

请注意值的稍微尴尬的“重新打包”,我们将myOutput.value其用作依赖部署的输入,并将其放入带有 key 的对象中"value": "...."。这是因为 ARM 参数必须具有“值”属性才能有效。

如果您尝试直接使用输出,您将收到无效的模板错误(因为output变量具有“类型”,而这不是 a 中允许的键parameter)。这就是为什么您需要获取该value属性,然后将其放回value下游模板中。

于 2018-12-03T02:08:20.570 回答
0

你在使用 Azure DevOps 发布管道吗?您可以将要创建的输出设置为变量,以便您可以在相同或不同的阶段重复使用它们。

我们在我们的项目中使用这些扩展

于 2019-10-30T13:09:20.793 回答