简体   繁体   English

Azure SDK ARM 模板部署:找不到成员“id”

[英]Azure SDK ARM Template deployment: Could not find member 'id'

I'm trying to deploy a vm through the python azure sdk with an arm template.我正在尝试使用 arm 模板通过 python azure sdk 部署虚拟机。 I'm using the code provided by microsoft from here: https://learn.microsoft.com/en-us/samples/azure-samples/resource-manager-python-template-deployment/resource-manager-python-template-deployment/我正在使用微软从这里提供的代码: https://learn.microsoft.com/en-us/samples/azure-samples/resource-manager-python-template-deployment/resource-manager-python-template-部署/

But I get an error when trying to use the template.但是在尝试使用模板时出现错误。

parameters = my parameters as a python dict
       
parameters = {k: {'value': v} for k, v in parameters.items()}
template = self.ts_client.template_specs.get('test-rg', 'deploy-vm.test').as_dict()

deployment_properties = {'mode': DeploymentMode.incremental,
                       'template': template,
                       'parameters': parameters}
    
self.client.deployments.create_or_update(self.resource_group,'azure-sample', {'properties': deployment_properties, 'tags': []})

The only part thats different from the example code, is that I'm not reading the template from a file but I'm getting it through the sdk and converting it into a dictonary and I pass the deployment_properties into the begin_create_or_update method as a dict.与示例代码唯一不同的部分是,我不是从文件中读取模板,而是通过 sdk 获取模板并将其转换为字典,然后将 deployment_properties 作为字典传递给 begin_create_or_update 方法。 If I don't pass it like this it gives the exception: Parameter 'Deployment.properties' can not be None.如果我不这样传递它,它会给出异常:参数“Deployment.properties”不能为无。

However I get this error:但是我收到此错误:

azure.core.exceptions.HttpResponseError: (InvalidRequestContent) The request content was invalid and could not be deserialized: 'Could not find member 'id' on object of type 'Template'. Path 'properties.template.id', line 1, position 34.'.

Any idea what this could be?知道这可能是什么吗?

I tried in my environment and got same type of error.我在我的环境中尝试并得到了相同类型的错误。

Console:安慰:在此处输入图像描述

Make sure you are passing correct Arm template template.json and also check it is in correct state. Provide the valid id or correct the templates according to Azure-VM templates using this MS-Docs .确保您传递的是正确的 Arm 模板template.json并检查它是否正确 state。根据Azure-VM模板使用此MS-Docs提供有效 ID 或更正模板。

After I validated my templates using document the virtual machine is deployed successfully using python with Arm templates.在我使用文档验证我的模板后,使用 python 和 Arm 模板成功部署了虚拟机。

Code:代码:

from  azure.mgmt.resource  import  ResourceManagementClient
from  azure.mgmt.resource.resources.models  import  DeploymentMode
from  azure.identity  import  DefaultAzureCredential
import  json


subscription_id = '<subscription id>'
resource_group = '<your rg name >'
creds = DefaultAzureCredential()
client = ResourceManagementClient( creds, '<sub id>')

parameters = {
'virtualMachineName': '',
'location': '',
'virtualMachineRG':''
}

parameters = {k: {'value': v} for  k, v  in  parameters.items()}
with  open(r'<path of file >', 'r') as  template_file_fd:
template = json.load(template_file_fd)
deployment_properties = {
'mode': DeploymentMode.incremental,
'template': template,
'parameters': parameters
}
deployment_async_operation = client.deployments.begin_create_or_update(
resource_group, 'azure-sample', {'properties': deployment_properties, 'tags': []})
deployment_async_operation.wait()

Console:安慰:

在此处输入图像描述

Portal:门户网站:

在此处输入图像描述

Reference: Microsoft.Compute/virtualMachines - Bicep, ARM template & Terraform AzAPI reference |参考: Microsoft.Compute/virtualMachines - Bicep,ARM 模板和 Terraform AzAPI 参考 | Microsoft Learn 微软学习

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure ARM 模板部署使用 Python - Azure ARM template deployment using Python Python Azure ARM 模板部署失败 - Python Azure ARM Template Deployment failed 如何使用 azure python ZEAE18BC41E1434DD98FA2DD989531DA8 将参数传递给 ARM 模板 - How to pass parameters to ARM template using azure python sdk? 部署 ARM 模板时出错。 找不到与模板文件模式匹配的任何文件 - Error in Deploying ARM template. Could not find any file matching the template file pattern Python Azure Function App 部署失败:错误:找不到 .NET Core 项目文件 - Deployment of Python Azure Function App fails: Error: Could not find the .NET Core project file 使用 Python SDK 部署 ARM 模板的权限不足 - Insufficient permissions for deploying ARM template using Python SDK 如何使用 ZF926B3E222D7AFEE57071B2256Z3 模板部署 python azure function 模板? - How do you deploy a python azure function with an arm template? 哪里可以找到Box python SDK的jwt_key_id - Where to find jwt_key_id for box python SDK 错误:找不到满足要求的版本 azure-functions - ERROR: Could not find a version that satisfies the requirement azure-functions 使用 Python SDK azure-ai-ml v2 找不到 Azure Mlflow Run id - Azure Mlflow Run id not found using Python SDK azure-ai-ml v2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM