Search code examples
azurepowershellazure-resource-managerazure-rm-template

Azure ARM Template for SQL Server not printing connectionString


I have a functional ARM template to deploy a simple SQL Server with a dependent SQL database. I am trying to output the connectionString but I am getting the following error:

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

Can someone please see what I'm doing wrong. I am able to create the resources but there is no output of the connectionString and that's the error I get.

  1. I've checked to make sure my parameter names are correct.
  2. I've validated my template using Visual Studio and it says it is valid.

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"
      }
    }
  }
}

Solution

  • According to my test, The "reference(parameters('sqlserverName'))" does not has a property "administratorLoginPassword ", it just has properties"administratorLogin version state fullyQualifiedDomainName". If you need the password, please use "parameters('sqlserverAdminLoginPassword')". My test is below 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