Terraform aws_dynamodb_table_item - insert multiline JSON into attribute

Viewed 680

I have the following terraform config:

resource "aws_dynamodb_table_item" "my_table" {
  table_name = aws_dynamodb_table.my_table.name
  hash_key   = aws_dynamodb_table.my_table.hash_key

  item = <<ITEM
{
  "id": {"S": "nameAndCodes"},
  "data": {"S": "[
    {
      "code": "03",
      "displayName": "name1"
    },
    {
      "code": "04",
      "displayName": "name2"
    }
  ]"}
}
ITEM
}

When the plan stage executes I receive the error:

Error: Invalid format of "item": Decoding failed: invalid character '\r' in string literal

The only way i can get this to work is to make the whole json a single line as follows:

"data": {"S": "[{\"code\": \"03\", \"displayName\": \"name1\"},{\"code\": \"04\", \"displayName\": \"name2\"}]"

This looks very ugly and difficult to manage.

Does anyone know how I can enter a multiline JSON inside a <<ITEM block?

0 Answers
Related