question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[FEATURE REQ] Support objects in parameters.json file

See original GitHub issue

Please describe the feature or suggestion.

We are using quite a lot of objects in our parameters.json files to nicely combine several parameters, also described here, for example:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "infra": {
      "value": {
        "environment": {
          "resourcePrefix": "dummy",
          "resourceGroupName": "dummy"
        }
      }
    }
  }
}

We can then access that value from our Bicep file like this infra.environment.resourcePrefix.

When running the Template Analyzer tool this does not seem to be supported as I run into these kind of errors: The template variable 'appSettings' is not valid: The language expression property 'environment' doesn't exist, available properties are 'property1'...

It seems like using objects in the parameters file are not supported, or am I doing something wrong? Searched within the documentation and issues but couldn’t really find anything. Would be great if this could be supported!

Additional context

Entire error:

Warning: An exception occurred when processing the template language expressions
Exception details:
Azure.Deployments.Templates.Exceptions.TemplateValidationException: The template variable 'appSettings' is not valid: The language expression property 'environment' doesn't exist, available properties are 'property1'.. Please see https://aka.ms/arm-template-expressions for usage details.
 ---> Azure.Deployments.Core.Exceptions.ExpressionException: The language expression property 'environment' doesn't exist, available properties are 'property1'.
   at Azure.Deployments.Expression.Expressions.FunctionExpression.SelectObjectProperty(JObject root, JToken token, TemplateErrorAdditionalInfo additionalInfo)
   at Azure.Deployments.Expression.Expressions.FunctionExpression.SelectProperty(JToken root, JToken property, TemplateErrorAdditionalInfo additionalInfo)
   at Azure.Deployments.Expression.Expressions.FunctionExpression.EvaluateExpression(ExpressionEvaluationContext context, TemplateErrorAdditionalInfo additionalInfo)
   at Azure.Deployments.Expression.Expressions.FunctionExpression.<>c__DisplayClass23_0.<EvaluateParameters>b__0(LanguageExpression parameter)
   at System.Array.ConvertAll[TInput,TOutput](TInput[] array, Converter`2 converter)
   at Microsoft.WindowsAzure.ResourceStack.Common.Extensions.IEnumerableExtensions.SelectArray[TSource,TElement](TSource[] source, Converter`2 elementSelector)
   at Azure.Deployments.Expression.Expressions.FunctionExpression.EvaluateParameters(ExpressionEvaluationContext context, TemplateErrorAdditionalInfo additionalInfo)
   at Azure.Deployments.Expression.Expressions.FunctionExpression.EvaluateExpression(ExpressionEvaluationContext context, TemplateErrorAdditionalInfo additionalInfo)
   at Azure.Deployments.Expression.Engines.ExpressionsEngine.EvaluateLanguageExpressionsInternal(JToken root, ExpressionEvaluationContext evaluationContext, Boolean ignoreExceptions, TemplateErrorAdditionalInfo additionalInfo, InsensitiveHashSet skipEvaluationPaths)
   at Azure.Deployments.Expression.Engines.ExpressionsEngine.EvaluateLanguageExpressionsRecursive(JToken root, ExpressionEvaluationContext evaluationContext, TemplateErrorAdditionalInfo additionalInfo, InsensitiveHashSet skipEvaluationPaths)
   at Azure.Deployments.Templates.Engines.TemplatePreprocessingEngine.ProcessTemplateVariableLanguageExpressionsRecursive(Template template, String variableName, InsensitiveDictionary`1 recursionState, ExpressionEvaluationContext evaluationContext, TemplateErrorAdditionalInfo additionalInfo)
   --- End of inner exception stack trace ---
   at Azure.Deployments.Templates.Engines.TemplatePreprocessingEngine.ProcessTemplateVariableLanguageExpressionsRecursive(Template template, String variableName, InsensitiveDictionary`1 recursionState, ExpressionEvaluationContext evaluationContext, TemplateErrorAdditionalInfo additionalInfo)
   at Azure.Deployments.Templates.Engines.TemplatePreprocessingEngine.ProcessTemplateVariablesLanguageExpressions(Template template, String apiVersion, InsensitiveDictionary`1 functionEvaluationOverwrites)
   at Azure.Deployments.Templates.Engines.TemplatePreprocessingEngine.ProcessTemplateLanguageExpressions(String managementGroupName, String subscriptionId, String resourceGroupName, Template template, String apiVersion, InsensitiveDictionary`1 functionEvaluationOverwrites)
   at Azure.Deployments.Templates.Engines.TemplateEngine.ProcessTemplateLanguageExpressions(String managementGroupName, String subscriptionId, String resourceGroupName, Template template, String apiVersion, InsensitiveDictionary`1 functionEvaluationOverwrites)
   at Microsoft.Azure.Templates.Analyzer.TemplateProcessor.ArmTemplateProcessor.ParseAndValidateTemplate(InsensitiveDictionary`1 parameters, InsensitiveDictionary`1 metadata) in C:\temp\template-analyzer-0.3.1\src\Analyzer.TemplateProcessor\ArmTemplateProcessor.cs:line 131
Warning: An exception occurred while evaluating the properties of a resource.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pim-simonscommented, Oct 27, 2022

I am indeed using a separate parameters json file. @VeraBE here is an example of a bicep file and a separate parameters json file causing the issue:

@description('Provide the object that contains all info about the common infrastructure.')
param infra object

resource applicationInsight 'microsoft.insights/components@2020-02-02' = {
  name: 'test'
  location: infra.environment.location
  kind: 'other'
}
{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "infra": {
      "value": {
        "environment": {
          "location": "West Europe"
        }
      }
    }
  }
}

When I use the TemplateAnalyzer.exe analyze-directory command this fails with the error The language expression property 'environment' doesn't exist, available properties are 'property1'... When I use the TemplateAnalyzer.exe analyze-template with the -p command then it works fine indeed 👍🏻:

Parameters File: D:\temp\template.parameters.json

        Rules passed: 0

Execution summary:
        The execution completed successfully

@JohnathonMohr thanks for the workaround!! Is the auto-discovery of parameters when analyzing a directory on the roadmap?

1reaction
JohnathonMohrcommented, Oct 26, 2022

I believe the issue is when a template doesn’t define a default value for the object. The value used during analysis is a mocked object, which will not have the expected properties during template expansion, and fail to parse.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Feature Request - "partial" parameters file support #3274
This would allow for doing things like having a base template (shared publicly), and a default set of parameters that you use locally...
Read more >
Add 'Json' export type support (Export pester object - ...
It would be great to have a way to export the PesterObject in a standard way to pesist it to a file. The...
Read more >
ARM template best practices - Resource Manager
Describes recommended approaches for authoring Azure Resource Manager templates (ARM templates). Offers suggestions to avoid common problems ...
Read more >
Create parameters files for Bicep deployment - Azure
bicepparam file extension or a JSON parameters file that contains the parameter values. This article shows how to create parameters files. Note.
Read more >
JSON:API — Latest Specification (v1.1)
The JSON:API specification supports two media type parameters: ext and profile , which are used to specify extensions and profiles, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found