{"record":{"id":"15d69ec277582ec6","repo":"hashicorp/terraform","slug":"failed-to-create-stacks-plugin-stored-path-file","errorCode":null,"errorMessage":"failed to create stacks plugin stored path file: %w","messagePattern":"failed to create stacks plugin stored path file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/stacks.go","lineNumber":415,"sourceCode":"\t}\n\n\tif info, err := os.Stat(pluginPath); err != nil || !info.IsDir() {\n\t\tlog.Printf(\"[TRACE] initialized stacksplugin cache directory at %q\", pluginPath)\n\t\terr = os.MkdirAll(pluginPath, 0755)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to initialize stacksplugin cache directory: %w\", err)\n\t\t}\n\t} else {\n\t\tlog.Printf(\"[TRACE] stacksplugin cache directory found at %q\", pluginPath)\n\t}\n\n\treturn pluginPath, nil\n}\n\nfunc (c *StacksCommand) storeStacksPluginPath(pluginCachePath string) error {\n\tf, err := os.Create(path.Join(c.WorkingDir.DataDir(), \".stackspluginpath\"))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create stacks plugin stored path file: %w\", err)\n\t}\n\tdefer f.Close()\n\tf.WriteString(pluginCachePath)\n\n\treturn nil\n}\n\n// Run runs the stacks command with the given arguments.\nfunc (c *StacksCommand) Run(args []string) int {\n\targs = c.Meta.process(args)\n\treturn c.realRun(args, c.Meta.Streams.Stdout.File, c.Meta.Streams.Stderr.File)\n}\n\n// Help returns help text for the stacks command.\nfunc (c *StacksCommand) Help() string {\n\thelpText := new(bytes.Buffer)\n\terrorText := new(bytes.Buffer)\n","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/stacks.go#L397-L433","documentation":"Thrown by StacksCommand.storeStacksPluginPath when os.Create of `.stackspluginpath` in c.WorkingDir.DataDir() fails. This is the write side of the cache path store that [743] reads. os.Create failure means the data dir is missing/unwritable, or a file of the same name exists as a directory or is locked.","triggerScenarios":"DataDir() (typically `.terraform/`) does not exist or is read-only; `.terraform/.stackspluginpath` already exists as a directory; disk full; Windows file lock by another process holding it open.","commonSituations":"`.terraform/` was deleted between init and stacks run; running terraform as a different user than the one that owns `.terraform/`; container with read-only mount for the workspace; concurrent terraform processes writing the marker.","solutions":["Run `terraform init` first so `.terraform/` exists and is owned by the current user.","Verify ownership and writability: `ls -la .terraform/ && touch .terraform/.test`.","Run terraform with the same user account that owns the working directory.","If on a read-only filesystem, point TF_DATA_DIR at a writable location."],"exampleFix":"# before: read-only workspace mount\n terraform stacks up\n\n# after\n export TF_DATA_DIR=/tmp/tfdata\n terraform init\n terraform stacks up","handlingStrategy":"validation","validationCode":"// Ensure DataDir exists and is writable before storeStacksPluginPath.\ndataDir := c.WorkingDir.DataDir()\nif err := os.MkdirAll(dataDir, 0755); err != nil {\n    return fmt.Errorf(\"data dir %s not writable: %w\", dataDir, err)\n}\nif info, err := os.Stat(dataDir); err == nil && info.Mode().Perm()&0200 == 0 {\n    return fmt.Errorf(\"data dir %s is not user-writable\", dataDir)\n}","typeGuard":null,"tryCatchPattern":"f, err := os.Create(path.Join(c.WorkingDir.DataDir(), \".stackspluginpath\"))\nif err != nil {\n    if os.IsPermission(err) {\n        // helpful hint rather than raw PathError\n        return fmt.Errorf(\"cannot write %s/.stackspluginpath (permission denied); check TF_DATA_DIR ownership: %w\", c.WorkingDir.DataDir(), err)\n    }\n    return fmt.Errorf(\"failed to create stacks plugin stored path file: %w\", err)\n}","preventionTips":["Always run `terraform init` before `terraform stacks` so `.terraform/` exists.","Run terraform as the user that owns the working directory.","Use `TF_DATA_DIR` to relocate state on read-only mounts.","Avoid `sudo terraform` which creates root-owned files future runs cannot modify."],"tags":["terraform","stacks","plugin","filesystem","data-dir","permissions"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}