Hi, I am trying to create Grafana alert for almost 20 services using grafana terraform provider. Added alerts in a plugable way to services… Each service has different set of alerts like “500 errors”, “5xx error percentage” etc. So, relative time range and alert types and service owners etc are service specific data. Then alert consitions, data source, summary message etc would be alert specific data. Finally in main.tf file, I have added the required attribute for resource “grafana_rule_group”. In which I have dynamic block for rules in each service. And inside each rule, created dynamic bloack for conditions(data–A,B or C) in each rule. So, the model attribute is different for data block A, B or C. So, used a template.tpl for conditions and provided the alert specifc input variables to the placeholders in the template using templatefile()(in alert_config.tf file). In the condition, there is a attribute called ‘expr’. Which is like ““expr”: “sum by(status) (increase(http_server_requests_seconds_count{service={{service}}, status=~” 500 “}[1m]))”,”. I can replace the {{$service}} with actual service name, only in main.tf. Not sure how to do that in terraform. Tried many ways. But got error as: " Error: Invalid function argument
201│
202│ on …/gfalerts/shasl_alerts/main.tf line 53, in resource “grafana_rule_group” “shasl_rule_group”:
203│ 53: model = data.key == “A” ? templatefile(“${jsonencode(data.value.model)}”, { service = each.key }) : jsonencode(data.value.model)
204│ ├────────────────
205│ │ data.value.model is “{\n "datasource": {\n "type": "prometheus",\n "uid": "000000018"\n },\n "editorMode": "code",\n "exemplar": true,\n "expr": "sum by(status) (increase(http_server_requests_seconds_count{service={{service}}, status=~"500"}[1m]))",\n "instant": true,\n "interval": "1m",\n "intervalFactor": 1,\n "intervalMs": 1000,\n "legendFormat": "500 errors",\n "maxDataPoints": 43200,\n "range": false,\n "refId": "A"\n}\n”
206│
207│ Invalid value for “path” parameter: open "{\n "datasource": {\n
208│ "type": "prometheus",\n "uid": "000000018"\n },\n
209│ "editorMode": "code",\n "exemplar": true,\n "expr": "sum
210│ by(status)
211│ (increase(http_server_requests_seconds_count{service={{service}},
212│ status=~"500"}[1m]))",\n "instant": true,\n "interval": "1m",\n
213│ "intervalFactor": 1,\n "intervalMs": 1000,\n "legendFormat": "500
214│ errors",\n "maxDataPoints": 43200,\n "range": false,\n "refId":
215│ "A"\n}\n": file name too long."