【发布时间】:2019-08-13 23:01:10
【问题描述】:
我有一个功能性 ARM 模板,用于部署一个带有依赖 SQL 数据库的简单 SQL Server。我正在尝试输出 connectionString,但出现以下错误:
{"code":"DeploymentOutputEvaluationFailed","message":"Unable to evaluate template outputs: 'DatabaseConnectionString'. Please see error details and deployment operations. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"DeploymentOutputEvaluationFailed","target":"DatabaseConnectionString","message":"The template output 'DatabaseConnectionString' is not valid: The language expression property 'administratorLoginPassword' doesn't exist, available properties are 'administratorLogin, version, state, fullyQualifiedDomainName'.."}]}
有人可以看看我做错了什么。我能够创建资源,但没有连接字符串的输出,这就是我得到的错误。
- 我已检查以确保我的参数名称正确。
- 我已经使用 Visual Studio 验证了我的模板,它说它是有效的。
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
},
"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;')]"
}
}
}
azuredeploy.parameters.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"
}
}
}
}
【问题讨论】:
-
您可以使用
parameters('sqlserverAdminLoginPassword'),而不是使用reference(parameters('sqlserverName')).administratorLoginPassword。因为密码是秘密,我认为您无法使用reference找回它。 -
@Thomas 官方推荐方式有参考techcommunity.microsoft.com/t5/Azure-Database-Support-Blog/…
-
@HariHaran,这篇文章已经有 3 年历史了,也不是官方的。
-
@Thomas,谢谢!像魅力一样工作:)
标签: azure powershell arm-template