0
votes

Trying to apply certificate from Azure key vault using multiple hostnames that I iterate in property section of the ARM template but it fails with message "HTTP request body must not be empty"

My ARM template looks like this:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appServiceName": {
      "type": "string",
      "metadata": {
        "description": "Name of app service to apply SSL to."
      }
    },
    "certificateName": {
      "type": "string",
      "metadata": {
        "description": "User friendly certificate resource name"
      }
    },
    "appServicePlan": {
      "type": "string",
      "metadata": {
        "description": "App Service Plan Name"
      }
    },
    "keyVaultId": {
      "type": "string",
      "metadata": {
        "description": "Existing Key Vault resource Id with an access policy to allow Microsoft.Web RP to read Key Vault secrets (Checkout README.md for more information)"
      }
    },
    "hostname": {
      "type": "array",
      "metadata": {
        "description": "Custom hostname for creating SSL binding. This hostname should already be assigned to the Web App"
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2016-03-01",
      "type": "Microsoft.Web/sites",
      "name": "[parameters('appServiceName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/certificates', parameters('certificateName'))]"
      ],
      "properties": {
        "copy": [
          {
            "name": "hostnames",
            "count": "[length(parameters('hostname'))]",
            "input": {
              "name": "[copyIndex('hostnames')]",
              "properties": {
                "hostNameSslStates": [
                  {
                    "name": "[parameters('hostname')[copyIndex('hostnames')]]",
                    "sslState": "SniEnabled",
                    "thumbprint": "[reference(resourceId('Microsoft.Web/certificates', parameters('certificateName'))).Thumbprint]",
                    "toUpdate": true
                  }
                ]
              }
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Web/certificates",
      "name": "[parameters('certificateName')]",
      "apiVersion": "2016-03-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "keyVaultId": "[parameters('keyVaultId')]",
        "keyVaultSecretName": "[parameters('certificateName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms',parameters('appServicePlan'))]"
      }
    }
  ]
}

And the error I get:

New-AzureRmResourceGroupDeployment : Resource Microsoft.Web/sites 'developapp' failed with message '{ "Code": "BadRequest", "Message": "HTTP request body must not be empty.", "Target": null, "Details": [ { "Message": "HTTP request body must not be empty." }, { "Code": "BadRequest" }, { "ErrorEntity": { "ExtendedCode": "51016", "MessageTemplate": "HTTP request body must not be empty.", "Parameters": [], "Code": "BadRequest", "Message": "HTTP request body must not be empty." } } ], "Innererror": null }' At line:1 char:1 + New-AzureRmResourceGroupDeployment -Name test -ResourceGroupName deve ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

VERBOSE: 13:52:43 - Resource Microsoft.Web/certificates 'testCert' provisioning status is succeeded New-AzureRmResourceGroupDeployment : 13:52:43 - Template output evaluation skipped: at least one resource deploym ent operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usag e details. At line:1 char:1 + New-AzureRmResourceGroupDeployment -Name test -ResourceGroupName deve ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

New-AzureRmResourceGroupDeployment : 13:52:43 - Template output evaluation skipped: at least one resource deploym ent operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usag e details. At line:1 char:1 + New-AzureRmResourceGroupDeployment -Name test -ResourceGroupName deve ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

Any of you guys have suggestion on what could be causing this? Thanks in advance!

1
is your array zero length by any chance? also, try including "serverFarmId": into the properties of the webapp, right before "copy": [4c74356b41
My parameters: "hostname": { "value": [ "projectapp.mydomain.com", "developapp.mydomain.com" ] } Not sure why I should add serverFarmId into properties of the webapp, can you explain closer`?A0r
well, all the examples online have this. webapp (app service) has to be linked to the app service plan (serverfarmid).4c74356b41
In this template I'm working towards existing webapp and I don't think that serverfarmid is required since I only want to bind SSL to existing webapp.A0r

1 Answers

0
votes

Try this instead of your copy:

"copy": [
    {
        "name": "hostNameSslStates",
        "count": "[length(parameters('hostname'))]",
        "input": {
            "name": "[parameters('hostname')[copyIndex('hostNameSslStates')]]",
            "sslState": "SniEnabled",
            "thumbprint": "[reference(resourceId('Microsoft.Web/certificates', parameters('certificateName'))).Thumbprint]",
            "toUpdate": true
        }
    }
]