I have a root module which calls child module with this call:
module "routing_extapp_data" {
source = "../../modules/Stack/Routing"
routing = {
src_rt_ids = module.extapp_vpc.private_route_table_ids
dst_rt_ids = module.data_vpc.private_route_table_ids
src_cidr = module.extapp_vpc.vpc.cidr_block
dst_cidr = module.data_vpc.vpc.cidr_block
peering_connection_id = module.peering_extapp_data.peering_connection_ids
name = "extapp-data"
src_provider = "aws.stack"
dst_provider = "aws.stack"
}
providers = {
aws.stack = aws.stack
aws.ops = aws.ops
}
}
In child module I have:
resource "aws_route" "src_stack" {
timeouts {
create = "5m"
delete = "5m"
}
for_each = {for rt_id in var.routing.src_rt_ids: format("%s-%s", var.routing.name, rt_id) => rt_id if var.routing.src_provider == "aws.stack"}
provider = aws.stack
route_table_id = each.value
destination_cidr_block = var.routing.dst_cidr
vpc_peering_connection_id = var.routing.peering_connection_id
}
However it gives me this error:
The "for_each" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the for_each depends on.
Logs says:
2020/02/19 14:49:38 [TRACE] evalVariableValidations: not active for module.routing_extapp_intapp.var.routing, so skipping
2020/02/19 14:49:38 [TRACE] [walkPlan] Exiting eval tree: module.routing_extapp_intapp.var.routing
2020/02/19 14:49:38 [TRACE] vertex “module.routing_extapp_intapp.var.routing”: visit complete
2020/02/19 14:49:38 [TRACE] dag/walk: visiting “module.routing_extapp_intapp.aws_route.dst_stack”
2020/02/19 14:49:38 [TRACE] vertex “module.routing_extapp_intapp.aws_route.dst_stack”: starting visit (*terraform.NodePlannableResource)
2020/02/19 14:49:38 [TRACE] vertex “module.routing_extapp_intapp.aws_route.dst_stack”: evaluating
2020/02/19 14:49:38 [TRACE] [walkPlan] Entering eval tree: module.routing_extapp_intapp.aws_route.dst_stack
2020/02/19 14:49:38 [TRACE] module.routing_extapp_intapp: eval: *terraform.EvalWriteResourceState
2020/02/19 14:49:38 [WARN] Provider “Terraform Registry” produced an invalid plan for module.peering_extapp_intapp.aws_vpc_peering_connection_accepter.stack_accept_peering[0], but we are tolerating it because it is using the legacy plugin SDK.
The following problems may be the cause of any confusing errors from downstream operations:
.accepter: attribute representing nested block must not be unknown itself; set nested attribute values to unknown instead
.requester: attribute representing nested block must not be unknown itself; set nested attribute values to unknown instead
2020/02/19 14:49:38 [TRACE] module.peering_extapp_intapp: eval: *terraform.EvalCheckPreventDestroy
2020/02/19 14:49:38 [TRACE] module.peering_extapp_intapp: eval: *terraform.EvalWriteState
2020/02/19 14:49:38 [TRACE] EvalWriteState: writing current state object for module.peering_extapp_intapp.aws_vpc_peering_connection_accepter.stack_accept_peering[0]
2020/02/19 14:49:38 [ERROR] module.routing_extapp_intapp: eval: *terraform.EvalWriteResourceState, err: Invalid for_each argument: The “for_each” value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created. To work around this, use the -target argument to first apply only the resources that the for_each depends on.
2020/02/19 14:49:38 [TRACE] [walkPlan] Exiting eval tree: module.routing_extapp_intapp.aws_route.dst_stack
2020/02/19 14:49:38 [TRACE] vertex “module.routing_extapp_intapp.aws_route.dst_stack”: visit complete
2020/02/19 14:49:38 [TRACE] GRPCProvider: Close