错误:根据验证程序,模板部署“模板”无效

问题描述 投票:0回答:1

在 github 中运行工作流程文件来部署函数应用程序时,我收到以下错误,该错误因错误而失败。

模板文件:

{
  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "subscriptionId": {
      "type": "string"
    },
    "resourceGroup": {
      "type": "string"
    },
    "rgTags": {
      "type": "object"
    },
    "funcAppName": {
      "type": "string"
    },
    "location": {
      "type": "string"
    },
    "hostingPlanName": {
      "type": "string"
    },
    "funcAppSku": {
      "type": "string"
    },
    "funcAppSkuCode": {
      "type": "string"
    },
    "appInsightsName": {
      "type": "string"
    },
    "storageAccountName": {
      "type": "string"
    },
    "vnetName": {
      "type": "string"
    },
    "laWorkspaceName": {
      "type": "string"
    },
    "laWorkspaceRGName": {
      "type": "string"
    },
    "tagEnvironment": {
      "type": "string"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/tags",
      "name": "default",
      "apiVersion": "2021-04-01",
      "properties": {
        "tags": "[parameters('rgTags')]"
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "name": "[parameters('funcAppName')]",
      "apiVersion": "2018-11-01",
      "kind": "functionapp",
      "location": "[parameters('location')]",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "dependsOn": [
        "[concat('microsoft.insights/components/', parameters('appInsightsName'))]",
        "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
      ],
      "properties": {
        "name": "[parameters('funcAppName')]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "powershell"
            },
            {
              "name": "WEBSITE_LOAD_CERTIFICATES",
              "value": "*"
            },
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName')), '2015-05-01').InstrumentationKey]"
            },
            {
              "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
              "value": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName')), '2015-05-01').ConnectionString]"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
            },
            {
              "name": "FUNCTIONS_WORKER_PROCESS_COUNT",
              "value": "2"
            },
            {
              "name": "PSWorkerInProcConcurrencyUpperBound",
              "value": "2"
            }
          ],
          "use32BitWorkerProcess": false,
          "alwaysOn": true,
          "powerShellVersion": "~7",
          "http20Enabled": true,
          "minTlsVersion": "1.2",
          "ftpsState": "FtpsOnly"
        },
        "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('resourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "clientAffinityEnabled": false
      },
      "resources": [
        {
          "apiVersion": "2018-11-01",
          "name": "virtualNetwork",
          "type": "config",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('funcAppName'))]",
            "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
          ],
          "properties": {
            "subnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), 'default')]",
            "swiftSupported": true
          }
        }
      ]
    },
    {
      "apiVersion": "2018-11-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[parameters('location')]",
      "kind": "",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "dependsOn": [],
      "properties": {
        "name": "[parameters('hostingPlanName')]",
        "workerSize": "0",
        "workerSizeId": "0",
        "numberOfWorkers": "1"
      },
      "sku": {
        "Tier": "[parameters('funcAppSku')]",
        "Name": "[parameters('funcAppSkuCode')]"
      }
    },
    {
      "apiVersion": "2020-02-02",
      "name": "[parameters('appInsightsName')]",
      "type": "microsoft.insights/components",
      "location": "[parameters('location')]",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "dependsOn": [],
      "properties": {
        "ApplicationId": "[parameters('funcAppName')]",
        "Request_Source": "IbizaWebAppExtensionCreate",
        "Flow_Type": "Redfield",
        "Application_Type": "web",
        "WorkspaceResourceId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourceGroups/', parameters('laWorkspaceRGName'), '/providers/Microsoft.OperationalInsights/workspaces/', parameters('lAWorkspaceName'))]",
        "IngestionMode": "LogAnalytics",
        "publicNetworkAccessForIngestion": "Enabled",
        "publicNetworkAccessForQuery": "Enabled"
      }
    },
    {
      "apiVersion": "2019-06-01",
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "sku": {
        "name": "Standard_LRS"
      },
      "properties": {
        "supportsHttpsTrafficOnly": true,
        "minimumTlsVersion": "TLS1_2"
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2020-11-01",
      "name": "[parameters('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "10.0.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "default",
            "properties": {
              "addressPrefix": "10.0.0.0/24",
              "serviceEndpoints": [
                {
                  "service": "Microsoft.Storage.Global",
                  "locations": [
                    "*"
                  ]
                }
              ],
              "delegations": [
                {
                  "name": "delegation",
                  "properties": {
                    "serviceName": "Microsoft.Web/serverfarms"
                  }
                }
              ],
              "privateEndpointNetworkPolicies": "Enabled",
              "privateLinkServiceNetworkPolicies": "Enabled"
            }
          }
        ],
        "virtualNetworkPeerings": [],
        "enableDdosProtection": false
      },
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      }
    }
  ]
}

参数文件

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "subscriptionId": {
      "value": ""
    },
    "resourceGroup": {
      "value": ""
    },
    "rgTags": {
      "value": null
    },
    "funcAppName": {
      "value": ""
    },
    "location": {
      "value": ""
    },
    "hostingPlanName": {
      "value": ""
    },
    "funcAppSku": {
      "value": ""
    },
    "funcAppSkuCode": {
      "value": ""
    },
    "appInsightsName": {
      "value": ""
    },
    "storageAccountName": {
      "value": ""
    },
    "vnetName": {
      "value": ""
    },
    "laWorkspaceName": {
      "value": ""
    },
    "laWorkspaceRGName": {
      "value": ""
    },
    "tagEnvironment": {
      "value": ""
    }
  }
}

错误:

##[调试]选择-AzSubscription -订阅 dc86c13b-36f0-4b2f-a42d-1bd68ebdaaf7 ##[调试]New-AzResourceGroupDeployment -ResourceGroupName az-dna-113-rg-businessfuncappxayb

##[debug]-TemplateFile arm-templates/business-subscription-afna/template.json
##[调试]-TemplateParameterFile arm-templates/business-subscription-afna/parameters.json ##[debug]要运行的脚本文件:D:_temp;d8fc60-7cad-4983-8b66-2d762ae62181.ps1 “C:\ Program Files \ PowerShell \ pwsh.exe”-NoLogo -NoProfile -NonInteractive -命令D:_temp;d8fc60-7cad-4983-8b66-2d762ae62181.ps1

新 AzResourceGroupDeployment:D:_temp;d8fc60-7cad-4983-8b66-2d762ae62181.ps1:3 线路| 3 | New-AzResourceGroupDeployment -ResourceGroupName az-dna-113-rg-busine … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~ |上午 11:44:45 - 错误:代码=InvalidTemplateDeployment;消息=模板部署“模板”无效 |根据验证程序。跟踪 ID 为“xxxxxxxx-f32f-459c-9487-xxxxxxxx”。有关详细信息,请参阅内部错误。 错误:错误:进程“C:\Program Files\PowerShell \pwsh.exe”失败,退出代码为 1

azure powershell github azure-resource-manager
1个回答
0
投票

您的代码看起来很好,可以满足您的要求。验证以下几点以避免冲突。

New-AzResourceGroupDeployment
PowerShell 命令可能出现错误。尝试使用
az deployment group create
通过以下方式使用 CLI 命令可实现高效的 ARM 部署。

az deployment group create --resource-group xxx --template-file github.json

正如@jdweng建议的那样,尝试使用在线或任何地方提供的

ARM工具包
来验证Json模板。

重新检查代码内部的资源依赖和参数配置,以避免此类问题。

有时,在新环境中重新部署模板将使代码按预期工作。

也就是说,我在我的环境中尝试了类似的代码,并且能够成功部署它,如图所示。

{
  "$schema": "https://schema.management.azure.com/schemas/2018-05-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "subscriptionId": {
      "type": "string",
      "defaultValue":"xxx"
    },
    "resourceGroup": {
      "type": "string",
      "defaultValue": "xxx"
    },
    "sku": {
      "type": "string",
      "defaultValue": "PerGB2018",
      "allowedValues": [
        "CapacityReservation",
        "Free",
        "LACluster",
        "PerGB2018",
        "PerNode",
        "Premium",
        "Standalone",
        "Standard"
      ],
      "metadata": {
        "description": "Specify the pricing tier."
      }
    },
    "rgTags": {
      "type": "object",
      "defaultValue": {
        "createdby": "jahnavi",
        "Environment": "Production"
      }
    },
    "funcAppName": {
      "type": "string",
      "defaultValue": "newapjm"
    },
    "location": {
      "type": "string",
      "defaultValue": "eastus"
    },
    "hostingPlanName": {
      "type": "string",
      "defaultValue": "myplanja"
    },
    "funcAppSku": {
      "type": "string",
      "defaultValue": "Standard"
    },
    "funcAppSkuCode": {
      "type": "string",
      "defaultValue":"S1"
    },
    "appInsightsName": {
      "type": "string",
      "defaultValue": "myinsigjah"
    },
    "storageAccountName": {
      "type": "string",
      "defaultValue": "newjstr"
    },
    "vnetName": {
      "type": "string",
      "defaultValue": "latestvnj"
    },
    "laWorkspaceName": {
      "type": "string",
      "defaultValue": "kurklay"
    },
    "laWorkspaceRGName": {
      "type": "string",
      "defaultValue": "v-jahnavi-Mindtree"
    },
    "tagEnvironment": {
      "type": "string",
      "defaultValue": "production"
    }
  },
  "resources": [
    {
      "type": "Microsoft.Resources/tags",
      "name": "default",
      "apiVersion": "2021-04-01",
      "properties": {
        "tags": "[parameters('rgTags')]"
      }
    },
    {
      "type": "Microsoft.OperationalInsights/workspaces",
      "apiVersion": "2021-12-01-preview",
      "name": "[parameters('laWorkspaceName')]",
      "location": "[parameters('location')]",
      "properties": {
        "sku": {
          "name": "[parameters('sku')]"
        }
      }
    },
    {
      "type": "Microsoft.Web/sites",
      "name": "[parameters('funcAppName')]",
      "apiVersion": "2018-11-01",
      "kind": "functionapp",
      "location": "[parameters('location')]",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "dependsOn": [
        "[concat('microsoft.insights/components/', parameters('appInsightsName'))]",
        "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]",
        "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
      ],
      "properties": {
        "name": "[parameters('funcAppName')]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~4"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "powershell"
            },
            {
              "name": "WEBSITE_LOAD_CERTIFICATES",
              "value": "*"
            },
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName')), '2015-05-01').InstrumentationKey]"
            },
            {
              "name": "APPLICATIONINSIGHTS_CONNECTION_STRING",
              "value": "[reference(concat('microsoft.insights/components/', parameters('appInsightsName')), '2015-05-01').ConnectionString]"
            },
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',parameters('storageAccountName'),';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
            },
            {
              "name": "FUNCTIONS_WORKER_PROCESS_COUNT",
              "value": "2"
            },
            {
              "name": "PSWorkerInProcConcurrencyUpperBound",
              "value": "2"
            }
          ],
          "use32BitWorkerProcess": false,
          "alwaysOn": true,
          "powerShellVersion": "~7",
          "http20Enabled": true,
          "minTlsVersion": "1.2",
          "ftpsState": "FtpsOnly"
        },
        "serverFarmId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('resourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]",
        "clientAffinityEnabled": false
      },
      "resources": [
        {
          "apiVersion": "2018-11-01",
          "name": "virtualNetwork",
          "type": "config",
          "location": "[parameters('location')]",
          "dependsOn": [
            "[resourceId('Microsoft.Web/sites', parameters('funcAppName'))]",
            "[concat('Microsoft.Network/virtualNetworks/', parameters('vnetName'))]"
          ],
          "properties": {
            "subnetResourceId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('vnetName'), 'default')]",
            "swiftSupported": true
          }
        }
      ]
    },
    {
      "apiVersion": "2018-11-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[parameters('location')]",
      "kind": "",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "dependsOn": [],
      "properties": {
        "name": "[parameters('hostingPlanName')]",
        "workerSize": "0",
        "workerSizeId": "0",
        "numberOfWorkers": "1"
      },
      "sku": {
        "Tier": "[parameters('funcAppSku')]",
        "Name": "[parameters('funcAppSkuCode')]"
      }
    },
    {
      "apiVersion": "2020-02-02",
      "name": "[parameters('appInsightsName')]",
      "type": "microsoft.insights/components",
      "location": "[parameters('location')]",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "dependsOn": [],
      "properties": {
        "ApplicationId": "[parameters('funcAppName')]",
        "Request_Source": "IbizaWebAppExtensionCreate",
        "Flow_Type": "Redfield",
        "Application_Type": "web",
        "WorkspaceResourceId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourceGroups/', parameters('laWorkspaceRGName'), '/providers/Microsoft.OperationalInsights/workspaces/', parameters('lAWorkspaceName'))]",
        "IngestionMode": "LogAnalytics",
        "publicNetworkAccessForIngestion": "Enabled",
        "publicNetworkAccessForQuery": "Enabled"
      }
    },
    {
      "apiVersion": "2019-06-01",
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      },
      "sku": {
        "name": "Standard_LRS"
      },
      "properties": {
        "supportsHttpsTrafficOnly": true,
        "minimumTlsVersion": "TLS1_2"
      }
    },
    {
      "type": "Microsoft.Network/virtualNetworks",
      "apiVersion": "2020-11-01",
      "name": "[parameters('vnetName')]",
      "location": "[parameters('location')]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "10.0.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "default",
            "properties": {
              "addressPrefix": "10.0.0.0/24",
              "serviceEndpoints": [
                {
                  "service": "Microsoft.Storage.Global",
                  "locations": [
                    "*"
                  ]
                }
              ],
              "delegations": [
                {
                  "name": "delegation",
                  "properties": {
                    "serviceName": "Microsoft.Web/serverfarms"
                  }
                }
              ],
              "privateEndpointNetworkPolicies": "Enabled",
              "privateLinkServiceNetworkPolicies": "Enabled"
            }
          }
        ],
        "virtualNetworkPeerings": [],
        "enableDdosProtection": false
      },
      "tags": {
        "Environment": "[parameters('tagEnvironment')]"
      }
    }
  ]
}

部署成功:

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.