{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "principalId": {
      "type": "string",
      "metadata": {
        "description": "Principal ID to set the access for"
      }
    },
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "The storage account to set access for"
      }
    }
  },
  "variables": {
    "contributor": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
    "RBACResourceName": "[concat(parameters('storageAccountName'), '/Microsoft.Authorization/', parameters('principalId'))]"
  },
  "resources": [
    {
      "apiVersion": "2016-07-01",
      "name": "[variables('RBACResourceName')]",
      "type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
      "properties": {
        "roleDefinitionId": "[variables('contributor')]",
        "principalId": "[parameters('principalId')]",
        "scope": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      }
    }
  ]
}

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "principalId": {
      "type": "string",
      "metadata": {
        "description": "Principal ID to set the access for"
      }
    },
    "storageAccountName": {
      "type": "string",
      "metadata": {
        "description": "The storage account to set access for"
      }
    }
  },
  "variables": {
    "contributor": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', 'b24988ac-6180-42a0-ab88-20f7382dd24c')]",
    "RBACResourceName": "[concat(parameters('storageAccountName'), '/Microsoft.Authorization/', parameters('principalId'))]"
  },
  "resources": [
    {
      "apiVersion": "2018-09-01-preview",
      "name": "[variables('RBACResourceName')]",
      "type": "Microsoft.Storage/storageAccounts/providers/roleAssignments",
      "properties": {
        "roleDefinitionId": "[variables('contributor')]",
        "principalId": "[parameters('principalId')]",
        "principalType":"ServicePrincipal",
        "scope": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      }
    }
  ]
}

Add principleType to avoid race condition
Add principleType to avoid race condition

Setting the principleType to ServicePrincipal to avoid possible race conditions that exist when attempting to use a new service principal before it has replicated throughout the AAD tenant.  I also updated the API version to the version that supports the principleType property.