【问题标题】:Azure ARM template deployment. The value for template parameter not providedAzure ARM 模板部署。未提供模板参数的值
【发布时间】:2020-07-03 14:39:04
【问题描述】:

我正在扩展其中一个 Azure 快速入门模板来部署带有 VNET 集成的 Azure Web 应用程序。已经创建了 RG、网络组件和应用服务计划(使用 powershell)。我正在使用 ARM 模板来部署 Web 应用程序。但我在执行部署时遇到以下错误。

我使用 JSON Lint 来验证 JSON 并且看起来没问题。错误代码告诉我参数文件的语法存在问题,但我无法查明它。我尝试了很多方法来调试它,但无法修复它。

错误:

PS C:\Users\manjug\Desktop> New-AzResourceGroupDeployment `
        -Name 'test01' `
        -ResourceGroupName ITQIG-eu-manjug-windows-app `
        -TemplateParameterUri C:\Users\manjug\Desktop\azuredeploy_webapp.parameters.json `
        -TemplateUri C:\Users\manjug\Desktop\azuredeploy_webapp.json `
        -Verbose
VERBOSE: Performing the operation "Creating Deployment" on target "ITQIG-eu-manjug-windows-app".
New-AzResourceGroupDeployment : 2:22:59 PM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The value for the template parameter 'appName' at line '7' and 
column '20' is not provided. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.
At line:1 char:1
+ New-AzResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-AzResourceGroupDeployment], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet
 
New-AzResourceGroupDeployment : The deployment validation failed
At line:1 char:1
+ New-AzResourceGroupDeployment `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [New-AzResourceGroupDeployment], InvalidOperationException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupDeploymentCmdlet

azuredeploy_webapp.parameter.json:

    {
      "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "appName": {
          "value": "ITQIG-eu-web-manju123"
        },
        "kind": {
          "value": "app"
        },
        "location": {
          "value": "west europe"
        },
        "subnetResourceID": {
          "value": "/subscriptions/7e7f55d3-4bfd-a6be-1c59594b8592/resourceGroups/ITQIG-eu-network-dev/providers/Microsoft.Network/virtualNetworks/ITQIG-eu-vnet-dev/subnets/subnet7-AWmanjug"
        },
        "appServicePlanResourceID": {
          "value": "/subscriptions/7e7f55d3-4bfd-a6be-1c59594b8592/resourceGroups/ITQIG-eu-manjug-windows-app/providers/microsoft.web/serverFarms/eu-manjug-windows-plan"
        }
      }
    }

azuredeploy_webapp.json

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "appName": {
      "type": "string",
      "metadata": {
        "description": "The name of the app to create."
      }
    },
    "kind": {
      "type": "string",
      "metadata": {
        "description": "Web app kind. OS type -> Windows / Linux."
      }
    },
    "appServicePlanResourceID": {
      "metadata": {
        "description": "The resource ID of the app service plan."
      },
      "type": "string"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "The location in which all resources should be deployed."
      }
    },
    "subnetResourceID": {
      "type": "string",
      "metadata": {
        "description": "The subnet resource ID created for app service plan which contains this web app."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2019-08-01",
      "name": "[parameters('appName')]",
      "location": "[parameters('location')]",
      "kind": "[parameters('kind')]",
      "properties": {
        "serverFarmId": "[parameters('appServicePlanResourceID')]"
      },
      "resources": [
        {
          "name": "virtualNetwork",
          "type": "networkConfig",
          "apiVersion": "2019-08-01",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('appName'))]"
          ],
          "properties": {
            "subnetResourceId": "[parameters('subnetResourceId')]",
            "swiftSupported": true
          }
        }
      ]
    }
  ]
}

【问题讨论】:

    标签: json azure-web-app-service azure-resource-manager azure-template


    【解决方案1】:

    我删除了旧文件并重新创建了一个具有相同内容的新 JSON 文件。它现在正在工作。我不知道是什么导致旧文件出现问题..

    【讨论】:

    • 也许真的发生了某种奇迹。
    【解决方案2】:

    问题似乎是您使用的 powershell cmdlet 参数而不是您的模板/参数的结果。请尝试以下操作:

    使用TemplateParameterFile 而不是TemplateParameterUri

    使用TemplateFile 代替TemplateUri

    将文件参数用于非基于 uri 的 arm 部署,这应该可以解决您的问题。 https://docs.microsoft.com/en-us/powershell/module/az.resources/new-azresourcegroupdeployment?view=azps-4.5.0

    【讨论】:

      【解决方案3】:

      我认为您的问题是因为您提供了对现有资源的依赖项。删除"serverFarmId": "[parameters('appServicePlanResourceID')]"

      另外一个需要修复的是你在参数文件中的resourceId的硬编码值。

      【讨论】:

      • serverFarmId 是网站的强制属性。这不是依赖
      猜你喜欢
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多