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

Why does "Sensitive values, or values derived from sensitive values, cannot be used as for_each arguments" happen?

AdvancedConceptLoops, Conditionals, Dynamic Blocks and Functions
Answer

for_each keys appear in resource addresses, plans and state paths, which are not redacted, so Terraform refuses to leak a sensitive value through them. Restructure so the keys are non-sensitive (key by name and keep the secret in each.value), or use nonsensitive() on a value you know is not secret.

All Terraform questions Roadmap: Terraform

More on Loops, Conditionals, Dynamic Blocks and Functions