hashicorp/terraform · error

No instance found for the given address! This command requi

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 StateShowCommand (state_show.go:130) using errNoInstanceFound. State exists and refreshed fine, but state.ResourceInstance(addr) returned an instance whose is.HasCurrent() is false — i.e. the address parsed but no current object exists for it (the resource was destroyed, never created, or the address is a count/for_each index that does not exist).

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 c9def3e214)

Solutions

  1. Run `terraform state list` to see exact addresses currently in state, then copy the precise address.
  2. If the resource should exist, run `terraform plan`/`apply` to (re)create it, then retry.
  3. Check count/for_each indices and module paths against the state list output.

Example fix

# before (wrong index)
 terraform state show aws_instance.web[5]
# after
 terraform state list              # shows aws_instance.web[0]
 terraform state show aws_instance.web[0]
Defensive patterns

Strategy: validation

Validate before calling

// List state addresses and confirm the exact address before showing.
 addrs, _ := exec.Command("terraform", "state", "list").CombinedOutput()
 if !containsLine(addrs, targetAddr) {
     return errors.New("address not in state; pick from `terraform state list`")
 }

Try / catch

out, err := exec.Command("terraform", "state", "show", addr).CombinedOutput()
 if err != nil && bytes.Contains(out, []byte("No instance found")) {
     // list state, choose a valid address, retry
 }

Prevention

When it happens

Trigger: Running `terraform state show <addr>` with an address that resolves but has no current instance: wrong index in a count/for_each (e.g. aws_instance.web[99] when only [0] exists), a resource removed via `terraform state rm`, or a destroyed-but-not-pruned entry.

Common situations: Typo in instance index; referencing a module resource path that no longer exists; state lists the resource type but the specific instance key changed.

Related errors


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/626b49b2d0f3297e. Report an issue: GitHub.