Is there a maximum length for lists?

Do Terraform lists have a maximum length? I just ran into an issue where I added another item onto a list a got the following error:

Error: Error refreshing state: 3 errors occurred:
    * module.XYZ.aws_sqs_queue_policy.sqs_policy: 1 error occurred:
    * module.XYZ.aws_sqs_queue_policy.sqs_policy[19]: index 19 out of range 
for list data.aws_iam_policy_document.sqs_policy.*.json (max 19) in:

We’re on version 0.11.0.

Hi @erikgreen-x!

Lists in Terraform are limited only by a couple practical constraints: available memory to store them and the fact that internally element indices are represented as integers of the native size of your platform (32-bit or 64-bit). Certainly no limit that would prevent a 20-element list, nor that would produce an error like you saw here.

It does look like you’ve hit a rather strange behavior there, though. I expect you’ve found a planning bug in Terraform 0.11.0 where it’s evaluating an expression too soon before the new list item has been added. Since you are dealing with a data source there that seems likely: I remember that we found and fixed some bugs of this sort during the 0.11 point releases.

Upgrading to 0.11.14 (the latest 0.11 release) may help here.

Hi @apparentlymart. I’m on Terraform version 0.11.14 and my specifies any version 0.11.x.

required_version = "~>0.11.0

I’m not sure about “evaluating an expression too soon before the new list item has been added” comment, but we have a hard-coded list, not dynamically generated, and we’re using count along with count.index to access elements in the list. I looked at some issues related to this, but they all seemed to be related to dynamically generated lists and/or use of the splat operator.

I suppose next step is to file an issue for this one.

Thanks for opening the issue, @erikgreen-x!

In the interests of creating a trail for anyone who finds this topic in the future, the issue that span off from this topic is here:

Note that there is no further development on Terraform 0.11 planned, so unfortunately it’s unlikely that this issue will be fixed unless it’s also affecting 0.12.x releases. The language engine was significantly rebuilt for Terraform 0.12, and so the codepath that generated this error in 0.11.14 doesn’t exist at all anymore, but that doesn’t mean that there can’t be a similar bug in the new implementation. The team will need to try to reproduce it across both and see.

1 Like