Terraform-provider-aws: aws_redshift_parameter_group should compress WLM json config to one line

Created on 8 Mar 2019  路  2Comments  路  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 馃憤 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

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.

New or Affected Resource(s)

Resource aws_redshift_parameter_group

References

Related issue: https://github.com/hashicorp/terraform/issues/5526

enhancement servicredshift

Most helpful comment

@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]+/", "")}"
  }
}

All 2 comments

@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

Was this page helpful?
0 / 5 - 0 ratings