Azure/template-analyzer

[BUG] template-analyzer throws TemplateValidationException for subscription().displayName for bicep as The language expression property 'displayName' doesn't exist

vlahane opened this issue · 0 comments

Describe the bug

Below is the sample code:

param name string = 'vnet-${subscription().displayName}'
param location string
resource vnet 'Microsoft.Network/virtualNetworks@2022-01-01' = {
  name: name
  location: location
}

Gives error:

Error: An exception occurred while analyzing a template
Exception details:
Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzerException: Error while processing template.
 ---> Azure.Deployments.Templates.Exceptions.TemplateValidationException: The template resource 'name' at line '12' and column '13' is not valid: The language expression property 'displayName' doesn't exist, available properties are 'id, subscriptionId, tenantId'.. Please see https://aka.ms/arm-template-expressions for usage details.
 ---> Azure.Deployments.Core.Exceptions.ExpressionException: The language expression property 'displayName' doesn't exist, available properties are 'id, subscriptionId, tenantId'.
   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.TemplateParameterizationEngine.ParameterizeInputParameter(String parameterName, TemplateInputParameter parameter, InsensitiveDictionary`1 inputParameters, ExpressionEvaluationContext evaluationContext, Boolean ignoreEvaluationExceptionsForWhatIf)
   at Azure.Deployments.Templates.Engines.TemplateParameterizationEngine.ParameterizeInputParameterRecursive(String parameterName, TemplateInputParameter parameter, InsensitiveDictionary`1 inputParameters, InsensitiveDictionary`1 recursionState, ExpressionEvaluationContext evaluationContext, Boolean ignoreEvaluationExceptionsForWhatIf)
   --- End of inner exception stack trace ---
   at Azure.Deployments.Templates.Engines.TemplateParameterizationEngine.ParameterizeInputParameterRecursive(String parameterName, TemplateInputParameter parameter, InsensitiveDictionary`1 inputParameters, InsensitiveDictionary`1 recursionState, ExpressionEvaluationContext evaluationContext, Boolean ignoreEvaluationExceptionsForWhatIf)
   at Azure.Deployments.Templates.Engines.TemplateParameterizationEngine.ParameterizeInputParameters(Template template, InsensitiveDictionary`1 inputParameters, InsensitiveDictionary`1 metadata, Boolean ignoreEvaluationExceptionsForWhatIf, InsensitiveDictionary`1 functionEvaluationOverwrites)
   at Azure.Deployments.Templates.Engines.TemplateParameterizationEngine.ParameterizeTemplate(Template template, InsensitiveDictionary`1 inputParameters, InsensitiveDictionary`1 metadata, Boolean ignoreEvaluationExceptionsForWhatIf, InsensitiveDictionary`1 functionEvaluationOverwrites)
   at Microsoft.Azure.Templates.Analyzer.TemplateProcessor.ArmTemplateProcessor.ParseAndValidateTemplate(InsensitiveDictionary`1 parameters, InsensitiveDictionary`1 metadata)
   at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeTemplate(String template, String templateFilePath, String parameters)
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Templates.Analyzer.Core.TemplateAnalyzer.AnalyzeTemplate(String template, String templateFilePath, String parameters)
   at Microsoft.Azure.Templates.Analyzer.Cli.CommandLineParser.AnalyzeTemplate(FileInfo templateFilePath, FileInfo parametersFilePath)

Execution summary:
        The verbose mode (option -v or --verbose) can be used to obtain even more information about the execution.

        Summary of the errors:
                1 instance of: An exception occurred while analyzing a template

        0 Warnings
        1 Error

Expected behavior

Should not throw any error.

Reproduction Steps

Copy below code to demo.bicep

param name string = 'vnet-${subscription().displayName}'
param location string
resource vnet 'Microsoft.Network/virtualNetworks@2022-01-01' = {
  name: name
  location: location
}

now run command TemplateAnalyzer to analyze demo.bicep

TemplateAnalyzer.exe analyze-template demo.bicep

Environment

TemplateAnalyzer.exe --version
0.3.0

dotnet --version
6.0.202

vscode (IDE): 1.71.0