在 Azure 中部署计算机时部署模板验证失败

在 Azure 中部署计算机时部署模板验证失败

使用 azure 提供程序执行 vagrant up 时遇到以下问题

"response": {
    "body": "{\"error\":{\"code\":\"InvalidTemplate\",\"message\":\"Deployment template validation failed: 'The value fo
r the template parameter 'adminPassword' at line '1' and column '306' is not provided. Please see https://aka.ms/arm-dep
loy/#parameter-file for usage details.'.\"}}",

模板文件:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vaults_VaultVagrant_name": {
      "defaultValue": "VaultVagrant",
      "type": "String"
    },
    "AdminPassword":{
    "type":"securestring"
    }

  },
  "variables": {},
  "resources": [
    {
      "type": "Microsoft.KeyVault/vaults",
      "name": "[parameters('vaults_VaultVagrant_name')]",
      "apiVersion": "2015-06-01",
      "location": "eastus",
      "tags": {},
      "properties": {
        "sku": {
          "family": "A",
          "name": "standard"
        },
        "tenantId": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
        "accessPolicies": [
          {
            "tenantId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
            "objectId": "1efb1891-8ad4-4f69-9e0d-f5849e6f8c98",
            "permissions": {
              "keys": [
                "get",
                "create",
                "delete",
                "list",
                "update",
                "import",
                "backup",
                "restore"
              ],
              "secrets": [
                "all"
              ]
            }
          }
        ],
        "enabledForDeployment": true
      },
      "resources": [],
      "dependsOn": []
    }

  ]
}

范围

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "AdminPassword": {
            "reference": {
               "keyVault": {
                  "id":"/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxx/resourceGroups/azurevag/providers/Microsoft.KeyVault/vaults/VaultVagrant"
               }, 
               "secretName": "vagrant" 
            }   
        }
   }
}

我正在从本地机器部署这两个文件,如下所示

azure 组部署创建 -f“c:\MyTemplates\example.json”-e“c:\MyTemplates\example.params.json”-g examplegroup -n exampledeployment

问题:成功创建部署后,检查 Azure 门户中的部署脚本,其中两个文件如下所示

模板文件

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vaults_VaultVagrant_name": {
      "defaultValue": "VaultVagrant",
      "type": "String"
    }
  },
  "variables": {},
  "resources": [
    {
      "comments": "Generalized from resource: '/subscriptions/xxxxxxxxxxxxxxxxxxxx/resourceGroups/azurevag/providers/Microsoft.KeyVault/vaults/VaultVagrant'.",
      "type": "Microsoft.KeyVault/vaults",
      "name": "[parameters('vaults_VaultVagrant_name')]",
      "apiVersion": "2015-06-01",
      "location": "eastus",
      "tags": {},
      "properties": {
        "sku": {
          "family": "A",
          "name": "standard"
        },
        "tenantId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
        "accessPolicies": [
          {
            "tenantId": "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",
            "objectId": "1efb1891-8ad4-4f69-9e0d-f5849e6f8c98",
            "permissions": {
              "keys": [
                "get",
                "create",
                "delete",
                "list",
                "update",
                "import",
                "backup",
                "restore"
              ],
              "secrets": [
                "all"
              ]
            }
          }
        ],
        "enabledForDeployment": true
      },
      "resources": [],
      "dependsOn": []
    }
  ]
}

**注意:**部署后缺少参数 adminpassword

参数文件:

参数文件为空。部署后如何丢失值(管理员密码)?

答案1

ARM 模板需要一个名为 AdminPassword 的参数,但未收到。如果不查看模板和参数,很难知道原因,但大多数模板都要求参数为安全字符串,因此请确保以正确的格式提供它。

答案2

根据您的错误,可能是您的模板丢失了参数“adminPassword”或者列“306”中存在语法错误。也许您可以检查一下您的模板。我建议您使用工具检查您的模板。JSON 格式化程序和验证器也许是一个不错的选择。

在此处输入图片描述

相关内容