【发布时间】:2022-09-30 05:04:06
【问题描述】:
我正在尝试使用 ARM 模板部署密钥库。我作为基础使用的模板位于azuredeploy.json,如果我不提供参数,部署成功,但是只要我添加一个参数文件,如下面的。
参数文件:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters":
{
"vaultName":
{
"value": <key vault name>
}
}
}
(无效模板)部署模板验证失败:'模板参数'$schema,contentVersion,参数'在 参数文件无效;它们在原版中不存在 模板,因此无法在部署时提供。这 此模板仅支持的参数是 'vaultName, location, enabledForDeployment、enabledForDiskEncryption、 enabledForTemplateDeployment、enablePurgeProtection、 enableRbacAuthorization,enableSoftDelete,softDeleteRetentionInDays, 租户 ID、networkRuleBypassOptions、NetworkRuleAction、ipRules、 accessPolicies、virtualNetworkRules、skuName、标签'。请参见 https://aka.ms/arm-deploy/#parameter-file 了解使用详情。'。
#代码:无效模板
#信息:部署模板验证失败:参数中的'模板参数'$schema,contentVersion,参数' 文件无效;它们不在原始模板中,并且 因此无法在部署时提供。唯一支持的 此模板的参数是 'vaultName, location, enabledForDeployment、enabledForDiskEncryption、 enabledForTemplateDeployment、enablePurgeProtection、 enableRbacAuthorization,enableSoftDelete,softDeleteRetentionInDays, 租户 ID、networkRuleBypassOptions、NetworkRuleAction、ipRules、 accessPolicies、virtualNetworkRules、skuName、标签'。请参见 https://aka.ms/arm-deploy/#parameter-file 了解使用详情。'。
附加信息:类型:模板违规
信息:{ “行号”:0, “线位置”:0, “小路”: ”” }根据错误消息,问题出在参数文件中,但我无法确定问题所在。你知道错误可能在哪里吗?
**Python代码:
import os from azure.identity import DefaultAzureCredential from azure.mgmt.resource import ResourceManagementClient from azure.mgmt.resource.resources.models import DeploymentMode from azure.mgmt.resource.resources.models import Deployment from azure.mgmt.resource.resources.models import DeploymentProperties from miscellaneous.logger import Logger from msrestazure.azure_cloud import get_cloud_from_metadata_endpoint from uuid6 import uuid7 class AzureConnection(object): def __init__(self, subscriptionId, resourceGroup): self.logger = Logger("Azure Connection") self.logger.info("Retrieving the list of available endpoint") endpoints = get_cloud_from_metadata_endpoint(os.environ.get("ARM_ENDPOINT")) self.subscriptionId = subscriptionId self.resourceGroup = resourceGroup self.credentials = DefaultAzureCredential() self.logger.info("Creating a client for deploying resources on subscription {}".format(self.subscriptionId)) self.client = ResourceManagementClient(self.credentials, self.subscriptionId, base_url=endpoints.endpoints.resource_manager) self.logger.success("Client was successfully created") def deploy(self, template): resources = "" for resource in template.get("resources"): resources += "\n\t {}".format(resource.get("type")) self.logger.info("The following resources: {}\nwill be deployed".format(resources)) deploymentProperties = DeploymentProperties( mode=DeploymentMode.incremental, template=template ) self.logger.info("Attempting deploy operation") try: deployment_async_operation = self.client.deployments.begin_create_or_update( self.resourceGroup, uuid7(), Deployment(properties=deploymentProperties) ) except: self.logger.error("The resources could not be deployed"); self.logger.success("Resources were successfully deployed") def deployWithParameters(self, template, parameters): resources = "" for resource in template.get("resources"): resources += "\n\t {}".format(resource.get("type")) self.logger.info("The following resources: {}\nwill be deployed".format(resources)) parameters = {k: {"value": v} for k, v in parameters.items()} deploymentProperties = DeploymentProperties( mode=DeploymentMode.incremental, template=template, parameters=parameters ) self.logger.info("Attempting deploy operation") deployment_async_operation = self.client.deployments.begin_create_or_update( self.resourceGroup, uuid7(), Deployment(properties=deploymentProperties) ) from dotenv import load_dotenv load_dotenv() azureConnection = AzureConnection(os.environ.get("AZURE_SUBSCRIPTION_ID"), os.environ.get("AZURE_RESOURCE_GROUP")) with open((os.path.dirname(__file__), "templates", <fileName>), "r") as file: template = json.load(file) with open((os.path.dirname(__file__), "parameters", <fileName>), "r") as file: json = json.load(file) deployment = azureConnection.deployWithParameters(template, parameter)
【问题讨论】:
标签: python azure azure-resource-manager arm-template