hashicorp/terraform · error
error loading plugin path: %s
Error message
error loading plugin path: %s
What it means
Thrown by `terraform state show` when c.loadPluginPath() returns an error. loadPluginPath reads the forced plugin directories file (.terraform/.terraformrc-relative plugin path marker, i.e. the file written by -plugin-dir) and returns an error if that file exists but cannot be read or fails to JSON-unmarshal. The %s is the underlying read/parse error.
Source
Thrown at internal/command/state_show.go:49
// Parse and apply global view arguments
common, args := arguments.ParseView(args)
c.View.Configure(common)
parsedArgs, diags := arguments.ParseStateShow(args)
if diags.HasErrors() {
c.View.Diagnostics(diags)
c.View.HelpPrompt("state show")
return 1
}
c.Meta.statePath = parsedArgs.StatePath
c.viewType = parsedArgs.ViewType
view := views.NewShow(parsedArgs.ViewType, c.View)
// Check for user-supplied plugin path
var err error
if c.pluginPath, err = c.loadPluginPath(); err != nil {
diags = diags.Append(fmt.Errorf("error loading plugin path: %s", err))
view.Diagnostics(diags)
return 1
}
// Load the backend
b, diags := c.backend(".", c.viewType)
if diags.HasErrors() {
return view.DisplayResourceInstanceState(jsonformat.State{}, diags)
}
// We require a local backend
local, ok := b.(backendrun.Local)
if !ok {
diags = diags.Append(ErrUnsupportedLocalOp)
return view.DisplayResourceInstanceState(jsonformat.State{}, diags)
}
// This is a read-only commandView on GitHub (pinned to c9def3e214)
Solutions
- Inspect .terraform for the forced plugin path file and validate it is a JSON array of strings.
- If corrupt, delete it and re-run `terraform init` to regenerate, or clear forced dirs with `terraform init` without -plugin-dir.
- Fix .terraform permissions so the current user can read it.
- Re-run `terraform state show` after init succeeds.
Example fix
# before: corrupt forced plugin path file terraform state show aws_instance.web # error loading plugin path: invalid character... # after rm .terraform/.terraformrc_plugin_path # remove corrupt marker terraform init terraform state show aws_instance.web
Defensive patterns
Strategy: validation
Validate before calling
// before running state show, validate the forced plugin path file is sane.
func validateForcedPluginDirs(path string) error {
raw, err := os.ReadFile(path)
if os.IsNotExist(err) { return nil }
if err != nil { return err }
var dirs []string
return json.Unmarshal(raw, &dirs)
} Prevention
- Do not manually edit the forced plugin path marker file.
- Re-run `terraform init` if you change -plugin-dir usage.
- Keep .terraform/ readable by the user running Terraform.
- Avoid file-sync tools that truncate small marker files.
When it happens
Trigger: Running `terraform state show <addr>` when .terraform's forced-plugin-dirs file (PluginPathFilename) exists but is unreadable (permissions) or contains invalid JSON (corrupt/truncated), via WorkingDir.ForcedPluginDirs().
Common situations: Corrupted forced plugin path file from an interrupted init; permissions change on .terraform/; editor or sync tool truncating the file; mismatched Terraform version writing a different format.
Related errors
- error loading plugin path: %s
- Failed to load state: %s
- Failed to marshal state to json: %s
- invalid syntax: %w
- No state file was found! State management commands require
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/428b506e02f7a96c.
Report an issue: GitHub.