Deeply nested structures in schema.Resource

Are there any soft/hard limits on how much nesting can be done with blocks in a resource schema, I have a recursive data structure and I wasn’t sure if there would be any limits on the size/depth of blocks.


There isn’t a specific hard limit to nesting or schema size, but there is a gRPC message size limit which does end up being what you would hit with a recursive structure.

A few other providers have run in to this (kubernetes-alpha and AWS). AWS specifically hit the limit on 2878 nested blocks or something to that effect.

See Performance issues with blocktoattr.ExpandedVariables and Block.DecoderSpec · Issue #25889 · hashicorp/terraform · GitHub for more info.

Its worth pointing out that with terraform-plugin-go, you can utilize the “Dynamic” type, which allows for an undefined type for a block/attribute, that could be leveraged to solve situations like this as well.

Ah interesting thanks @paultyng, is it possible to calculate what a given structure would produce in terms of gRPC message size?

In theory, but I don’t think our compatibility guarantees extend to the on-the-wire gRPC representation, so it’s probably not a stable calculation to be making.