A module call with `for_each = var.services` fails: `The "for_each" set includes values derived from resource attributes that cannot be determined until apply` only on first apply.
IntermediateTroubleshootingModules, Variables, Sensitive Values and Workspaces
Answer
Likely causes → var.services (a root variable) is fine, but you merged it with something unknown (for example merge(var.services, { for k, v in aws_ecr_repository.r : k => ... })).
Diagnose → terraform console with the plan state; trace which part is unknown.
Fix → Keep the for_each keys from static data (keys(var.services)) and pass resource values inside each element.
Prevent → Separate "which instances" (static keys) from "their config" (can be dynamic).
More on Modules, Variables, Sensitive Values and Workspaces
`Error: Module not installed` — `This module is not yet installed. Run "terraform init" to install all modules required by this configuration.`Beginner`Error: Failed to download module` — `git::https://github.com/acme/tf-modules.git?ref=v2.3.0 ... exit status 128` in CI, works locally.Intermediate`Error: Invalid module source address` for `source = "github.com/acme/modules//vpc?ref=v1.0"` with a `version = "1.0.0"` argument.BeginnerAfter bumping a registry module from 4.x to 5.x, plan shows dozens of resources destroyed and recreated.Advanced`Error: No value for required variable` — `The root module input variable "db_password" is not set, and has no default value.` in CI.Beginner`Error: Invalid value for variable` — `This was checked by the validation rule at variables.tf:8,3-13.`Beginner