【问题标题】:Getting ARM template deploy error "Could not find member 'securityType' ...."获取 ARM 模板部署错误 \"找不到成员 \'securityType\' ....\"
【发布时间】:2022-10-31 10:06:09
【问题描述】:

我有一个 ARM 模板,可以很好地创建虚拟机(Windows Server 2022)。

我为 Trusted Launch 添加了一些变量:

"variables": {

    "securityType": "TrustedLaunch",
    "secureBoot": true,
    "vTPMEnabled": true
},

在虚拟机 (Microsoft.Compute/virtualMachines) 资源数组中,我添加了以下内容:

   "securityProfile": {
       "securityType": "[variables('securityType')]",
       "uefiSettings": {
           "secureBootEnabled": "[variables('secureBoot')]",
           "vTpmEnabled": "[variables('vTPMEnabled')]"
       }
   }

当我部署模板并单击创建时,它会给出以下错误:

{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.","details":[{"code":"BadRequest","message":"Could not find member 'securityType' on object of type 'SecurityProfile'. Path 'properties.securityProfile.securityType', line 1, position 1186."}]}

我可以去虚拟机并创建一个安全类型设置为“受信任的启动虚拟机”的虚拟机,它创建得很好。当我在单击创建之前下载模板并查看 JSON 时,它几乎是相同的(它使用参数而不是变量,但我尝试使用变量并对 SecureProfiles 进行硬编码,但我得到了同样的错误)。这是下载的模板 JSON 中的 SecureProfiles 以供参考:

   securityProfile": {
      securityType": "[parameters('securityType')]",
      uefiSettings": {
          secureBootEnabled": "[parameters('secureBoot')]",
          vTpmEnabled": "[parameters('vTPM')]"
      }
   }

寻求有关错误“找不到成员'securityType'...”的帮助,我得到了。

【问题讨论】:

  • 如果没有整个 ARM 模板,就无法识别您的问题。提示错误的原因之一是使用了不正确的 api 版本。供您参考,我正在添加 Trusted Launch VM 的工作模板。

标签: security azure-resource-manager arm-template


【解决方案1】:

可信启动 VM ARM 模板参考

天蓝色部署.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "adminUsername": {
        "type": "string",
        "metadata": {
          "description": "Username for the Virtual Machine."
        }
      },
      "adminPassword": {
        "type": "secureString",
        "minLength": 12,
        "metadata": {
          "description": "Password for the Virtual Machine."
        }
      },
      "dnsLabelPrefix": {
        "type": "string",
        "defaultValue": "[toLower(format('{0}-{1}', parameters('vmName'), uniqueString(resourceGroup().id, parameters('vmName'))))]",
        "metadata": {
          "description": "Unique DNS Name for the Public IP used to access the Virtual Machine."
        }
      },
      "publicIpName": {
        "type": "string",
        "defaultValue": "myPublicIP",
        "metadata": {
          "description": "Name for the Public IP used to access the Virtual Machine."
        }
      },
      "publicIPAllocationMethod": {
        "type": "string",
        "defaultValue": "Dynamic",
        "allowedValues": [
          "Dynamic",
          "Static"
        ],
        "metadata": {
          "description": "Allocation method for the Public IP used to access the Virtual Machine."
        }
      },
      "publicIpSku": {
        "type": "string",
        "defaultValue": "Basic",
        "allowedValues": [
          "Basic",
          "Standard"
        ],
        "metadata": {
          "description": "SKU for the Public IP used to access the Virtual Machine."
        }
      },
      "OSVersion": {
        "type": "string",
        "defaultValue": "2022-datacenter-azure-edition-core",
        "allowedValues": [
          "2008-R2-SP1",
          "2008-R2-SP1-smalldisk",
          "2012-Datacenter",
          "2012-datacenter-gensecond",
          "2012-Datacenter-smalldisk",
          "2012-datacenter-smalldisk-g2",
          "2012-Datacenter-zhcn",
          "2012-datacenter-zhcn-g2",
          "2012-R2-Datacenter",
          "2012-r2-datacenter-gensecond",
          "2012-R2-Datacenter-smalldisk",
          "2012-r2-datacenter-smalldisk-g2",
          "2012-R2-Datacenter-zhcn",
          "2012-r2-datacenter-zhcn-g2",
          "2016-Datacenter",
          "2016-datacenter-gensecond",
          "2016-datacenter-gs",
          "2016-Datacenter-Server-Core",
          "2016-datacenter-server-core-g2",
          "2016-Datacenter-Server-Core-smalldisk",
          "2016-datacenter-server-core-smalldisk-g2",
          "2016-Datacenter-smalldisk",
          "2016-datacenter-smalldisk-g2",
          "2016-Datacenter-with-Containers",
          "2016-datacenter-with-containers-g2",
          "2016-datacenter-with-containers-gs",
          "2016-Datacenter-zhcn",
          "2016-datacenter-zhcn-g2",
          "2019-Datacenter",
          "2019-Datacenter-Core",
          "2019-datacenter-core-g2",
          "2019-Datacenter-Core-smalldisk",
          "2019-datacenter-core-smalldisk-g2",
          "2019-Datacenter-Core-with-Containers",
          "2019-datacenter-core-with-containers-g2",
          "2019-Datacenter-Core-with-Containers-smalldisk",
          "2019-datacenter-core-with-containers-smalldisk-g2",
          "2019-datacenter-gensecond",
          "2019-datacenter-gs",
          "2019-Datacenter-smalldisk",
          "2019-datacenter-smalldisk-g2",
          "2019-Datacenter-with-Containers",
          "2019-datacenter-with-containers-g2",
          "2019-datacenter-with-containers-gs",
          "2019-Datacenter-with-Containers-smalldisk",
          "2019-datacenter-with-containers-smalldisk-g2",
          "2019-Datacenter-zhcn",
          "2019-datacenter-zhcn-g2",
          "2022-datacenter",
          "2022-datacenter-azure-edition",
          "2022-datacenter-azure-edition-core",
          "2022-datacenter-azure-edition-core-smalldisk",
          "2022-datacenter-azure-edition-smalldisk",
          "2022-datacenter-core",
          "2022-datacenter-core-g2",
          "2022-datacenter-core-smalldisk",
          "2022-datacenter-core-smalldisk-g2",
          "2022-datacenter-g2",
          "2022-datacenter-smalldisk",
          "2022-datacenter-smalldisk-g2"
        ],
        "metadata": {
          "description": "The Windows version for the VM. This will pick a fully patched image of this given Windows version."
        }
      },
      "vmSize": {
        "type": "string",
        "defaultValue": "Standard_D2s_v5",
        "metadata": {
          "description": "Size of the virtual machine."
        }
      },
      "location": {
        "type": "string",
        "defaultValue": "[resourceGroup().location]",
        "metadata": {
          "description": "Location for all resources."
        }
      },
      "vmName": {
        "type": "string",
        "defaultValue": "simple-vm",
        "metadata": {
          "description": "Name of the virtual machine."
        }
      },
      "securityType": {
        "type": "string",
        "metadata": {
          "description": "Security Type of virtualmachine"
        }
      },
      "secureBootEnabled": {
        "type": "string",
        "metadata": {
          "description": "secureBootEnabled of the virtual machine"
        }
      },
      "vTpmEnabled": {
        "type": "string",
        "metadata": {
          "description": "vTpmEnabled of the virtual machine"
        }
      }
    },
    "variables": {
      "storageAccountName": "[format('bootdiags{0}', uniqueString(resourceGroup().id))]",
      "nicName": "myVMNic",
      "addressPrefix": "10.0.0.0/16",
      "subnetName": "Subnet",
      "subnetPrefix": "10.0.0.0/24",
      "virtualNetworkName": "MyVNET",
      "networkSecurityGroupName": "default-NSG"
    },
    "resources": [
      {
        "type": "Microsoft.Storage/storageAccounts",
        "apiVersion": "2021-04-01",
        "name": "[variables('storageAccountName')]",
        "location": "[parameters('location')]",
        "sku": {
          "name": "Standard_LRS"
        },
        "kind": "Storage"
      },
      {
        "type": "Microsoft.Network/publicIPAddresses",
        "apiVersion": "2021-02-01",
        "name": "[parameters('publicIpName')]",
        "location": "[parameters('location')]",
        "sku": {
          "name": "[parameters('publicIpSku')]"
        },
        "properties": {
          "publicIPAllocationMethod": "[parameters('publicIPAllocationMethod')]",
          "dnsSettings": {
            "domainNameLabel": "[parameters('dnsLabelPrefix')]"
          }
        }
      },
      {
        "type": "Microsoft.Network/networkSecurityGroups",
        "apiVersion": "2021-02-01",
        "name": "[variables('networkSecurityGroupName')]",
        "location": "[parameters('location')]",
        "properties": {
          "securityRules": [
            {
              "name": "default-allow-3389",
              "properties": {
                "priority": 1000,
                "access": "Allow",
                "direction": "Inbound",
                "destinationPortRange": "3389",
                "protocol": "Tcp",
                "sourcePortRange": "*",
                "sourceAddressPrefix": "*",
                "destinationAddressPrefix": "*"
              }
            }
          ]
        }
      },
      {
        "type": "Microsoft.Network/virtualNetworks",
        "apiVersion": "2021-02-01",
        "name": "[variables('virtualNetworkName')]",
        "location": "[parameters('location')]",
        "properties": {
          "addressSpace": {
            "addressPrefixes": [
              "[variables('addressPrefix')]"
            ]
          },
          "subnets": [
            {
              "name": "[variables('subnetName')]",
              "properties": {
                "addressPrefix": "[variables('subnetPrefix')]",
                "networkSecurityGroup": {
                  "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
                }
              }
            }
          ]
        },
        "dependsOn": [
          "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
        ]
      },
      {
        "type": "Microsoft.Network/networkInterfaces",
        "apiVersion": "2021-02-01",
        "name": "[variables('nicName')]",
        "location": "[parameters('location')]",
        "properties": {
          "ipConfigurations": [
            {
              "name": "ipconfig1",
              "properties": {
                "privateIPAllocationMethod": "Dynamic",
                "publicIPAddress": {
                  "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))]"
                },
                "subnet": {
                  "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
                }
              }
            }
          ]
        },
        "dependsOn": [
          "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))]",
          "[resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName'))]"
        ]
      },
      {
        "type": "Microsoft.Compute/virtualMachines",
        "apiVersion": "2021-03-01",
        "name": "[parameters('vmName')]",
        "location": "[parameters('location')]",
        "properties": {
          "hardwareProfile": {
            "vmSize": "[parameters('vmSize')]"
          },
          "osProfile": {
            "computerName": "[parameters('vmName')]",
            "adminUsername": "[parameters('adminUsername')]",
            "adminPassword": "[parameters('adminPassword')]"
          },
          "storageProfile": {
            "imageReference": {
              "publisher": "MicrosoftWindowsServer",
              "offer": "WindowsServer",
              "sku": "[parameters('OSVersion')]",
              "version": "latest"
            },
            "osDisk": {
              "createOption": "FromImage",
              "managedDisk": {
                "storageAccountType": "StandardSSD_LRS"
              }
            },
            "dataDisks": [
              {
                "diskSizeGB": 1023,
                "lun": 0,
                "createOption": "Empty"
              }
            ]
          },
          "networkProfile": {
            "networkInterfaces": [
              {
                "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
              }
            ]
          },
          "diagnosticsProfile": {
            "bootDiagnostics": {
              "enabled": true,
              "storageUri": "[reference(resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))).primaryEndpoints.blob]"
            }
          },
          "securityProfile":{
            "securityType": "[parameters('securityType')]",
            "uefiSettings": {
              "secureBootEnabled": "[parameters('secureBootEnabled')]",
              "vTpmEnabled": "[parameters('vTpmEnabled')]"
            }
          }
        },
        "dependsOn": [
          "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]",
          "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
        ]
      }
    ],
    "outputs": {
      "hostname": {
        "type": "string",
        "value": "[reference(resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpName'))).dnsSettings.fqdn]"
      }
    }
  }

天蓝色部署.parameters.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "adminUsername": {
            "value": "" 
        },
        "adminPassword": {
            "value": "" 
        },
        "dnsLabelPrefix": {
            "value": "" 
        },
        "publicIpName": {
            "value": ""
        },
        "publicIPAllocationMethod": {
            "value": ""
        },
        "publicIpSku": {
            "value": ""
        },
        "OSVersion": {
            "value": "2022-datacenter-azure-edition-core"
        },
        "vmSize": {
            "value": "Standard_D2s_v5"
        },
        "location": {
            "value": "eastus" 
        },
        "vmName": {
            "value": ""
        },
        "securityType": {
            "value": "TrustedLaunch" 
        },
        "secureBootEnabled": {
            "value": "true" 
        },
        "vTpmEnabled": {
            "value": "true" 
        }
    }
}

【讨论】:

    猜你喜欢
    • 2022-11-23
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 2020-12-05
    • 1970-01-01
    • 2022-08-20
    相关资源
    最近更新 更多