{"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":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/stacks.go#L397-L433","documentation":"Thrown by StacksCommand.storeStacksPluginPath when os.Create fails to make the .terraform/.stackspluginpath marker file that records where the stacks plugin is cached. The stacks subcommand caches the discovered stacksplugin binary location so subsequent runs skip re-discovery; persisting that location requires a writable data directory. The wrapped %w carries the underlying os.PathError (permission, read-only filesystem, or missing parent dir).","triggerScenarios":"Running `terraform stacks` (or any stacks subcommand) after the stacks plugin has been located, when the working directory's data dir (.terraform/) is read-only, owned by another user, on a full disk, or when the parent directory was removed between initPackagesCache and storeStacksPluginPath. Concretely: os.Create(path.Join(c.WorkingDir.DataDir(), \".stackspluginpath\")) returns a non-nil error.","commonSituations":"CI runners that mark .terraform/ read-only after `terraform init`; containers with a read-only volume mount for the workspace; running as a different UID than the one that ran init; NFS/network filesystem permission mismatches; disk-full ephemeral runners.","solutions":["Verify the data dir is writable: ls -la .terraform/ and ensure the current user owns it.","Re-run `terraform init` in the same directory as the user/UID that will run `terraform stacks`, so ownership matches.","Free disk space or remount the workspace read-write if the .terraform dir is on a read-only mount.","If sharing the dir across users, set group write: chmod -R g+w .terraform and ensure matching group ownership."],"exampleFix":"# before: running stacks as a user that does not own .terraform\nsudo terraform stacks init\n\n# after: run as the owning user, or fix ownership\nchown -R $USER:$USER .terraform\nterraform stacks init","handlingStrategy":"validation","validationCode":"// before calling storeStacksPluginPath, ensure the data dir is writable\nimport \"os\"\n\nfunc dataDirWritable(dir string) error {\n    info, err := os.Stat(dir)\n    if err != nil {\n        return err\n    }\n    if !info.IsDir() {\n        return fmt.Errorf(\"%s is not a directory\", dir)\n    }\n    f, err := os.CreateTemp(dir, \".write-probe-*\")\n    if err != nil {\n        return fmt.Errorf(\"data dir %s is not writable: %w\", dir, err)\n    }\n    f.Close()\n    os.Remove(f.Name())\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `terraform stacks` as the same user/UID that ran `terraform init`.","Keep .terraform/ on a writable filesystem in CI (avoid read-only volume mounts).","Ensure adequate free disk/inode space before running stacks commands.","Do not chmod .terraform/ read-only between init and stacks."],"tags":["stacks","filesystem","permissions","plugin-cache"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}