我正在尝试从存储在默认存储帐户中的 vhd 图像在我的 Azure DevTestLab 中创建自定义图像。
我开始在GitHub存储库中修改用于从 vhd 创建自定义图像的 ARM 模板文件。
我已经创建了 DevTest 实验室,我可以运行以下 Powershell 命令来获取其数据:
PS C:\git> $rid = Get-AzureRmResource -ResourceGroupName jgTl9-rg -ResourceType Microsoft.DevTestLab/labs -ResourceName jgTl9 -ApiVersion 2016-05-15
这会产生大量信息。如果要提取默认存储帐户名称,请执行以下操作:
PS C:\git> $rid.properties.defaultStorageAccount
所以我知道有可能得到它。现在我修改了 Azure 构建模板(一个 JSON 文件)的变量部分,如下所示:
"variables": {
"resourceName": "[concat(variables('existingLabName'), '/', variables('imageName'))]",
"resourceType": "Microsoft.DevTestLab/labs/customimages",
"existingLabName": "[replace(resourceGroup().name,'-rg','')]",
"storageAccountID": "/subscriptions/xxxxxxxxxxxx/resourceGroups/jgTl9-rg/providers/Microsoft.Storage/storageAccounts/djgtl91795",
"saidFrags": "[skip(split(variables('storageAccountID'), '/' ), add(length(split(variables('storageAccountID'), '/' )),-1) ) ]",
"storageAccountSuffix": "[take(variables('saidFrags'),1)[0]]",
"existingVhdUri": "[concat('https://',variables('storageAccountSuffix'),'.blob.core.windows.net/uploads/',parameters('imageFileName'))]",
"imageName": "JaysImage"
},
当我使用 azuredeploy.json 和 azuredeploy.parameters.json 调用 New-AzureRmResourceGroupDeployment 命令时,此代码实际上有效。
但是,我不想硬编码storageAccountID变量,而是想从环境中提取 defaultStorageAccount。我试过这样的事情:
"storageAccountID": "[string( resourceId(resourceGroup().name,'MicrosoftDevTestLab/labs','jgTl9').properties.defaultStorageAccount ))",
我对此尝试了一些变化,但没有任何效果。我需要使用什么语法来提取与我为 storageAccountID 硬编码的相同信息?
(我在微软对模板函数的描述中找不到任何东西)。