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

Monitor creation using templatefile changing JSON file true value to false #170

Open
sandeepsharmadevops opened this issue Mar 26, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@sandeepsharmadevops
Copy link

What is the bug?

A clear and concise description of the bug.
Using opensearch_monitor resource block to create monitor using templatefile for JSON file, where all true boolean values are changing to false.

How can one reproduce the bug?

Steps to reproduce the behavior.

What is the expected behavior?

A clear and concise description of what you expected to happen.
True boolean value shouldn't be changed to false.

What is your host/environment?

Operating system, version.
Terraform version. = 1.6
Opensearch TF provider version = 2.2.0

Do you have any screenshots?

If applicable, add screenshots to help explain your problem.

Do you have any additional context?

Add any other context about the problem.

@sandeepsharmadevops sandeepsharmadevops added bug Something isn't working untriaged labels Mar 26, 2024
@sandeepsharmadevops
Copy link
Author

Here are the details to reproduce.

  1. TF resource block to create monitor, using TF templatefile to pass dynamic values to JSON file.
resource "opensearch_monitor" "example_monitor" {
  body = templatefile("./example_monitor.json", {
    destination_id = "example_destination_id"
  })
}
  1. content of example_monitor.json file
{
  "type": "monitor",
  "name": "test-monitor",
  "monitor_type": "query_level_monitor",
  "enabled": true,
  "schedule": {
    "period": {
      "interval": 1,
      "unit": "MINUTES"
    }
  },
  "inputs": [{
    "search": {
      "indices": ["example-index"],
      "query": {
        "size": 0,
        "aggregations": {},
        "query": {
          "bool": {
            "filter": {
              "range": {
                "@timestamp": {
                  "gte": "{{period_end}}||-1h",
                  "lte": "{{period_end}}",
                  "format": "epoch_millis",
                  "include_lower": true,
                  "include_upper": true
                }
              }
            }
          }
        }
      }
    }
  }],
  "triggers": [{
    "name": "test-trigger",
    "severity": "1",
    "condition": {
      "script": {
        "source": "ctx.results[0].hits.total.value > 0",
        "lang": "painless"
      }
    },
    "actions": [{
      "name": "test-action",
      "destination_id": "${destination_id}",
      "message_template": {
        "source": "This is my message body."
      },
      "throttle_enabled": true,
      "throttle": {
        "value": 27,
        "unit": "MINUTES"
      },
      "subject_template": {
        "source": "TheSubject"
      }
    }]
  }]
}
  1. TF plan
    Screenshot 2024-03-27 at 4 10 56 PM
    Screenshot 2024-03-27 at 4 19 37 PM
    Screenshot 2024-03-27 at 4 20 16 PM

Please help us in guiding this through.

Thanks!!

@samiran31
Copy link

Hi all,

I am facing the same issue, where the monitor resources are going into DISABLED state once we pass it from terraform. In addition to monitor state, other parameters which were true in the json file is getting changed to false(i: getting DISABLED). Kindly support.

@rblcoder
Copy link
Collaborator

@sandeepsharmadevops @samiran31
I am able to run terraform plan successfully.


Terraform used the selected providers to generate the following execution plan. Resource
actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # opensearch_monitor.example_monitor will be created
  + resource "opensearch_monitor" "example_monitor" {
      + body = jsonencode(
            {
              + enabled      = true
              + inputs       = [
                  + {
                      + search = {
                          + indices = [
                              + "example-index",
                            ]
                          + query   = {
                              + aggregations = {}
                              + query        = {
                                  + bool = {
                                      + filter = {
                                          + range = {
                                              + "@timestamp" = {
                                                  + format        = "epoch_millis"
                                                  + gte           = "{{period_end}}||-1h"
                                                  + include_lower = true
                                                  + include_upper = true
                                                  + lte           = "{{period_end}}"
                                                }
                                            }
                                        }
                                    }
                                }
                              + size         = 0
                            }
                        }
                    },
                ]
              + monitor_type = "query_level_monitor"
              + name         = "test-monitor"
              + schedule     = {
                  + period = {
                      + interval = 1
                      + unit     = "MINUTES"
                    }
                }
              + triggers     = [
                  + {
                      + actions   = [
                          + {
                              + destination_id   = "example_destination_id"
                              + message_template = {
                                  + source = "This is my message body."
                                }
                              + name             = "test-action"
                              + subject_template = {
                                  + source = "TheSubject"
                                }
                              + throttle         = {
                                  + unit  = "MINUTES"
                                  + value = 27
                                }
                              + throttle_enabled = true
                            },
                        ]
                      + condition = {
                          + script = {
                              + lang   = "painless"
                              + source = "ctx.results[0].hits.total.value > 0"
                            }
                        }
                      + name      = "test-trigger"
                      + severity  = "1"
                    },
                ]
              + type         = "monitor"
            }
        )
      + id   = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

──────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take
exactly these actions if you run "terraform apply" now.
$ terraform -v
Terraform v1.7.5
Operating system - Debian GNU/Linux 11 (bullseye)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants