我有一个功能齐全的ARM模板,用于部署带有相关SQL数据库的简单SQL Server。我正在尝试输出connectionString,但是出现以下错误:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sqlserverName": {
"type": "string",
"minLength": 1,
"defaultValue": "[concat('sqlserver', uniqueString(resourceGroup().id))]"
},
"sqlserverAdminLogin": {
"type": "string",
"minLength": 1
},
"sqlserverAdminLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL Server."
}
},
"dbName": {
"type": "string",
"minLength": 1
},
"dbCollation": {
"type": "string",
"minLength": 1,
"defaultValue": "SQL_Latin1_General_CP1_CI_AS"
},
"dbEdition": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"dbRequestedServiceObjectiveName": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"S0",
"S1",
"S2",
"P1",
"P2",
"P3"
],
"metadata": {
"description": "Describes the performance level for Edition"
}
}
},
"variables": {
"sqlserverName": "[parameters('sqlserverName')]",
"databaseName": "[parameters('dbName')]"
},
"resources": [
{
"name": "[variables('sqlserverName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [ ],
"tags": {
"displayName": "sqlserver"
},
"properties": {
"administratorLogin": "[parameters('sqlserverAdminLogin')]",
"administratorLoginPassword": "[parameters('sqlserverAdminLoginPassword')]"
},
"resources": [
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"name": "[parameters('dbName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"tags": {
"displayName": "db"
},
"properties": {
"collation": "[parameters('dbCollation')]",
"edition": "[parameters('dbEdition')]",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "[parameters('dbRequestedServiceObjectiveName')]"
}
}
]
}],
"outputs": {
"sqlServerName": {
"type": "string",
"value": "[reference(concat('Microsoft.Sql/servers/', variables('sqlServerName'))).fullyQualifiedDomainName]"
},
"databaseName": {
"type": "string",
"value": "[variables('databaseName')]"
},
"DatabaseConnectionString": {
"type": "string",
"value": "[concat('Server=tcp:',reference(variables('sqlserverName')).fullyQualifiedDomainName,',1433;Initial Catalog=',parameters('dbName'),';Persist Security Info=False;User ID=',reference(parameters('sqlserverName')).administratorLogin,';Password=',reference(parameters('sqlserverName')).administratorLoginPassword,';MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;')]"
}
}
}
有人可以看看我在做什么错。我能够创建资源,但是connectionString没有输出,这就是我得到的错误。
azuredeploy.json
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
/*Parameters for SQL Server */
"sqlserverName": {
"value": "talhasqlserver",
"metadata": {
"description": "This is your SQL Server name"
}
},
"sqlserverAdminLogin": {
"value": "talha",
"metadata": {
"description": "This is your SQL Server Login"
}
},
"sqlserverAdminLoginPassword": {
"value": "bleh",
"metadata": {
"description": "This is your SQL Server password. For privacy concerns, consider using KeyVault reference here."
}
},
/*Parameters for SQL Database */
"dbName": {
"value": "talhadbname",
"metadata": {
"description": "This is your SQL DB name."
}
},
"dbCollation": {
"value": "SQL_Latin1_General_CP1_CI_AS"
},
"dbEdition": {
"value": "Basic"
},
"dbRequestedServiceObjectiveName": {
"value": "Basic",
"metadata": {
"description": "Describes the performance level for Edition"
}
}
}
}
azuredeploy.parameters.json
{{1}}
答案 0 :(得分:1)
根据我的测试,“ reference(parameters('sqlserverName'))
”不具有属性“ administratorLoginPassword
”,而仅具有属性“ administratorLogin version state fullyQualifiedDomainName
”。如果需要密码,请使用“ parameters('sqlserverAdminLoginPassword')
”。我的测试如下
azuredeploy.json:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"sqlserverName": {
"type": "string",
"minLength": 1,
"defaultValue": "[concat('sqlserver', uniqueString(resourceGroup().id))]"
},
"sqlserverAdminLogin": {
"type": "string",
"minLength": 1,
"defaultValue":"jimtest"
},
"sqlserverAdminLoginPassword": {
"type": "securestring",
"metadata": {
"description": "The administrator password of the SQL Server."
},
"defaultValue":"Password0123!"
},
"dbName": {
"type": "string",
"minLength": 1,
"defaultValue": "[concat('db', uniqueString(resourceGroup().id))]"
},
"dbCollation": {
"type": "string",
"minLength": 1,
"defaultValue": "SQL_Latin1_General_CP1_CI_AS"
},
"dbEdition": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"Standard",
"Premium"
]
},
"dbRequestedServiceObjectiveName": {
"type": "string",
"defaultValue": "Basic",
"allowedValues": [
"Basic",
"S0",
"S1",
"S2",
"P1",
"P2",
"P3"
],
"metadata": {
"description": "Describes the performance level for Edition"
}
}
},
"variables": {
"sqlserverName": "[parameters('sqlserverName')]",
"databaseName": "[parameters('dbName')]"
},
"resources": [
{
"name": "[variables('sqlserverName')]",
"type": "Microsoft.Sql/servers",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [ ],
"tags": {
"displayName": "sqlserver"
},
"properties": {
"administratorLogin": "[parameters('sqlserverAdminLogin')]",
"administratorLoginPassword": "[parameters('sqlserverAdminLoginPassword')]"
},
"resources": [
{
"name": "AllowAllWindowsAzureIps",
"type": "firewallrules",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"name": "[parameters('dbName')]",
"type": "databases",
"location": "[resourceGroup().location]",
"apiVersion": "2014-04-01-preview",
"dependsOn": [
"[resourceId('Microsoft.Sql/servers', variables('sqlserverName'))]"
],
"tags": {
"displayName": "db"
},
"properties": {
"collation": "[parameters('dbCollation')]",
"edition": "[parameters('dbEdition')]",
"maxSizeBytes": "1073741824",
"requestedServiceObjectiveName": "[parameters('dbRequestedServiceObjectiveName')]"
}
}
]
}],
"outputs": {
"ServerObject": {
"type": "Object",
"value": "[reference(variables('sqlServerName'))]"
},
"Passwording":{
"type":"string",
"value":"[parameters('sqlserverAdminLoginPassword')]"
}
}
}