After going through all these tips and tricks, it’s worth taking a step back and pointing out a few gotchas, including those related to loops and if-statements, as well as those related to more general problems that affect Terraform as a whole:
count and for_each have limitations.
Valid plans can fail.
Refactoring can be tricky.