Two Resources to be created for Azure SQL Server
- Azure SQL Database Server for hosting the database
- SQL Database
ARM Template for Azure SQL Server
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"SQLLogin":{
"type": "string",
"metadata":{
"description":"The administrator user name"
}
},
"SQLPassword":{
"type": "secureString",
"metadata":{
"description":"The administrator user name"
}
},
},
"functions": [],
"variables": {},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2023-05-01-preview",
"name": "sqlserver24062024",
"location": "[resourceGroup().location]",
"properties":{
"administratorLogin": "[parameters('SQLLogin')]",
"administratorLoginPassword": "[parameters('SQLPassword')]"
}
},
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-05-01-preview",
"name": "[format('{0}/{1}','sqlserver24062024','appdb')]",
"location": "[resourceGroup().location]",
"sku":{
"name":"Basic",
"tier":"Basic"
},
"properties":{},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers','sqlserver24062024')]"
]
}
],
"outputs": {}
}
Explanation for the above template
Step1:
"parameters": {
"SQLLogin":{
"type": "string",
"metadata":{
"description":"The administrator user name"
}
},
"SQLPassword":{
"type": "secureString",
"metadata":{
"description":"The administrator user name"
}
},
}
- Two variable parameters SQL Login and SQL Password has been created in ARM Template and to pass dynamic values
Step2:
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2023-05-01-preview",
"name": "sqlserver24062024",
"location": "[resourceGroup().location]",
"properties":{
"administratorLogin": "[parameters('SQLLogin')]",
"administratorLoginPassword": "[parameters('SQLPassword')]"
}
},
- Above code is used for creating SQL Server for hosting the database and using two input parameters passed
Step3:
{
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2023-05-01-preview",
"name": "[format('{0}/{1}','sqlserver24062024','appdb')]",
"location": "[resourceGroup().location]",
"sku":{
"name":"Basic",
"tier":"Basic"
},
"properties":{},
"dependsOn": [
"[resourceId('Microsoft.Sql/servers','sqlserver24062024')]"
]
}
- Creating sql database only after the sql server is created by mentioning the dependency in dependsOn resourceId
Step4:Go to portal.azure.com and create a new resource group as arm-sql
Step5:Search with template deployment in azure portal and select the option highlighted in the picture
Step6: Select the custom template and paste the arm template code,select resource group and pass the parameters
then review and create
Conclusion : Code used for SQL Server and database using ARM Template
💬 If you enjoyed reading this blog post and found it informative, please take a moment to share your thoughts by leaving a review and liking it 😀 and follow me in dev.to , linkedin
Top comments (0)