Azure / Azure/template-analyzer

[BUG] Placeholder metadata value causing TemplateAnalyzerException

Open
#293 2 comments 0 reactions 0 assignees View on GitHub
bug revisit
Dominant language
C#
Stars
143
Forks
47
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

A user reported that the tool was throwing a TemplateAnalyzerException on a valid ARM template. The error logged to the console output:

```
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 '18' and column '13' is not valid: The language expression property array index '1' is out of bounds.. Please see https://aka.ms/arm-template-expressions for usage details.
```

The template parameter `name` in the template has a default value of `[format('{0}-{1}-{2}', replace(parameters('addressSpace')[0], '/', '-'), split(subscription().displayName, '.')[0], split(subscription().displayName, '.')[1])]`, and for our analysis we don’t have access to the subscription information, so instead of using the real `displayName`, we use a placeholder value, that doesn’t have a dot, that’s why `split(subscription().displayName, '.')[1]` is an out of bounds access

### Expected behavior

The template should be analyzed

### Reproduction Steps

Analyze a template that anywhere uses an expression like `split(subscription().displayName, '.')[1]`

### Environment

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.