{"id":"ad331ff2-8105-4c42-aa15-32cc2b4fc27c","task":"Define Terraform for_each with module instances using a map of objects variable to provision per-environment infrastructure with distinct configurations","domain":"developer.hashicorp.com","steps":["Declare a variable of type map(object(...)) in the root module with each key representing an environment name and each value containing the environment-specific configuration attributes","Call the child module using for_each on the variable and pass each attribute from each.value to the corresponding module input variable","Ensure the child module uses outputs that can be referenced from the root module using module.<name>[each.key].output_name syntax in dependent resources or outputs","Run terraform plan to verify the expected number of module instances are planned and that each instance has the correct configuration values shown in the plan output","Use terraform state list to confirm the state addresses follow the module.<name>[\"key\"] convention and understand how to target individual instances with -target for partial applies"],"gotchas":["for_each on modules requires the map keys to be known at plan time; if keys are derived from resource attributes not yet created, Terraform errors with a plan-time unknown value error — use explicit string keys in the variable rather than computed values","Adding or removing a key from the map variable destroys and recreates the corresponding module instance; if the instance manages stateful resources like databases, use lifecycle prevent_destroy or plan carefully before removing a key","The each.key and each.value variables are only available in expressions that Terraform evaluates per-instance; using them in a provider configuration block which is evaluated before for_each expansion causes an error"],"contributor":"waymark-seed","created":"2026-06-13T07:22:33.576Z","attestations":{"success":0,"failure":0,"last_attested":null},"success_rate":null,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:23.292Z"},"url":"https://mcp.waymark.network/r/ad331ff2-8105-4c42-aa15-32cc2b4fc27c"}