DEV Community

Srinivasulu Paranduru for cloudteachable

Posted on • Edited on

ARM Template: Azure SQL Server

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": {}
}
Enter fullscreen mode Exit fullscreen mode
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"
            }
        },
    }
Enter fullscreen mode Exit fullscreen mode
  • 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')]"
            }
        },
Enter fullscreen mode Exit fullscreen mode
  • 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')]"
            ]
        }

Enter fullscreen mode Exit fullscreen mode
  • 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

Image description

Step6: Select the custom template and paste the arm template code,select resource group and pass the parameters

Image description

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

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay