Unable to deploy template using json loaded from arm template
I am getting the following error when I load my template and parameters from a ARM template file generated from the azure portal
The code I'm using to execute the deploy came from an online example, the parameter file and the template file are directly copied from the Azure Portal for a Azure Data Warehouse instance.
It looks like the error is related to the template json versions being of a different date/Version. Is there a way to force python to use a newer client, I thought it would have default to the latest version.
Any help would be appreciated
Error and example code below
Error:
_Traceback (most recent call last):
File "main.py", line 20, in <module>
main()
File "main.py", line 11, in main
edw.standup()
File "/home/sfibich/projects/exampleEDW/iac/edw.py", line 61, in standup
self.deploy()
File "/home/sfibich/projects/exampleEDW/iac/edw.py", line 53, in deploy
deployment_properties
File "/home/sfibich/projects/exampleEDW/venv/lib/python3.6/site-packages/azure/mgmt/resource/resources/v2018_05_01/operations/deployments_operations.py", line 852, in create_or_update
**operation_config
File "/home/sfibich/projects/exampleEDW/venv/lib/python3.6/site-packages/azure/mgmt/resource/resources/v2018_05_01/operations/deployments_operations.py", line 799, in _create_or_update_initial
raise exp
msrestazure.azure_exceptions.CloudError: Azure Error: InvalidRequestContent
Message: The request content was invalid and could not be deserialized: 'Error converting value "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#" to type 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Data.Definitions.DeploymentParameterDefinition'. Path 'properties.parameters.$schema', line 1, position 1810.'.
Example Code:
self.client.resource_groups.create_or_update(self.resource_group,
{'location':'eastus2'}
)
template_path = os.path.join( os.path.dirname(__file__), 'edw_template.json')
with open(template_path,'r') as template_file_fd:
template = json.load(template_file_fd)
parameter_path = os.path.join(os.path.dirname(__file__),
'edw_parameters.json')
with open(parameter_path,'r') as pf:
parameters = json.load(pf)
print (template['$schema'])
deployment_properties = {
'mode':DeploymentMode.incremental,
'template': template,
'parameters': parameters
}
deployment_async_operation = self.client.deployments.create_or_update(
self.resource_group
,'azure-sample',
deployment_properties
)
deployment_async_operation.wait()
Update: I have validated the Template and Parameter Json are valid by deploying using PowerShell New-AzResourceGroupDeployment
Hi @sfibich I don't see how your parameters are provided, this is a concrete example of the intended content:
parameters = {
'sshKeyData': self.pub_ssh_key,
'vmName': 'azure-deployment-sample-vm',
'dnsLabelPrefix': self.dns_label_prefix
}
parameters = {k: {'value': v} for k, v in parameters.items()}
deployment_properties = {
'mode': DeploymentMode.incremental,
'template': template,
'parameters': parameters
}
Does it help?
Hi Imazuel,
I am reading the parameter file from disk using the code:
with open(parameter_path,'r') as pf:
parameters = json.load(pf)
Between your example and this closed issue, https://github.com/Azure/azure-sdk-for-python/issues/482, which I actually looked at earlier but didn't follow 100% I think I see the problem.
The both the template and the template parameter file I was feeding to the create_update function call was generated by the MS Azure Portal Interface. The Parameter file has a top level object that contains $schema, contentVersion, and Parameters objects, it looks like the deployment properties parameters input does not need or want the top level object so I just provided the "Parameters" object and it works. Overall I'm glad its now working however I would have never been able to glean that from the documentation here https://docs.microsoft.com/en-us/python/api/azure-mgmt-resource/azure.mgmt.resource.resources.v2018_05_01.models.deploymentproperties?view=azure-python
Side question how did you know what the deployment properties parameter object schema can/should be?
Hi @sfibich Will be https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#
See on https://github.com/Azure/azure-quickstart-templates/ for any files called xxxxx.parameters.json as example. In Python you will pass only the parameters dict of that format.
Hi, not sure if I should refer to this open issue. I have been using CLI to trigger inline nested ARM deployment, it was working fine until yesterday May 04, 2019 when I started to get following error
Message: The request content was invalid and could not be deserialized: 'Required property 'type' not found in JSON. Path 'properties.template.parameters.resourceGroup', line 1, position 304.'.
Was there possible any change on Azure side which might cause this issue?
Thanks
below is the ARM I am using template: { "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", "contentVersion": "1.0.0.1", "parameters": { "resourceGroup": { "type": "object", "metadata": { "description": "object containing the name alias and location of resource group" } } }, "variables": { "resourceGroup": { "name": "[parameters('resourceGroup').name]", "location": "[parameters('resourceGroup').location]" } }, "resources": [ { "name": "[variables('resourceGroup').name]", "type": "Microsoft.Resources/resourceGroups", "apiVersion": "2018-05-01", "location": "[variables('resourceGroup').location]" } ] }
parameters: { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#", "contentVersion": "1.0.0.0", "parameters": { "resourceGroup": { "value": { "name": "chartestCACentral", "location": "Canada Central" } } } }
CLI Command: az deployment create --location CanadaCentral --subscription {mySub} --parameters rg.params.json --template-file rg.json --debug
Error: cli.azure.cli.core.util : Azure Error: InvalidRequestContent Message: The request content was invalid and could not be deserialized: 'Required property 'type' not found in JSON. Path 'properties.template.parameters.resourceGroup', line 1, position 285.'. Azure Error: InvalidRequestContent Message: The request content was invalid and could not be deserialized: 'Required property 'type' not found in JSON. Path 'properties.template.parameters.resourceGroup', line 1, position 285.'.
Was this issue resolved. hitting same issue with c#
To clarify the workaround: The parameters file from the portal looks something like this:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"value": "ImagingFunctionsd49b41"
},
"location": {
"value": "eastus"
}
}
}
To work-around the problem, remove the header elements to make the parameters file look like this:
{
"name": {
"value": "ImagingFunctionsd49b41"
},
"location": {
"value": "eastus"
}
}
Hi @sfibich , we are cleaning up issues. Want to know whether you have got enough solution for this issue? We will close this issue if didn't hear you in one month.