AWS require the wlm_json_configuration parameter in a Redshift Parameter Group to be single-line JSON. That's kind of rubbish on their part, the API returns this error:
* aws_redshift_parameter_group.analytics: Error modifying Redshift Parameter Group: InvalidParameterValue: Invalid JSON for wlm_json_configuration: Multi line JSON is not allowed
status code: 400, request id: REDACTED
It would be nice to be able to store the configuration as nicely formatted JSON and have Terraform automatically compress it to one line if necessary.
Resource aws_redshift_parameter_group
Related issue: https://github.com/hashicorp/terraform/issues/5526
@ayazabbas @bflad I was able to hack around this with terraform's replace
function:
wlm.json:
[{
"query_concurrency": 15,
"query_group": [],
"query_group_wild_card": 0,
"user_group": [],
"user_group_wild_card": 0,
"auto_wlm": true,
"concurrency_scaling": "auto",
"rules": [{
"rule_name": "rule_query_execution",
"predicate": [{
"metric_name": "query_execution_time",
"operator": ">",
"value": 10000
}],
"action": "abort"
}]
}, {
"short_query_queue": true
}]
Parameter group:
resource "aws_redshift_parameter_group" "foo" {
name = "foo-parameter-group"
family = "redshift-1.0"
description = "foo parameter group"
parameter {
name = "wlm_json_configuration"
# https://github.com/terraform-providers/terraform-provider-aws/issues/7865
# Redshift WLM API expects a single line JSON file, so we're stripping out newlines and tabs here
value = "${replace(var.wlm_json_configuration, "/[\\n\\t]+/", "")}"
}
}
You can also roundtrip json decode/encode to get a oneline json:
jsonencode(jsondecode(file("wlm.json")))
source: https://gitmemory.com/issue/hashicorp/terraform/5526/552028124
Most helpful comment
@ayazabbas @bflad I was able to hack around this with terraform's
replace
function:wlm.json:
Parameter group: