terraform-provider-opensearch
terraform-provider-opensearch copied to clipboard
Monitor creation using templatefile changing JSON file true value to false
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.
Here are the details to reproduce.
- 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"
})
}
- 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"
}
}]
}]
}
- TF plan
Please help us in guiding this through.
Thanks!!
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.
@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)