0

While working on log Queries in an arm template, I stuck with how to pass parameter values or variable values in the log Query.

parameters:   
{  
    "resProviderName":     
        {  
          "value": "Microsoft.Storage"      
       }  
} 

For Eg:

AzureMetrics | where ResourceProvider == **parameters('resProviderName')** | where Resource == 'testacc'  

Here I am facing an error like, it was taking parameters('resProviderName') as a value and it was not reading value from that particular parameter "resProviderName" and my requirement is to take the values from parameters or variables and should not hardcode like what I did in the above query as Resource=='testacc'.
Do we have any option to read the values from either parameters or variables in the log query? If so, please help on this issue.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
suresh d
  • 29
  • 4

2 Answers2

0

The answer to this would depend on what this query segment is a part of, and how your template is structured.

It appears that you're trying to reference a resource in the query. It is best to use one of the many available template resource functions if you want the details of the resource like its resourceID (within the resources section). When referencing a resource that is deployed in the same template, provide the name of the resource through a parameter. When referencing a resource that isn't deployed in the same template, fetch the resource ID.

Also, I'd recommend referring to the ARM snippet given this example to understand how queries can be constructed as custom variables as opposed to the other way round. According to ARM template best practices, variables should be used for values that you need to use more than once in a template. If a value is used only once, a hard-coded value makes your template easier to read. For more info, please take a look at this doc.

Hope this helps.

Bhargavi Annadevara
  • 4,923
  • 2
  • 13
  • 30
0

This is an old question but I bumped into this while searching for the same issue.

I'm much more familiar with Bicep templates so what I did to figure out was to create a Bicep template, construct the query by using the variables and compile it. This will generate a ARM template and you can analyze it.

I figured out you can use both concat or format functions in order to construct your query using variables. I preferred the format one since it looks more elegant and readable (also, Bicep build generates the string using the format function).

So based on this example, the query would be something like this:

query: "[format('AzureMetrics | where ResourceProvider == {0} | where Resource == ''testacc'' ', parameters('resProviderName') )]"

Don't forget to escape the ' in the ARM template which you do by doubling the single quote.

I hope this helps some people.

André

andrescpacheco
  • 604
  • 1
  • 8
  • 26