So I was applying a TF Provider to create 150 resource via simple terraform apply and noticed that it prints out resources in batches:
# batch #1
foo_resource.bar_1: Creating...
...
foo_resource.bar_10: Creating...
foo_resource.bar_1: Creation complete after 12s [id=...]
...
foo_resource.bar_10: Creation complete after 15s [id=...]
# batch #2
foo_resource.bar_11: Creating...
...
Moreover when I opened trace logs I could see that there’re 10 logs within the same second:
# batch #1
2022-03-03T00:48:59.139-0800 [INFO] provider.: 2022/03/03 00:48:59 [DEBUG] Created foo_1: timestamp=2022-03-03T00:48:59.139-0800
2022-03-03T00:48:59.139-0800 [INFO] provider.: 2022/03/03 00:48:59 [DEBUG] Created foo_3: timestamp=2022-03-03T00:48:59.139-0800
...
# batch #2
2022-03-03T00:49:20.866-0800 [INFO] provider.: 2022/03/03 00:49:20 [DEBUG] Created foo_12: timestamp=2022-03-03T00:49:10.866-0800
so you can clearly see timestamp difference between batch #1 and batch #2 is about 20 seconds (00:49:20 – 00:48:59) which is the exact same timeout that provider uses internally after creating each resource so it seems like it doesn’t send 150 create requests simulteniously but rather execute them in batches where each batch size is 10.
The question is does Terraform batch resource creation automatically or it’s just a coincidence?
>Solution :
Terraform doesn’t perform batching, but does have a parallelism limit, which defaults to 10: https://www.terraform.io/cli/commands/apply#parallelism-n