Interview Prep/Terraform/Loops, Conditionals, Dynamic Blocks and Functions

What does "The for_each value depends on resource attributes that cannot be determined until apply" mean?

AdvancedConceptLoops, Conditionals, Dynamic Blocks and Functions
Answer

Terraform must know the keys of for_each (or the value of count) at plan time to build the graph. If keys come from something computed, such as aws_instance.x.id, they are unknown. Fix it by keying on values known statically (names from variables), or apply in two steps with -target only as a last resort.

All Terraform questions Roadmap: Terraform

More on Loops, Conditionals, Dynamic Blocks and Functions