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.
More on Loops, Conditionals, Dynamic Blocks and Functions
How does `count` work?BeginnerHow does `for_each` work?BeginnerWhen should you choose `for_each` over `count`?IntermediateHow do you use `for_each` with a list of objects?IntermediateWhat does "The for_each value depends on resource attributes that cannot be determined until apply" mean?AdvancedHow do you create a resource conditionally?Beginner