Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARM Deployment failure - HTTP request body must not be empty #5099

Open
mmisztal1980 opened this issue Dec 7, 2017 · 13 comments

Comments

Projects
None yet
@mmisztal1980
Copy link

commented Dec 7, 2017

Cmdlet(s)

PowerShell Version

Name                           Value
----                           -----
PSVersion                      5.1.14393.1715
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.1715
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Module Version

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.0.1      AzureRM

OS Version

Instructions: to get OS version, type $PSversionTable and look for value associated with BuildVersion

Description

We are deploying a simple AppService template:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "environmentName": {
            "type": "string"
        },
        "nodeVersion": {
            "type": "string"
        },
        "appInsightsInstrumentationKey": {
            "type": "string"
        },
        "appServiceRenewalManagerTileWebApp": {
            "type": "string"
        },
        "subscriptionId": {
            "type": "string"
        },
        "appServiceResourceGroup": {
            "type": "string"
        },
        "appServicePlanId": {
            "type": "string"
        },
        "appServiceSSLThumbprint": {
            "type": "string"
        },
        "hostnamesRenewalManagerWebApp": {
            "type": "array"
        },
        "enabledhostnamesRenewalManagerWebApp": {
            "type": "array"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/sites",
            "name": "[parameters('appServiceRenewalManagerTileWebApp')]",
            "apiVersion": "2016-08-01",
            "location": "[resourceGroup().location]",
            "tags": {},
            "properties": {
                "name": "[parameters('appServiceRenewalManagerTileWebApp')]",
                "hostNames": "[parameters('hostnamesRenewalManagerWebApp')]",
                "enabledHostNames": [
                    "[parameters('enabledHostnamesRenewalManagerWebApp')]"
                ],
                "hostNameSslStates": [
                    {
                        "name": "[concat(parameters('appServiceRenewalManagerTileWebApp'),'.azurewebsites.net')]",
                        "sslState": 0,
                        "thumbprint": null,
                        "ipBasedSslState": 0
                    },
                    {
                        "name": "[concat(parameters('appServiceRenewalManagerTileWebApp'),'.scm.azurewebsites.net')]",
                        "sslState": 0,
                        "thumbprint": null,
                        "ipBasedSslState": 0
                    }
                ],
                "serverFarmId": "[resourceId(parameters('subscriptionId'), parameters('appServiceResourceGroup'), 'Microsoft.Web/serverfarms', parameters('appServicePlanId'))]",
                "siteConfig": {
                    "AlwaysOn": true,
                    "appSettings": [
                        {
                            "name": "ASPNETCORE_ENVIRONMENT",
                            "value": "[parameters('environmentName')]"
                        },
                        {
                            "name": "WEBSITE_NODE_DEFAULT_VERSION",
                            "value": "[parameters('nodeVersion')]"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[parameters('appInsightsInstrumentationKey')]"
                        }
                    ],
                    "connectionStrings": []
                }
            },
            "resources": [
                {
                    "apiVersion": "2016-08-01",
                    "name": "RedirectHttpToHttps",
                    "type": "siteextensions",
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/Sites', parameters('appServiceRenewalManagerTileWebApp'))]"
                    ],
                    "properties": {}
                }
            ],
            "dependsOn": []
        }
    ]
}

During deployment, we are using the New-AzureRmResourceGroupDeployment commandlet. The template appears to pass the validation stage, and the deployment begins. During the deployment. the PS Cmdlet appears to be sending a request with empty body, which results in a HTTP 400 Bad Request.

Debug Output

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/023e896a-62e5-46c0-8278-7b10d4dafd91/resourcegroups/nltapp0137rgp-test-renew
al-manager/deployments/renewal-manager-tile-web-app-test/operations?api-version=2017-05-10

Headers:
x-ms-client-request-id        : 964ffdef-d8e5-404b-aa29-6389d705ef29
accept-language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
x-ms-ratelimit-remaining-subscription-reads: 14975
x-ms-request-id               : 3a65fdb9-d802-43ed-aa50-a7d5a0b740e2
x-ms-correlation-request-id   : 3a65fdb9-d802-43ed-aa50-a7d5a0b740e2
x-ms-routing-request-id       : UKSOUTH:20171207T154520Z:3a65fdb9-d802-43ed-aa50-a7d5a0b740e2
Strict-Transport-Security     : max-age=31536000; includeSubDomains
Cache-Control                 : no-cache
Date                          : Thu, 07 Dec 2017 15:45:20 GMT

Body:
{
  "value": [
    {
      "id":
"/subscriptions/023e896a-62e5-46c0-8278-7b10d4dafd91/resourceGroups/nltapp0137rgp-test-renewal-manager/providers/Micros
oft.Resources/deployments/renewal-manager-tile-web-app-test/operations/B5373B3E483C5E07",
      "operationId": "B5373B3E483C5E07",
      "properties": {
        "provisioningOperation": "Create",
        "provisioningState": "Failed",
        "timestamp": "2017-12-07T15:45:17.7608919Z",
        "duration": "PT2.2347342S",
        "trackingId": "ae55f4f3-466d-442c-a933-1ee24be0938f",
        "serviceRequestId": "4ebfadf5-e5cc-46cb-bcba-c7a974d84ef8",
        "statusCode": "BadRequest",
        "statusMessage": {
          "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
        },
        "targetResource": {
          "id":
"/subscriptions/023e896a-62e5-46c0-8278-7b10d4dafd91/resourceGroups/nltapp0137rgp-test-renewal-manager/providers/Micros
oft.Web/sites/nltapp0137wap2-test-renewal-manager-tile-web-app",
          "resourceType": "Microsoft.Web/sites",
          "resourceName": "nltapp0137wap2-test-renewal-manager-tile-web-app"
        },
        "request": {
          "content": {
            "location": "westeurope",
            "tags": {},
            "properties": {
              "name": "nltapp0137wap2-test-renewal-manager-tile-web-app",
              "hostNames": [
                "nltapp0137wap2-test-renewal-manager-tile-web-app.azurewebsites.net"
              ],
              "enabledHostNames": [
                [
                  "nltapp0137wap2-test-renewal-manager-tile-web-app.azurewebsites.net",
                  "nltapp0137wap2-test-renewal-manager-tile-web-app.scm.azurewebsites.net"
                ]
              ],
              "hostNameSslStates": [
                {
                  "name": "nltapp0137wap2-test-renewal-manager-tile-web-app.azurewebsites.net",
                  "sslState": 0,
                  "thumbprint": null,
                  "ipBasedSslState": 0
                },
                {
                  "name": "nltapp0137wap2-test-renewal-manager-tile-web-app.scm.azurewebsites.net",
                  "sslState": 0,
                  "thumbprint": null,
                  "ipBasedSslState": 0
                }
              ],
              "serverFarmId":
"/subscriptions/91819a1c-c7d3-4b89-bc9f-39f85bff4666/resourceGroups/nltasp0022rgp/providers/Microsoft.Web/serverfarms/n
ltasp0022",
              "siteConfig": {
                "AlwaysOn": true,
                "appSettings": [
                  {
                    "name": "ASPNETCORE_ENVIRONMENT",
                    "value": "test"
                  },
                  {
                    "name": "WEBSITE_NODE_DEFAULT_VERSION",
                    "value": "4.4.7"
                  },
                  {
                    "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                    "value": "0d14114c-e884-4a06-8d58-0baff6988085"
                  }
                ],
                "connectionStrings": []
              }
            }
          }
        },
        "response": {
          "content": {
            "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
          }
        }
      }
    },
    {
      "id":
"/subscriptions/023e896a-62e5-46c0-8278-7b10d4dafd91/resourceGroups/nltapp0137rgp-test-renewal-manager/providers/Micros
oft.Resources/deployments/renewal-manager-tile-web-app-test/operations/08586889453714940785",
      "operationId": "08586889453714940785",
      "properties": {
        "provisioningOperation": "EvaluateDeploymentOutput",
        "provisioningState": "Failed",
        "timestamp": "2017-12-07T15:45:18.2513924Z",
        "duration": "PT0.2884839S",
        "trackingId": "5dd4f75d-216a-41ab-acfc-c04de8ca6ba4",
        "statusCode": "Conflict",
        "statusMessage": "Template output evaluation skipped: at least one resource deployment operation failed. Please
 list deployment operations for details. Please see https://aka.ms/arm-debug for usage details."
      }
    }
  ]
}

New-AzureRmResourceGroupDeployment : 16:45:20 - Resource Microsoft.Web/sites 'nltapp0137wap2-test-renewal-manager-tile-
web-app' 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 C:\Checkout\ops-arm-templates\area404\Deploy-Template.ps1:76 char:5
+     New-AzureRmResourceGroupDeployment -Name $parameters.Get_Item("De ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzureRmResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDep
   loymentCmdlet

Please advise - is this an issue with our template?

@markcowl

This comment has been minimized.

Copy link
Member

commented Dec 12, 2017

@mmisztal1980 Yes, this appears to be an issue in which the ARM template deployment is making an empty request to the AppService ResourceProvider. You cna use the request id or correlation id in the debug output to find the service error and diagnose the template

@mmisztal1980

This comment has been minimized.

Copy link
Author

commented Dec 12, 2017

@markcowl Hi Mark, thanks for the response. Can you elaborate on how to diagnose the issue? I'll retrieve the requestId/correlationId tomorrow, while at the office.

@maddieclayton

This comment has been minimized.

Copy link
Contributor

commented Jan 23, 2018

@ravbhatnagar @vivsriaus Can you take a look at this issue? It looks like it could be a service side issue.

@cpumanaz

This comment has been minimized.

Copy link

commented Mar 11, 2018

I am having this same error when attempting to update resources. Outside the template using
Set-AzureRmResource

$AppConfig | Set-AzureRmResource -ApiVersion $APIVersion -Force | Out-Null

Using API 2016-08-01

Using the Microsoft.Web/sites/config Resource Type
Get-AzureRmResource -ResourceType Microsoft.Web/sites/config

@omnoms

This comment has been minimized.

Copy link

commented Apr 23, 2018

I am also having this issue when trying to update iprestriction on a website, also Microsoft.Web/sites/config Resource Type.

Import-Module AzureRM
Login-AzureRmAccount
$config = get-azurermresource -ResourceName my-web-application -ResourceType Microsoft.Web/sites/config -ResourceGroupName  MyResourceGroup -ApiVersion '2016-08-01'
$ips = $config.Properties.ipSecurityRestrictions
"52.28.56.226,52.28.45.240,52.16.224.164,52.16.193.66,34.253.4.94,52.50.106.250,52.211.56.181,52.213.38.246,52.213.74.69,52.213.216.142,35.156.51.163,35.157.221.52,52.28.184.187,52.28.212.16,52.29.176.99,52.57.230.214".split(",") | % { $ips += @([PSCustomObject] @{ ipAddress = $_; subnetMask = $null }) }
$config.Properties.ipSecurityRestrictions = $ips
Set-AzureRMResource -ResourceId $config.ResourceId -Properties $config.Properties -ApiVersion '2016-08-01'

Confirm
Are you sure you want to update the following resource:
/subscriptions/xxx-xxx-xxx-xxx-xxx-xxx-xxx/resourceGroups/MyResourceGroup/providers/Microsoft.Web/sites/my-web-application/co
nfig/web
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y
Set-AzureRMResource : {"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","MessageT
emplate":"HTTP request body must not be empty.","Parameters":[],"Code":"BadRequest","Message":"HTTP request body must n
ot be empty."}}],"Innererror":null}
At line:1 char:1
+ Set-AzureRMResource -ResourceId $config.ResourceId -Properties $confi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Set-AzureRmResource], ErrorResponseMessageException
    + FullyQualifiedErrorId : BadRequest,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.SetAzureResou
   rceCmdlet
@omnoms

This comment has been minimized.

Copy link

commented Apr 26, 2018

I've reproduced this behaviour by doing a PUT request to the Azure REST api through postman as if it was a PATCH it will produce this result. A proper PUT request with the full object in the request through postman will succeed. So I am suspecting that it's trying to behave as if it was a PATCH request, while actually sending a PUT request.

I will check with fiddler next.

Oh and passing the full $config to set-azurermresource makes no difference.

@omnoms

This comment has been minimized.

Copy link

commented Apr 26, 2018

As I suspected, even with passing the full configuration, when the powershell cmdlet composes the body, it's only sending the properties, and nothing else. So it's not a complete object for a valid PUT request. This is why it's failing.

PUT https://management.azure.com/subscriptions/<subscriptionId>/resourceGroups/<resourceGroup>/providers/Microsoft.Web/sites/<webapp>/config/web?api-version=2016-08-01 HTTP/1.1
Authorization: Bearer <token redacted>
User-Agent: AzurePowershell/v5.7.0 PSVersion/v5.1.14393.2189
ParameterSetName: ByResourceId
CommandName: Set-AzureRmResource
Content-Type: application/json; charset=utf-8
Host: management.azure.com
Content-Length: 5652
Expect: 100-continue

{
  "properties": {
    "numberOfWorkers": "1",
    "defaultDocuments": [
      "Default.htm",
      "Default.html",
      "Default.asp",
      "index.htm",
      "index.html",
...
@omnoms

This comment has been minimized.

Copy link

commented Apr 26, 2018

Also noted that despite having added the ips so that they look proper in the object and when checking $config.properties.ipSecurityRestrictions, what it sends in the request is not what should be there. So there's also an issue with serializing.

      ...
      {
        "ipAddress": {
          "Length": "12"
        },
        "subnetMask": null
      },
      {
        "ipAddress": {
          "Length": "12"
        },
        "subnetMask": null
      },
      ...
@omnoms

This comment has been minimized.

Copy link

commented Apr 26, 2018

So I got this to work with some adjustments.

First, to strictly cast the passed String object to string when adding the IPs from the comma-delimited string with [string]$_. That fixes the issue with String Object serialization in the request

Secondly, since it's behaving as PATCH regardsless of being a PUT or PATCH, use the flag -UsePatchSemantics and it sends a proper patch request instead.

This is more of a workaround until the actual cmdlet gets fixed.

@omnoms

This comment has been minimized.

Copy link

commented Apr 26, 2018

Final script

Import-Module AzureRM
Login-AzureRmAccount
$config = get-azurermresource -ResourceName my-web-application -ResourceType Microsoft.Web/sites/config -ResourceGroupName  MyResourceGroup -ApiVersion '2016-08-01'
$ips = $config.Properties.ipSecurityRestrictions
"52.28.56.226,52.28.45.240,52.16.224.164,52.16.193.66,34.253.4.94,52.50.106.250,52.211.56.181,52.213.38.246,52.213.74.69,52.213.216.142,35.156.51.163,35.157.221.52,52.28.184.187,52.28.212.16,52.29.176.99,52.57.230.214".split(",") | % { $ips += @([PSCustomObject] @{ ipAddress = [string]$_; subnetMask = $null }) }
$config.Properties.ipSecurityRestrictions = $ips
$config | Set-AzureRMResource -ApiVersion '2016-08-01' -UsePatchSemantics

@cormacpayne cormacpayne assigned Tiano2017 and unassigned vivsriaus Jun 8, 2018

@mmisztal1980

This comment has been minimized.

Copy link
Author

commented Jun 22, 2018

Soooo, it's been 6 months, and the issue reappeared for me. Is there anyone who can grace this issue with a potential reason for the issue to occur?

@AlexKeySmith

This comment has been minimized.

Copy link

commented Sep 3, 2018

I'm seeing something similar using Azure RM 6.2.1, we end up with the IP restrictions in an odd state, in the portal the rules have no names.

@Swimburger

This comment has been minimized.

Copy link

commented May 31, 2019

I ran into the same issue when using Az powershell, after googling for long I saw an example where hashtables were used for the individual ipSecurityRestriction objects. These didn't suffer from the same parsing issues as @omnoms.
PSCustomObjects did have the weird parsing where instead of the string, it would be an object with a length property inside.

Edit: blogged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.