SQL Server 的 Azure ARM 模板不打印连接字符串

标签 azure powershell azure-resource-manager azure-rm-template

我有一个功能性 ARM 模板,用于部署带有依赖 SQL 数据库的简单 SQL Server。我正在尝试输出连接字符串,但收到以下错误:

{
  "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'.."
    }
  ]
}

有人可以看看我做错了什么吗?我能够创建资源,但没有连接字符串的输出,这就是我收到的错误。

  1. 我已检查以确保我的参数名称正确。
  2. 我已使用 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"
      }
    }
  }
}

最佳答案

根据我的测试,“reference(parameters('sqlserverName'))”没有属性“administratorLoginPassword”,它只有属性“administratorLogin 版本状态 fullQualifiedDomainName”。如果您需要密码,请使用“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')]"

      }
  }


}

enter image description here

关于SQL Server 的 Azure ARM 模板不打印连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57486279/

相关文章:

azure - 为 ASP.NET 和 Wordpress 创建博客的子域

.net - 如何保护Azure存储/服务总线中的访问 key

azure - 是否可以导出 azure 函数的 ARM 模板?

azure - 授予 Azure Function 对 ARM REST API 的访问权限

Azure API 连接 : Change the connection name

c# - 从存储帐户 blob 读取和解析 Azure IoT 中心遥测

azure - 如何备份我的 Windows Azure 表存储?

从 Webhook 触发时 Azure 自动化 Runbook 失败

powershell - ssh-keygen: 系统找不到指定的路径

powershell - 如何将参数传递给 Powershell 脚本并在远程计算机上运行它