I would like to deploy ARM templates individually rather than linked templates/nested templates/multiple resources.
Ex: Deploy a Sql Server and database
I created individual templates for Sql Server and Sql database . I deployed successfully and its working fine.
- Deploy Sql Server ARM template(Specifically designed only for sql server)
- Deploy Sql Server Database(Specifically designed only for sql database with above sql server name mentioning in parameters file)
While deploying Sql database arm template , I had specified accurate sql server name(deployed in Step1) in parameters file of step2 but I did not mentioned "dependson" parameter in resource section and directly deployed .Database creation successfully under the resource group I selected while deployment process.
My Query:
How can I make sure Sql database arm template is deploying under specific server name(Step1) only without dependson parameter?
or
How to use existing reference resource id in resources section without dependson?
Will output of step1(resourceid) of sql server will be any helpful?
Sql ARM Template Deploy JSON:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"collation": {
"type": "string",
"defaultValue": "SQL_Latin1_General_CP1_CI_AS",
"metadata": {
"description": "The collation of the database."
}
},
"edition": {
"type": "string",
"metadata": {
"description": "The edition of the database. The DatabaseEditions enumeration contains all the valid editions. e.g. Basic, Premium."
},
"defaultValue": "Basic"
},
"sqlservername": {
"type": "string",
"metadata": {
"description": "The name of the sql server."
}
},
"databasename": {
"type": "string",
"metadata": {
"description": "The name of the database to be operated on (updated or created)."
},
"minLength": 7,
"maxLength": 128
},
"maxSizeBytes": {
"type": "string",
"metadata": {
"description": "The max size of the database expressed in bytes."
}
},
"serviceobjectivename": {
"type": "string",
"metadata": {
"description": "The configured service level objective ID of the database. This is the service level objective that is in the process of being applied to the database."
},
"defaultValue": "Basic"
},
"tagsArray": {
"type": "object",
"metadata": {
"description": "Resource Tags helps to indentify the use of service"
}
}
},
"functions": [],
"variables": {
"sqldatabasename": "[concat(parameters('sqlservername'),'/',parameters('databasename'))]"
},
"resources": [
{
"name": "[variables('sqldatabasename')]",
"type": "Microsoft.Sql/servers/databases",
"apiVersion": "2014-04-01",
"location": "[parameters('location')]",
"tags": "[parameters('tagsArray')]",
"properties": {
"collation": "[parameters('collation')]",
"edition": "[parameters('edition')]",
"maxSizeBytes": "[parameters('maxSizeBytes')]",
"requestedServiceObjectiveName": "[parameters('serviceobjectivename')]"
}
}
],
"outputs": {
"sqldatabaseresourceId": {
"type": "object",
"value": "[reference(resourceId('Microsoft.Sql/servers/databases',parameters('sqlservername'), parameters('databasename')),'2014-04-01')]"
}
}
}
Template Parameters:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"tagsArray": {
"value": {
"Environment": "POC"
}
},
"servername": {
"value": "sql-test"
},
"sqlAdministratorLogin": {
"value": "sqladmin"
},
"sqlAdministratorLoginPassword": {
"value": "myPassword586@"
},
"firewallIpAddresses": {
"value": [
{
"start": "1.1.1.0",
"end": "1.1.1.1",
"clientName": "Clienttest1"
},
{
"start": "1.2.3.4",
"end": "1.2.3.16",
"clientName": "Clienttest2"
}
]
},
"location": {
"value": ""
}
}
}
reference
with SQL server resource id to get server information in the resource section – Jim Xu