SQL 带有随机密码和密码的服务器 ARM 模板保存到 Key Vault

SQL Server ARM Template with random password and password save to Key Vault

我正在寻找用于部署 Azure SQL 服务器的 ARM 模板,该服务器生成了随机密码,稍后该密码被保存到密钥库中。

请问大家有遇到过这样的ARM模板吗

请参考本教程:Automatically generate a password for an Azure SQL database with ARM template:

它谈到了如何创建一个 ARM 模板,该模板将使用自动生成的密码创建 Azure SQL 数据库。

您可以在此处下载示例 ARM 模板解决方案:

  1. Download full sources
  2. Browse the GitHub repository

您想在 Key Vault 中设置相同的密码,您可以了解:Set and retrieve a secret from Azure Key Vault using an ARM template

@LeonYue

您的 link 问题出在以下作者代码中:

"sqlserverAdminPassword": "[concat('P', uniqueString(resourceGroup().id, '224F5A8B-51DB-46A3-A7C8-59B0DD584A41'), 'x', '!')]",

查看 uniqueString 的定义是:

Creates a deterministic hash string based on the values provided as parameters.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string#uniquestring

这意味着密码不是随机的,只要给定正确的参数就可以计算出来。

您可以通过为每个部署插入一个新的 Guid 来解决这个问题,但是您的密码也会在每次部署时更新。

"parameters": {
  "newGuid": {
    "type": "string",
    "defaultValue": "[newGuid()]"
  }
}

"variables": {
  "sqlserverAdminPassword": "[concat(uniqueString(guid(resourceGroup().id, deployment().name)), parameters('newGuid'), 'Tg2%')]"
}

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string#guid

newGuid 被添加为参数,因为这是可以使用此函数的唯一方式。

This function can only be used in the default value for a parameter.

https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-string#newguid