![](/img/trans.png)
[英]Is there a way to deploy Azure Data factory other than using ARM templates?
[英]Azure ARM templates - using the output of other deployments
我感興趣的是讀取不同資源組中另一個部署的輸出參數。 我的 ARM 模板類似於:
每個都部署在不同的資源組中,因為它們具有不同的生命周期。 但是,當我部署 app.json 時,我想獲取最新平台和存儲部署的輸出並使用它們來配置應用程序。
鏈接模板不是解決方案,因為鏈接模板最終部署在與應用程序相同的資源組中,這違背了將資源隔離在資源組中的目的。
有什么方法可以從不同的資源組讀取部署的輸出參數? 如果沒有,Azure 是否計划支持它?
我知道有一種方法可以通過 id 獲取資源,使用 resourceId 函數,並查看它們的屬性,但我試圖避免這樣做,以免進入資源引用意大利面。
你的部署情況如何? 在 PowerShell 中,您可以執行以下操作:
(Get-AzureResourceGroupDeployment NameOfResourceGroup).Outputs.NameOfOuputProperty.Value
這將為您提供最新部署的輸出。 您還可以將整個部署對象放入一個 var 並以這種方式進行處理。
$d = Get-AzureResourceGroupDeployment NameOfResourceGroup
如果您需要許多輸出屬性,這會更快。
這種幫助?
語法大致相同:
(Get-AzureRmResourceGroupDeployment -ResourceGroupName NameOfResourceGroup -Name NameOfDeployment).Outputs.NameOfOutputProperty.value
如果您有多個部署,您可以使用:
Get-AzureRmResourceGroupDeployment -ResourceGroupName NameOfResourceGroup
看到他們,看看他們的名字是什么......
我知道這是一個老問題,但對於其他人來說,截至 2018 年 3 月 12 日,您絕對可以這樣做。
您需要確保您的輸出按照Microsoft 文檔的格式進行格式化,該文檔的輸出變量大致具有以下格式
"outputs": {
"resourceID": {
"type": "string",
"value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
}
}
然后,您可以通過使用具有以下格式的資源引用來引用部署來在模板中使用這些輸出
reference(resourceName or resourceIdentifier, [apiVersion], ['Full'])
請注意,您需要提供 api 版本,因為部署可能使用與您的父模板使用的 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
作為依賴部署的輸入,並將其放入具有鍵"value": "...."
。 這是因為 ARM 參數必須具有“值”屬性才能有效。
如果您嘗試直接使用輸出,您將收到無效模板錯誤(因為output
變量具有“類型”並且這不是parameter
允許的鍵)。 這就是為什么您需要獲取value
屬性,然后將其放回下游模板中的value
。
你在使用 Azure DevOps 發布管道嗎? 您可以將要創建的輸出設置為變量,以便您可以在相同或不同的階段重新使用它們。
我們在我們的項目中使用這些擴展
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.