{"record":{"id":"626b49b2d0f3297e","repo":"hashicorp/terraform","slug":"no-instance-found-for-the-given-address-this-com","errorCode":null,"errorMessage":"No instance found for the given address!\n\nThis command requires that the address references one specific instance.\nTo view the available instances, use \"terraform state list\". Please modify\nthe address to reference a specific instance.","messagePattern":"No instance found for the given address!\n\nThis command requires that the address references one specific instance\\.\nTo view the available instances, use \"terraform state list\"\\. Please modify\nthe address to reference a specific instance\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/state_show.go","lineNumber":130,"sourceCode":"\tstateMgr, sDiags := b.StateMgr(env)\n\tif sDiags.HasErrors() {\n\t\tdiags = diags.Append(fmt.Errorf(errStateLoadingState, sDiags.Err()))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\tif err := stateMgr.RefreshState(); err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to refresh state: %s\\n\", err))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\tstate := stateMgr.State()\n\tif state == nil {\n\t\tdiags = diags.Append(errors.New(errStateNotFound))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\tis := state.ResourceInstance(addr)\n\tif !is.HasCurrent() {\n\t\tdiags = diags.Append(errors.New(errNoInstanceFound))\n\t\treturn view.DisplayResourceInstanceState(jsonformat.State{}, diags)\n\t}\n\n\t// check if the resource has a configured provider, otherwise this will use the default provider\n\trs := state.Resource(addr.ContainingResource())\n\tabsPc := addrs.AbsProviderConfig{\n\t\tProvider: rs.ProviderConfig.Provider,\n\t\tAlias:    rs.ProviderConfig.Alias,\n\t\tModule:   addrs.RootModule,\n\t}\n\tsingleInstance := states.NewState()\n\tsingleInstance.EnsureModule(addr.Module).SetResourceInstanceCurrent(\n\t\taddr.Resource,\n\t\tis.Current,\n\t\tabsPc,\n\t)\n\n\tmockFile := statefile.New(singleInstance, \"\", 0)","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/state_show.go#L112-L148","documentation":"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).","triggerScenarios":"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.","commonSituations":"Typo in instance index; referencing a module resource path that no longer exists; state lists the resource type but the specific instance key changed.","solutions":["Run `terraform state list` to see exact addresses currently in state, then copy the precise address.","If the resource should exist, run `terraform plan`/`apply` to (re)create it, then retry.","Check count/for_each indices and module paths against the state list output."],"exampleFix":"# before (wrong index)\n terraform state show aws_instance.web[5]\n# after\n terraform state list              # shows aws_instance.web[0]\n terraform state show aws_instance.web[0]","handlingStrategy":"validation","validationCode":"// List state addresses and confirm the exact address before showing.\n addrs, _ := exec.Command(\"terraform\", \"state\", \"list\").CombinedOutput()\n if !containsLine(addrs, targetAddr) {\n     return errors.New(\"address not in state; pick from `terraform state list`\")\n }","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"terraform\", \"state\", \"show\", addr).CombinedOutput()\n if err != nil && bytes.Contains(out, []byte(\"No instance found\")) {\n     // list state, choose a valid address, retry\n }","preventionTips":["Run `terraform state list` and copy the exact address (including indices/keys) before `state show`.","Match count/for_each indices and module paths to what state actually contains."],"tags":["state","state-show","resource-address","not-found"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}