Stagg
Stagg

Reputation: 2855

Terraform aws_dynamodb_table_item resource fails when item contains List AttributeValue

Trying to create a dynamodb table item resource which contains a DynamoDB List AttributeValue:

resource "aws_dynamodb_table_item" "job" {
  table_name = var.some_table.id
  hash_key   = var.some_table.hash_key
  item       = <<ITEM
{
  "partitionKey": {"S": "JOBID#1"},
  "workloads": [{ "S" : "w1" }, { "S" : "w2" }]
}
ITEM
}

but fails with:

Error: Invalid format of "item": Decoding failed: json: cannot unmarshal array into Go value of type dynamodb.AttributeValue

Works ok if workloads is a string type e.g. {"S": "w1"} but not when a list. What am I doing wrong? Is this resource able to create List AttributeValues?

I'm using Terraform v1.0.0

Upvotes: 2

Views: 2223

Answers (1)

Marcin
Marcin

Reputation: 238131

It should be:

  "partitionKey": {"S": "JOBID#1"},
  "workloads": {"L": [{ "S" : "w1" }, { "S" : "w2" }]}

where L is for list. The info about format is here.

Upvotes: 1

Related Questions