-
Notifications
You must be signed in to change notification settings - Fork 134
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
Improvement: allow triple quoted strings within JSON body #317
Comments
A very similar case is the embedded JSON needed in the body of the WorkaroundFor now (and this should work for the email html body too I imagine) my workaround is to use resource "elasticsearch_xpack_watch" "my-watcher" {
watch_id = "my-watcher-id"
body = templatefile(
"${path.module}/my-watcher-template.tftpl",
{
secret_teams_webhook_path = ...
teams_webhook_body_json_escaped = format("%q", templatefile(
"${path.module}/my-webhook-body-teams.tftpl",
{
teams_title = "Thing X went wrong"
}
))
}
)
} with {
...
"actions": {
"webhook_1": {
"webhook": {
"host": "...",
"port": 443,
"path": "${secret_teams_webhook_path}",
"method": "post",
"scheme": "https",
"body": ${teams_webhook_body_json_escaped}
}
}
}
} but with the webhook body interpolated from the escaped contents of {
"@type": "MessageCard",
"@context": "https://schema.org/extensions",
"summary": "${teams_title}",
"themeColor": "0078D7",
"sections": [
{
"activityTitle": "${teams_title}"
}
],
...
}
Note that the string produced by |
@sparrowt thanks for opening the issue - I have wished for the triple quoted strings as well. Your approach is a valid workaround. I think my general suggestion for a workaround would be to use HCL to build the objects and convert that to JSON, e.g.: body = jsonencode({
test = {
"is_write_index" = true
}
foo = <<-EOT
hello new
line world
EOT
}) One potential way to implement this directly is to use a extension of JSON like JSON5. However, the public go implementations I saw were all archived, e.g. https://github.com/flynn/json5. I think a helpful outcome of this issue would be to document these two workarounds as suggested approaches. |
Firstly thank you for this excellent provider! I'm filing this to track a desirable feature, but appreciate that (like me!) you may well have no desire or time to implement it. Nevertheless perhaps someone else or one of us will in future.
Summary: it would be really handy if the
body
of certain resources (e.g. watchers) was allowed to contain triple-quoted strings in the format sometimes returned by Elastic via Kibana dev tools (e.g. to allow multi-line strings within JSON, delimited by"""
).For example, to include a non-trivial amount of detail in the email action > body > html then you have to write it all on one line e.g. like this, which gets unwieldy to edit and for source control etc:
It would be amazing if we could instead do this:
Currently this fails due to
ValidateFunc
being set tovalidation.StringIsJSON
e.g. in the case ofelasticsearch_xpack_watch
that is here: https://github.com/phillbaker/terraform-provider-elasticsearch/blob/v2.0.4/es/resource_elasticsearch_xpack_watch.go#L27The text was updated successfully, but these errors were encountered: