I'm looking for ARM Template to deploy Azure SQL Server with random password generated and later that password is saved into the key vault.
Could you please let me know if any of you have come across such ARM Template.
I'm looking for ARM Template to deploy Azure SQL Server with random password generated and later that password is saved into the key vault.
Could you please let me know if any of you have come across such ARM Template.
@LeonYue
The problem with your link is the authors code below:
"sqlserverAdminPassword": "[concat('P', uniqueString(resourceGroup().id, '224F5A8B-51DB-46A3-A7C8-59B0DD584A41'), 'x', '!')]",
Looking at the definition for uniqueString it is:
Creates a deterministic hash string based on the values provided as parameters.
This means that the password is not random and given the correct parameters it can be calculated.
You can solve this by inserting a new Guid for every deployment but then your password will also be updated on every deployment.
"parameters": {
"newGuid": {
"type": "string",
"defaultValue": "[newGuid()]"
}
}
"variables": {
"sqlserverAdminPassword": "[concat(uniqueString(guid(resourceGroup().id, deployment().name)), parameters('newGuid'), 'Tg2%')]"
}
newGuid is added as a parameter because that is the only way this function can be used.
This function can only be used in the default value for a parameter.
Please ref this tutorial: Automatically generate a password for an Azure SQL database with ARM template:
It talked about how to create an ARM template that will create an Azure SQL database with an automatically generated password.
You can download the example ARM Template solution here:
You want to same the password in Key vault, you may learn: Set and retrieve a secret from Azure Key Vault using an ARM template.