hashicorp/terraform · error
No instance found for the given address! This command…
Error message
No instance found for the given address! This command requires that the address references one specific instance. To view the available instances, use "terraform state list". Please modify the address to reference a specific instance.
What it means
Returned by `terraform state show` when the state exists and refreshes fine, but the requested resource address either does not exist in state or has no current instance object (`!is.HasCurrent()`). The message tells the user the address must reference one specific instance and suggests `terraform state list`.
Solutions
- Run `terraform state list` and copy the exact address (including `[index]` for counted/for-each resources).
- If the resource was destroyed or never applied, run `terraform apply` to create it.
- Confirm you are targeting the right workspace whose state contains that resource.
Example fix
# before terraform state show aws_instance.web # counted resource -> error # after terraform state list # see exact address terraform state show aws_instance.web[0]
Defensive patterns
Strategy: validation
Validate before calling
// Validate the instance exists and is current before showing:
is := state.ResourceInstance(addr)
if is == nil || !is.HasCurrent() {
return errors.New(errNoInstanceFound)
} Type guard
// hasCurrentInstance reports whether an address resolves to a live instance.
func hasCurrentInstance(s *states.Sync, addr addrs.AbsResourceInstance) bool {
is := s.ResourceInstance(addr)
return is != nil && is.HasCurrent()
} Prevention
- Always `terraform state list` first and copy the exact address.
- Include `[index]` / `["key"]` for counted/for-each resources.
- Confirm the resource has been applied in the selected workspace.
When it happens
Trigger: `state.ResourceInstance(addr)` returns an instance whose `HasCurrent()` is false — the resource was never created, was destroyed, the address is misspelled, or a counted/for-each resource was asked for without an index.
Common situations: Asking for `aws_instance.web` when it is actually `aws_instance.web[0]`; resource was `terraform destroy`-ed; typo in the address; the provider has not yet created the resource (pre-apply).
Related errors
- No state file was found! State management commands require…
- backendDiags.Err()
- Can't ask approval for state migration when interactive…
- errInteractiveInputDisabled
- resource not found in state
AI-assisted analysis of hashicorp/terraform@d32a084675 (2026-08-11).
Data as JSON: /api/errors/626b49b2d0f3297e.
Report an issue: GitHub.
Appendix: source
Thrown at internal/command/state_show.go:130
stateMgr, sDiags := b.StateMgr(env)
if sDiags.HasErrors() {
diags = diags.Append(fmt.Errorf(errStateLoadingState, sDiags.Err()))
return view.DisplayResourceInstanceState(jsonformat.State{}, diags)
}
if err := stateMgr.RefreshState(); err != nil {
diags = diags.Append(fmt.Errorf("Failed to refresh state: %s\n", err))
return view.DisplayResourceInstanceState(jsonformat.State{}, diags)
}
state := stateMgr.State()
if state == nil {
diags = diags.Append(errors.New(errStateNotFound))
return view.DisplayResourceInstanceState(jsonformat.State{}, diags)
}
is := state.ResourceInstance(addr)
if !is.HasCurrent() {
diags = diags.Append(errors.New(errNoInstanceFound))
return view.DisplayResourceInstanceState(jsonformat.State{}, diags)
}
// check if the resource has a configured provider, otherwise this will use the default provider
rs := state.Resource(addr.ContainingResource())
absPc := addrs.AbsProviderConfig{
Provider: rs.ProviderConfig.Provider,
Alias: rs.ProviderConfig.Alias,
Module: addrs.RootModule,
}
singleInstance := states.NewState()
singleInstance.EnsureModule(addr.Module).SetResourceInstanceCurrent(
addr.Resource,
is.Current,
absPc,
)
mockFile := statefile.New(singleInstance, "", 0)View on GitHub (pinned to d32a084675)