通过模板从存储帐户安装应用程序.json文件. .我们需要通过参数传递storageName和Key,所以它不是硬编码的



我一直在敲我的头撞墙关于这一个,因为我无法弄清楚如何获得storage_accountname和Key从参数文件传递到模板。我正在努力找到任何明确的指南或例子…

我们想要达到的是这个。我们需要通过arm模板将Sophos AV安装为虚拟机部署的一部分。当存储帐户的详细信息被硬编码到模板文件中时,arm模板工作并运行。Ps1(保存安装程序运行)

我非常接近完成自定义部署脚本为我们,但我卡住了这件事,因为我不希望像存储帐户密钥硬编码到模板的敏感信息。

下面的模板文件片段将storeageaccountname和密钥硬编码到模板中。

更新

  • 为storage_accountresourcegroupname添加默认值
  • 将storageAccountResourceGroupName添加到storageAccountName
  • 更新storageAccountName

template.json

"parameters": {
"storageAccountResourceGroupName":{
"type": "string",
"defaultValue": "RSG2"
"storageAccountName": {
"type": "string",
"defaultValue": "filesstgacct"
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('virtualMachineName'), '/MyCustomScriptExtension')]",
"apiVersion": "2015-05-01-preview",
"location": "[parameters('location')]",
"dependsOn": [ "[concat('Microsoft.Compute/virtualMachines/',parameters('virtualMachineName'))]" ],
"tags": "[parameters('tags')]",
"properties": { "publisher": "Microsoft.Compute",
"type": "CustomScriptExtension", "typeHandlerVersion": "1.3", "autoUpgradeMinorVersion": true,
"settings": { 
"fileUris": [ "https://storage-account-name.blob.core.windows.net/scripts/sophos.ps1" 
]
},
"protectedSettings": {
"commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File sophos.ps1",
"storageAccountName": "[parameters('storageAccountName')]",
"storageAccountKey": "[listKeys(resourceid(parameters['storageAccountResourceGroupName'], 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value]"

}
}
}

storage_accountname和key是否可以存储在参数文件中?如果是,那么我如何将两者联系起来?

是的。我相信你不能读取值的原因是因为你没有正确地指定参数。请尝试如下:

"parameters": {
"storageAccountName": {
"type": "string",
"defaultValue": "storage-account-name"
},
"storageAccountKey": {
"type": "string",
"defaultValue": "storage-account-key"
}
}

也可以引用存储帐户密钥直接从模板/参数文件中获取,这意味着该键永远不会硬编码吗?

实际上,这是推荐的方法,您不需要在模板文件中硬编码存储帐户密钥。你可以做的是使用listKeys模板函数动态获取键。您所要做的就是提供存储帐户的完整资源id和API版本。

你可能会使用这样的语句:

"storageAccountKey": "[listKeys(resourceid(resourceGroup().name, 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), providers('Microsoft.Storage', 'storageAccounts').apiVersions[0]).keys[0].value]"

和ARM模板处理器将自动获取您的存储帐户的帐户密钥。