westandy
westandy

Reputation: 1440

Azure created ARM is not valid in Azure

I create a resource an Azure CosmosDB resource in a Sandbox resource group. That works great!

I then go to "Automation Script".

1) First Problem, these errors are output:

Export template operation completed with errors. Some resources were not exported. Please see details for more information. (Code: ExportTemplateCompletedWithErrors)

Could not get resources of the type 'Microsoft.Storage/storageAccounts/managementPolicies'. Resources of this type will not be exported. (Code: ExportTemplateProviderError, Target: Microsoft.Storage/storageAccounts/managementPolicies)
Could not get resources of the type 'Microsoft.Storage/storageAccounts/blobServices'. Resources of this type will not be exported. (Code: ExportTemplateProviderError, Target: Microsoft.Storage/storageAccounts/blobServices)
Could not get resources of the type 'Microsoft.Web/sites/premieraddons'. Resources of this type will not be exported. (Code: ExportTemplateProviderError, Target: Microsoft.Web/sites/premieraddons)
Could not get resources of the type 'Microsoft.Web/sites/sourcecontrols'. Resources of this type will not be exported. (Code: ExportTemplateProviderError, Target: Microsoft.Web/sites/sourcecontrols) 

2) I then download the JSON to a local file and save it, "./myTemplate.json". I go to "Templates" on the Azure portal, and add the JSON in myTemplate.json.

3) Second problem, I cannot validate the template.

In the Templates section, I select my Template, and can view the JSON (that was provided by Azure), and then select Deploy. (Shouldn't there be a Validate in addition to Deploy?)

Deploy takes me to a "Custom Deployment" view in the Azure portal. I follow the steps, and select Purchase which is when the template gets validated.

Deployment template validation failed: 
'The template resource '[variables('databaseAccounts_gsdev_name')]' at 
line '62' 
and column '9' is not valid: Evaluation result of language expression 
'[variables('databaseAccounts_gsdev_name')]' is type 'Object', expected 
 type is 'String'.. Please see https://aka.ms/arm-template-expressions 
 for usage details.'. (Code: InvalidTemplate)

I also reported this problem on the Azure DevOps website: https://developercommunity.visualstudio.com/content/problem/408898/azure-created-arm-is-not-valid-in-azure.html

Why is Azure unable to create a valid template from a resource that it is currently supporting?

Upvotes: 3

Views: 2617

Answers (3)

mkstr
mkstr

Reputation: 153

This doesn't resolve the issue but helps creating valid and more readable templates faster.

Take templates for desired services from here and then just copy the values and fill extra settings that are not included in the template. I would not recommend to use the automation script functionality as base for template anyway since it has tons of unnecessary lines which makes the ARM-template more difficult to read and understand.

Upvotes: 1

bmoore-msft
bmoore-msft

Reputation: 8727

1) happens when the template schemas for the resource are missing - we're working on filing the gaps here so this should be less common once that happens.

3) looks like a bug in the export or the schema (probably the latter). if I'm guessing right that var is used for the name of a db? The name property is defined as a string (JSON type) and the variable was exported as an object? If you can the template, it should help troubleshoot.

Upvotes: 0

Stringfellow
Stringfellow

Reputation: 2908

1) I see the error all the time. Using Automation script to export ARM templates becomes nearly useless for more complicated configuration, especially with resource extensions. I've seen the same problems reported (e.g. https://github.com/Azure/azure-resource-manager-schemas/issues/148).

3) Use double-quotes on the outermost string. The error message has:

'[variables('databaseAccounts_gsdev_name')]'

Try changing that to:

"[variables('databaseAccounts_gsdev_name')]"

Upvotes: 0

Related Questions