I'm trying to develop a feature in my app that creates an Availability Test and I'm running a lab that using Python SDK I'm able to create a resource group, AKS cluster, log analytics workspace and application insights. After it does all that, this comes in, trying to create an Availability Test.
availability_test = {
"$schema": "ttps://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2019-04-01",
"name": app_insights_name,
"type": "microsoft.insights/webtests",
"location": "eastus2",
"properties": {
"SyntheticMonitorId": None,
"Enabled": True,
"Locations": [
{
"Id": "us-ca-sjc-azr"
}
],
"Configuration": {
"WebTest": {
"Timeout": "60",
"ParseDependentRequests": False,
"FollowRedirects": True
}
}
}
}
]
}
deployment_url = f"https://management.azure.com/subscriptions/{subscription_id}/resourcegroups/{resource_group_name}/providers/microsoft.resources/deployments/{app_insights_name}?api-version=2023-07-01"
headers = {
"Authorization": f"Bearer {credentials.get_token('https://management.azure.com/.default').token}",
"Content-Type": "application/json"
}
response = requests.put(deployment_url, data=json.dumps(availability_test), headers=headers)
if response.status_code == 201:
print("Availability test deployed successfully!")
else:
print(f"Failed to deploy availability test. Status code: {response.status_code}")
print(response.text)
The error that persists is this one:
Failed to deploy availability test. Status code: 400
{"error":{"code":"InvalidRequestContent","message":"The request content was invalid and could not be deserialized: 'Could not find member '$schema' on object of type 'DeploymentContent'. Path '$schema', line 1, position 11.'."}}
Any ideas? Or maybe another method of doing this?
The Azure API is not recognizing the
$schemafield within the deployment content. In this context, the$schemafield is not expected, and the ARM deployment should only contain the resource definitions.It's better to keep your ARM templates in separate files, as this makes your code cleaner and easier to manage.
Deploy ARM Template with py script: