opentofu/opentofu
View on GitHubIncorrect warnings produced during `plan -replace`
Open
#4,368 opened on Jul 16, 2026
acceptedbuggood first issue
Repository metrics
- Stars
- (28,648 stars)
- PR merge metrics
- (Avg merge 4d 1h) (73 merged PRs in 30d)
Description
While working on -replace in the new engine, I stumbled across some code that did not make sense. This was traced back through a refactor and to it's initial introduction.
The problem with how this is written is that it is matching based on the addrs.Resource (no module info), not the addrs.AbsResource (with module info).
# main.tf
resource "tfcoremock_simple_resource" "foo" {
count = 2
}
module "child" {
source = "./child"
}
# cat child/child.tf
resource "tfcoremock_simple_resource" "foo" {
count = 2
}
tofu plan -replace=module.child.tfcoremock_simple_resource.foo
<...>
│ Warning: Incompletely-matched force-replace resource instance
│
│ Your force-replace request for module.child.tfcoremock_simple_resource.foo doesn't match any resource instances because it lacks an instance key.
│
│ To force replacement of particular instances, use one or more of the following options instead:
│ -replace="tfcoremock_simple_resource.foo[0]"
│ -replace="tfcoremock_simple_resource.foo[1]"
╵
╷
│ Warning: Incompletely-matched force-replace resource instance
│
│ Your force-replace request for module.child.tfcoremock_simple_resource.foo doesn't match any resource instances because it lacks an instance key.
│
│ To force replacement of particular instances, use one or more of the following options instead:
│ -replace="module.child.tfcoremock_simple_resource.foo[0]"
│ -replace="module.child.tfcoremock_simple_resource.foo[1]"
As you can see it flags both resources with the same provider, type, and name and ignores where the resource actually lives in configuration when determining if it should show a warning.