[英]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.