Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved Search Validation Incorrectly Flags Tabular Parameters #26685

Closed
1 task done
Folling opened this issue Jul 18, 2024 · 2 comments · Fixed by #26701
Closed
1 task done

Saved Search Validation Incorrectly Flags Tabular Parameters #26685

Folling opened this issue Jul 18, 2024 · 2 comments · Fixed by #26701

Comments

@Folling
Copy link

Folling commented Jul 18, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

regexp.MustCompile(`^[a-zA-Z0-9!-_]*:[a-zA-Z0-9!_-]+=[a-zA-Z0-9!_-]+|^[a-zA-Z0-9!-_]*:[a-zA-Z0-9!_-]+`),

This regex is wrong and excludes tabular parameters in the form of arg:(*) or arg:(sub_arg:type,sub_arg:type2).

For more info, see here: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/functions/user-defined-functions.

I also think the regex currently in use has some issues, such as the first segment being * instead of + or that ! is allowed within argument names. There's more, but let's keep it brief.
Here's a regex I think is (more) correct:

^[a-zA-Z_][a-zA-Z0-9-_]*:([a-z]+(=[^,\n]+)?|\(\*\)|(\([a-zA-Z_][a-zA-Z0-9-_]*:[a-z]+(,[a-zA-Z_][a-zA-Z0-9-_]*:([a-z]+))*\)))(,\s*[a-zA-Z_][a-zA-Z0-9-_]*:([a-z]+(=[^,\n]+)?|\(\*\)|(\([a-zA-Z_][a-zA-Z0-9-_]*:[a-z]+(,\s*[a-zA-Z_][a-zA-Z0-9-_]*:([a-z]+))*\))))*$

I'm aware it's a bit of a mess, but it matches things pretty convincingly (note that tabular arguments do not support default values): https://regex101.com/r/n99EPo/1

Terraform Version

v1.9.0

AzureRM Provider Version

3.112.0

Affected Resource(s)/Data Source(s)

azurerm_log_analytics_saved_search

Terraform Configuration Files

resource "azurerm_log_analytics_saved_search" "hello_world" {
  name                       = "hello_world"
  log_analytics_workspace_id = data.azurerm_log_analytics_workspace.example.id

  category     = "FooBar"
  display_name = "HelloWorld"
  query        = <<QUERY
    print("Hello World!")
  QUERY

  function_alias = "HelloWorld"
  function_parameters = [
    "foo:(*)"
  ]
}

Debug Output/Panic Output

│ Error: invalid value for function_parameters.0 (Log Analytics Saved Search Function Parameters must be in the following format: param-name1:type1=default_value1 OR param-name1:type1 OR param-name1:string='string goes here')
│ 
│   with module.saved_searches.azurerm_log_analytics_saved_search.hello_world,
│   on modules/saved_searches/main.tf line 400, in resource "azurerm_log_analytics_saved_search" "hello_world":
│  400:     "foo:(*)"

Expected Behaviour

Terraform should respect all valid function parameter definitions.

Actual Behaviour

It doesn't.

Steps to Reproduce

No response

Important Factoids

No response

References

#11341
#10989

@ziyeqf
Copy link
Contributor

ziyeqf commented Jul 19, 2024

Hi @Folling, thanks for reporting and providing the regexp.

The code was committed 3 years ago, might be out of date. I opened a PR(#26701) to update the validation.

For any further discussion please leave comments

Copy link

github-actions bot commented Sep 7, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants