Module performance


I have a question about Terraform modules: would using modules make running a plan/apply more performant when compared to a single configuration file?

To provide some context:

I have a customer using our Terraform provider. They have a single containing all the configurations for 200 “services”, and each service resource contains nested blocks (e.g. a service might have a domain block or a backend block etc for configuring a web service).

One such resource is a key/value data store which they can seed with values. Now the customer’s approach is to use a single configuration file along with for_each to generate all 200 ‘service’ resources and also the nested object store key/values. They pass a large JSON variable which contains the data for the services.

They find a change to a single key/value takes over 4 minutes, whereas I was able to (with a ‘module structure’ where I had 200 separate modules that the root module would import) update ALL the key/values for each module (all 200 of them) in just over 3 minutes.

I don’t know the customer’s full configuration but it does seem like a single configuration file with 200 resources is remarkably slower to plan/apply than defining 200 separate modules that are imported into the root module.

Is any one here familiar with how Terraform internally handles things and whether what I’m seeing as far as the time difference between architecture/structure is grounded in any kind of reality?


Hi @Integralist,

A Terraform configuration is always processed in its entirety. Modules are a tool to organize, and “modularize” the configuration for easier development and maintenance, but at runtime they are part of the same configuration.

It’s hard to say what the difference may have been between the configurations you were comparing. In the process of changing the structure, you may have removed unnecessary dependencies, and helped with the runtime slightly. The bulk of time required to plan large numbers of resources however is usually the time it takes to read them all from the remote APIs, and reading 200 resources should take the same amount of time regardless of how they are addressed within the Terraform configuration.