phillbaker / terraform-provider-elasticsearch

An elasticsearch provider for terraform
https://registry.terraform.io/providers/phillbaker/elasticsearch
Mozilla Public License 2.0
305 stars 134 forks source link

elasticsearch_opensearch_monitor not updating ui_metadata property in OpenSearch #310

Open leolorenzoluis opened 2 years ago

leolorenzoluis commented 2 years ago

Given the follwing code:

resource "elasticsearch_opensearch_monitor" "test {
  body = <<EOF
{
  "name": "${lookup(var.open_search_monitor_config, "name")}",
  "type": "${lookup(var.open_search_monitor_config, "type")}",
  "monitor_type": "${lookup(var.open_search_monitor_config, "monitor_type")}",
  "enabled": false,
  "schedule": {
    "period": {
      "unit": "MINUTES",
      "interval": 1
    }
  },
  "inputs": [
    {
      "search": {
        "indices": ["logs-aws-*"],
        "query": {
          "size": 0,
          "aggregations": {},
          "query": {
            "bool": {
              "filter": [
                        {
                           "range": {
                              "Created At": {
                                 "from": "{{period_end}}||-1h",
                                 "to": "{{period_end}}",
                                 "include_lower": true,
                                 "include_upper": true,
                                 "format": "epoch_millis",
                                 "boost": 1
                              }
                           }
                        }
                     ],
                     "adjust_pure_negative": true,
                     "boost": 1
                  }
               }
            }
         }
      }
   ],
  "triggers": [
    {
      "query_level_trigger": {
        "id": "queryId",
        "name": "${lookup(var.open_search_monitor_config, "trigger_name")}",
        "severity": "2",
        "condition": {
          "script": {
            "source": "ctx.results[0].hits.total.value > 0",
            "lang": "painless"
          }
        },
        "actions": [
          {
            "id": "alert",
            "name": "send-sns-alert-0",
            "destination_id": "${elasticsearch_opensearch_destination.opensearch-alert-destination.id}",
            "message_template": {
              "source": "Monitor {{ctx.monitor.name}} just entered alert status. Please investigate the issue.\n  - Trigger: {{ctx.trigger.name}}\n  - Severity: {{ctx.trigger.severity}}\n  - Period start: {{ctx.periodStart}}\n  - Period end: {{ctx.periodEnd}}",
              "lang": "mustache"
            },
            "throttle_enabled": false,
            "subject_template": {
              "source": "HUB Alerts-High",
              "lang": "mustache"
            }
          }
        ]
      }
    }
  ],
   "ui_metadata": {
      "monitor_type": "query_level_monitor",
      "schedule": {
         "cronExpression": "0 */1 * * *",
         "daily": 0,
         "frequency": "interval",
         "monthly": {
            "type": "day",
            "day": 1
         },
         "period": {
            "interval": 1,
            "unit": "MINUTES"
         },
         "timezone": null,
         "weekly": {
            "mon": false,
            "tue": false,
            "wed": false,
            "thur": false,
            "fri": false,
            "sat": false,
            "sun": false
         }
      },
      "search": {
         "aggregations": [],
         "bucketUnitOfTime": "h",
         "bucketValue": 1,
         "groupBy": [],
         "searchType": "query",
         "timeField": "",
         "where": {
            "fieldName": [],
            "fieldRangeEnd": 0,
            "fieldRangeStart": 0,
            "fieldValue": "",
            "operator": "is"
         }
      }
   }
}

it looks like the provider does not update the ui_metadataproperly. Tried matching the order of json properties thinking diff might be different what the Read vs it sees? Not sure.

Two scenarios happening:

  1. It creates the resource initially, but when you plan again it'll think those are updated values even if there are no actual changes
  2. It creates the resources initially. Any succeeding updates persists in OpenSearch but provider thinks it's still an update.

Hence I think the provider does not track the correct state for this property?

oleksiidv commented 1 year ago

@phillbaker @leolorenzoluis

Hi,

Has anyone found how to solve this issue? I tried using a different provider "opensearch-project/opensearch". The same problem. Maybe there is another option on how to import (add) OpenSearch alerts to terrafrom?

Yunir commented 1 month ago

@oleksiidv thanks for naming another provider name, didn't hear about that before. If you can reproduce the problem on their provider, can you fill the issue on their project, please? I think it might be fixed faster there because it looks more alive. (here the last release was 2 years before)