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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay