`Error: Module is incompatible with count, for_each, and depends_on` — `The module at module.legacy is a legacy module which contains its own local provider configurations`.
IntermediateTroubleshootingDependencies, Cycles and Providers
Answer
Likely causes → The child module has provider "aws" { ... } blocks inside it. Modules with their own provider blocks can't be used with count/for_each/depends_on.
Diagnose → grep -rn '^provider ' modules/legacy/
Fix → Move provider configuration to the root, declare configuration_aliases in the module if it needs multiple, and pass providers in:
module "legacy" {
source = "./modules/legacy"
for_each = var.regions
providers = { aws = aws.mumbai }
}
Note: you still can't choose a provider per for_each instance dynamically; one module call per provider is needed.
Prevent → Module guideline: no provider blocks in reusable modules, only required_providers.
More on Dependencies, Cycles and Providers
`Error: Cycle: aws_security_group.app, aws_security_group.db`.Beginner`Error: Cycle: local.name_prefix, local.tags`.BeginnerA cycle appears only after adding `depends_on = [module.app]` to a module. The error lists dozens of nodes.IntermediateAdding `create_before_destroy = true` to a launch template causes `Error: Cycle: ... (destroy deposed ...)`.Advanced`terraform init` fails: `Could not retrieve the list of available versions for provider hashicorp/aws: no available releases match the given constraints ~> 4.0, >= 5.30.0`.Intermediate`Error: Inconsistent dependency lock file` with `locked version selection 5.31.0 doesn't match the updated version constraints ">= 5.40.0"`.Beginner