coralogix / terraform-provider-coralogix

Terraform provider for Coralogix
https://registry.terraform.io/providers/coralogix/coralogix
Apache License 2.0
11 stars 8 forks source link

Unable to create dashboards using data_table widget with aggregations #224

Closed rudolf-repcin closed 5 months ago

rudolf-repcin commented 6 months ago

Affected Resource(s)

Terraform Configuration Files

coralogix_dashboard resource snippet 1 Here I have used official Coralogix TF 1.13.4 documentation to build a data table - however not sure how to reference the Aggregation in the column so I used its name. I also tried just with "Aggregation". ```hcl resource "coralogix_dashboard" "test1" { layout = { sections = [ { rows = [ { height = 19 widgets = [ { definition = { data_table = { query = { logs = { filter = [ { logs = { field = "applicationname" operator = { type = "equals" selected_values = ["xxx"] } } }, { logs = { field = "subsystemname" operator = { type = "equals" selected_values = ["xxx"] } } } ] aggregation = { type = "count" } group_names_fields = [ { keypath = ["xxx", "xxx", "xxx"] scope = "label" } ] } } results_per_page = 10 row_style = "one_line" columns = [ { field = "GroupBy:coralogix.metadata.subsystemName" }, { field = "Aggregation:Count" } ] data_mode_type = "archive" order_by = { field = "Aggregation:Count" order_direction = "desc" } } } title = "New Data Table" } ] } ] } ] } name = "Dashboard TEST" } ```
coralogix_dashboard resource snippet 2 Here I have used extracted code from tfstate after creating the dashboard manually in the UI and then using "data" source in Terraform to load it into tfstate. This one has a different structure than that provided in the documentation. Here I'm trying to use the aggregation name. ```hcl resource "coralogix_dashboard" "test2" { layout = { sections = [ { rows = [ { height = 19 widgets = [ { definition = { data_table = { columns = [ { field = "GroupBy:xxx" }, { field = "Aggregation:Count" width = 200 } ] data_mode_type = "archive" order_by = { field = "Aggregation:Count" order_direction = "desc" } query = { logs = { filters = [ { field = "applicationname" observation_field = { keypath = ["applicationname"] scope = "label" } operator = { selected_values = ["xxx"] type = "equals" } }, { field = "subsystemname" observation_field = { keypath = ["subsystemname"] scope = "label" } operator = { selected_values = ["xxx"] type = "equals" } } ], grouping = { aggregations = [ { aggregation = { type = "count" } is_visible = true name = "Count" } ] group_bys = [ { keypath = ["xxx", "xxx", "xxx"] scope = "user_data" } ] } } } results_per_page = 10 row_style = "one_line" } } title = "New Data Table" } ] } ] } ] } name = "Dashboard TEST" } ```
coralogix_dashboard resource snippet 3 Here I'm also using the code from tfstate, however I tried to assign the "id" to the aggregation definition and referenced it in column and order by. ```hcl resource "coralogix_dashboard" "test3" { layout = { sections = [ { rows = [ { height = 19 widgets = [ { definition = { data_table = { columns = [ { field = "GroupBy:xxx" }, { field = "Aggregation:8e21cba0-070b-79f1-3c1c-05b50f72dacc" width = 200 } ] data_mode_type = "archive" order_by = { field = "Aggregation:8e21cba0-070b-79f1-3c1c-05b50f72dacc" order_direction = "desc" } query = { logs = { filters = [ { field = "applicationname" observation_field = { keypath = ["applicationname"] scope = "label" } operator = { selected_values = ["xxx"] type = "equals" } }, { field = "subsystemname" observation_field = { keypath = ["subsystemname"] scope = "label" } operator = { selected_values = ["xxx"] type = "equals" } } ], grouping = { aggregations = [ { aggregation = { type = "count" } id = "8e21cba0-070b-79f1-3c1c-05b50f72dacc" is_visible = true name = "Count" } ] group_bys = [ { keypath = ["xxx", "xxx", "xxx"] scope = "user_data" } ] } } } results_per_page = 10 row_style = "one_line" } } title = "New Data Table" } ] } ] } ] } name = "Dashboard TEST" } ```

Debug Output

Dashboard 1: Terraform passed but created dashboard contains an Event type data table instead of Aggregation type image Dashboard 2: Terraform passed but the dashboard fails to load in the UI. Browser console contains this error: TypeError: column is undefined Also:

``` ZodError: [ { "code": "invalid_union", "unionErrors": [ { "issues": [ { "code": "invalid_type", "expected": "object", "received": "undefined", "path": [ "dashboard", "layout", "sections", 0, "rows", 0, "widgets", 0, "definition", "dataTable", "query", "logs", "grouping", "aggregations", 0, "id" ], "message": "Required" } ], "name": "ZodError" }, { "issues": [ { "code": "invalid_type", "expected": "string", "received": "undefined", "path": [ "dashboard", "layout", "sections", 0, "rows", 0, "widgets", 0, "definition", "dataTable", "query", "logs", "grouping", "aggregations", 0, "id" ], "message": "Required" } ], "name": "ZodError" } ], "path": [ "dashboard", "layout", "sections", 0, "rows", 0, "widgets", 0, "definition", "dataTable", "query", "logs", "grouping", "aggregations", 0, "id" ], "message": "Invalid input" } ] ```

Dashboard 3: Terraform fails with:

Error: -18T08:26:55.003Z [ERROR] provider.terraform-provider-coralogix_1.13.4: Response contains error diagnostic:
  diagnostic_detail=
  | Cannot set value for this attribute as the provider has marked it as read-only. Remove the configuration line setting the value.
  | 
  | Refer to the provider documentation or contact the provider developers for additional information about configurable and read-only attributes that are supported.
   diagnostic_summary="Invalid Configuration for Read-Only Attribute" tf_proto_version=6.4 tf_resource_type=coralogix_dashboard @caller=github.com/hashicorp/terraform-plugin-go@v0.20.0/tfprotov6/internal/diag/diagnostics.go:62 @module=sdk.proto diagnostic_severity=ERROR tf_req_id=4abd06f1-b65a-71fb-b42a-a372a09b88a6 tf_rpc=ValidateResourceConfig diagnostic_attribute="AttributeName(\"layout\").AttributeName(\"sections\").ElementKeyInt(0).AttributeName(\"rows\").ElementKeyInt(0).AttributeName(\"widgets\").ElementKeyInt(0).AttributeName(\"definition\").AttributeName(\"data_table\").AttributeName(\"query\").AttributeName(\"logs\").AttributeName(\"grouping\").AttributeName(\"aggregations\").ElementKeyInt(0).AttributeName(\"id\")" tf_provider_addr=registry.terraform.io/coralogix/coralogix timestamp=2024-04-18T08:26:55.002Z
Error: -18T08:26:55.003Z [ERROR] vertex "coralogix_dashboard.test3" error: Invalid Configuration for Read-Only Attribute

Expected Behavior

It should be possible to create a dashboard containing data table widget with aggregations via Terraform.

Actual Behavior

It's not possible to create a dashboard containing data table widget with aggregations using latest Terraform provider.

Important Factoids

Terraform 1.6.6 Coralogix TF provider 1.13.4

Community Note

OrNovo commented 6 months ago

@rudolf-repcin I think this is the section your'e looking for

grouping = {
  aggregations = [
    {
      aggregation = {
        type = "count"
      }
      name = "Count"
    },
  ]
  group_bys = [
    {
      keypath = ["ingressTimestamp"]
      scope   = "metadata"
    },
  ]
}
OrNovo commented 5 months ago

@rudolf-repcin please let me know if it solved your issue, so I can close it.

rudolf-repcin commented 5 months ago

Hello, the snippet you suggested is exactly what I already tried: image image It's in "coralogix_dashboard resource snippet 2" code snippet in the issue description

OrNovo commented 5 months ago

@rudolf-repcin I see what you say. I'll set the aggregation id to optional so you could set it as option 3. Look for next release.

rudolf-repcin commented 5 months ago

Thank you very much.

rudolf-repcin commented 5 months ago

Works like a charm now!! Thank you very much for resolving this frustrating issue we struggled with for a long time now.