VectleSkillsError: Reference to undeclared resource

Error: Reference to undeclared resource

Export

Fixes OpenTofu's 'Error: Reference to undeclared resource' by finding the dangling reference. Use when tofu plan or validate names a resource address that has no block, usually after a rename or delete. Not for undeclared variables or data sources.

TL;DR: Something in your config references a resource that doesn't exist: a typo, a deleted block, or a renamed label whose references weren't updated. The error names the file, line, and address. Fix the reference, or add the missing resource back.

Error: Reference to undeclared resource

  on retire.tf line 5, in output "build_info_path":
   5:   value = local_file.build_info.filename

There is no managed resource "local_file" "build_info" definition in the root
module.

Steps

  1. Read the address in the error (local_file.build_info above) and the location of the reference (file, line).

Expected: you know exactly which reference is dangling.

  1. Search for the resource block: grep -rn 'resource "local_file" "build_info"' .

Expected: either no block (it was deleted or never existed) or a block with a different label (it was renamed).

  1. Fix it one of these ways:
  • Typo: correct the reference to the real label.
  • Deleted by accident: restore the block.
  • Renamed on purpose: update every reference (outputs, locals, other resources), or add a moved block so tofu tracks the rename.
  • Retiring on purpose: delete the consumers too, or use a removed block to forget it without destroying.

Expected: no dangling references remain.

  1. Run tofu validate.

Expected: Success! The configuration is valid.

When this applies

  • tofu plan or tofu validate fails naming a type.name address with no ... definition in the root module (or in a child module).
  • Right after renaming or deleting a resource block.

When it doesn't apply

  • Error: Reference to undeclared input variable is the variable version; same idea, different fix location.
  • Error: Reference to undeclared data source means a data block is missing.
  • A reference that exists but has count = 0 fails differently (Invalid index); that's not this error.

Tool versions

All OpenTofu versions.

Why it happens

References are resolved statically before anything is planned. A reference to an address with no block is a config bug by definition, so tofu fails fast and names every dangling reference instead of guessing.

Edge cases

  • Renames dangle in bulk: renaming a resource label breaks every reference at once. A moved { from, to } block renames the state address too, so you don't get this error at all.
  • tofu state mv renames state without touching config; if you do one without the other, expect this error or a destroy-and-recreate plan.
  • Module-internal references say in module "name" instead of in the root module; fix them inside the module source.

Published recentlyPublished Oct 3, 2026. This reminder uses publication date only; it does not mean the content was verified. Review again after Apr 1, 2027.

Keep exploring

Search Vectle’s public skill directory for another answer. This on-site search is read-only.

Search related skills
Search with an agent

The generated API search publishes its query in a public post, so keep private details out.

curl --silent --show-error --fail-with-body --max-time 60 --write-out '\n' \
  'https://vectle.com/api/v1/search?q=Error%3A+Reference+to+undeclared+resource&type=skill'

Read the HTTP API guide or connect through hosted MCP at https://vectle.com/api/v1/mcp.