Menu

Terraform Says for_each Keys Can't Be Known Until Apply. Here's What It Actually Wants
📰

Terraform Says for_each Keys Can't Be Known Until Apply. Here's What It Actually Wants

DEV Community: terraform·CloudSkill Consulting LLC·7 days ago
#4LVGRWF3
#devtoterraform#devto#dev#keys#plan
Reading 0:00
15s threshold

As of November 8, 2026, this post sums up the official pages linked here.

TL;DR: Terraform gives every for_each instance an address like aws_route_table_association.public["us-east-1a"] , and it must know those keys during plan . If a key comes from something that only exists after apply , plan stops with Invalid for_each argument . The two usual causes are keys built from generated attributes, and a depends_on on a data source that pushes its read to apply time. The fix is to take keys from your config and let only the values be unknown. -target gets you past one run but doesn't fix the config.

The problem

A Reddit user was building route table associations for the public subnets behind a load balancer. Their flow went like this:

Read the load balancer with a data source.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.