Logo

dev-resources.site

for different kinds of informations.

ARM Template: Azure SQL Server

Published at
6/28/2024
Categories
arm
azure
sqlserver
iac
Author
srinivasuluparanduru
Categories
4 categories in total
arm
open
azure
open
sqlserver
open
iac
open
Author
20 person written this
srinivasuluparanduru
open
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

iac Article's
30 articles in total
Favicon
Customize VPCs with CloudFormation Conditions
Favicon
Provision EKS Cluster with Terraform, Terragrunt & GitHub Actions
Favicon
Terraform - Mastering Idempotency Violations - Handling Resource Conflicts and Failures in Azure
Favicon
OpenTofu - Infrastructure configuration management
Favicon
Goliat Shield: Your first line of defense
Favicon
Using CloudFormation to deploy a web app with HA
Favicon
KCL + Crossplane: A Declarative Language for Deploying Complex Infrastructure on AWS with Kubernetes.
Favicon
Terraform Remote Backend: How to Manage Terraform State File for Easier Collaboration across Teams
Favicon
Let's Talk Infrastructure as Code (IaC) 🚀
Favicon
Conditional deployment in Azure Bicep
Favicon
Learning Ansible, Proxmox and LXC, Part 1
Favicon
Create your K3S lab on Google Cloud
Favicon
Mastering Multi-Cloud Infrastructure with Terraform: A Game-Changer for Modern IT
Favicon
The KISS Principle: Why Simplicity is Key in Dev and DevOps (and How to Implement It)
Favicon
user-defined type in Azure Bicep, an introduction
Favicon
You Are Not Saved By IaC
Favicon
Terraform Tactics: A Guide to Mastering Terraform Commands for DevOps
Favicon
Infrastructure as Code with Terraform
Favicon
What is Infrastructure as Code (IaC) and Why It's Transforming DevOps
Favicon
Managing Infrastructure as Code at Amazon: Tools, Strategies, and Practices
Favicon
Automating AWS Cost and Usage Report with CloudFormation
Favicon
Crossplane + AWS Overview for Managing Infrastructure as Code (IaC) with Kubernetes
Favicon
How IaC can streamline the Infrastructure & Configuration
Favicon
Secure Terraform Solution for Government Agencies
Favicon
IAC - Azure WebApp creation
Favicon
Terraform pipeline (IaC for AWS)
Favicon
Terraform
Favicon
ARM Template: Azure SQL Server
Favicon
9 Ways to Spin Up an EKS Cluster - Way 3 - eksctl
Favicon
What is Infrastructure as Code (IaC)?

Featured ones: