{"record":{"id":"6dd0f416e05fe9f1","repo":"hashicorp/terraform","slug":"failed-to-initialize-cloudplugin-cache-directory","errorCode":null,"errorMessage":"failed to initialize cloudplugin cache directory: %w","messagePattern":"failed to initialize cloudplugin cache directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/cloud.go","lineNumber":256,"sourceCode":"\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Warning,\n\t\t\t\"Cloud plugin development overrides are in effect\",\n\t\t\tdetailMsg,\n\t\t))\n\t}\n\tlog.Printf(\"[TRACE] plugin %q binary located at %q%s\", version.ProductVersion, version.Path, cacheTraceMsg)\n\tc.pluginBinary = version.Path\n\treturn diags\n}\n\nfunc (c *CloudCommand) initPackagesCache() (string, error) {\n\tpackagesPath := path.Join(c.WorkingDir.DataDir(), CloudPluginDataDir)\n\n\tif info, err := os.Stat(packagesPath); err != nil || !info.IsDir() {\n\t\tlog.Printf(\"[TRACE] initialized cloudplugin cache directory at %q\", packagesPath)\n\t\terr = os.MkdirAll(packagesPath, 0755)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to initialize cloudplugin cache directory: %w\", err)\n\t\t}\n\t} else {\n\t\tlog.Printf(\"[TRACE] cloudplugin cache directory found at %q\", packagesPath)\n\t}\n\n\treturn packagesPath, nil\n}\n\n// Run runs the cloud command with the given arguments.\nfunc (c *CloudCommand) 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 cloud command.\nfunc (c *CloudCommand) Help() string {\n\thelpText := new(bytes.Buffer)\n\tif exitCode := c.realRun([]string{}, helpText, io.Discard); exitCode != 0 {","sourceCodeStart":238,"sourceCodeEnd":274,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/cloud.go#L238-L274","documentation":"Thrown by CloudCommand.initPackagesCache when os.MkdirAll fails to create the cloudplugin cache directory (path.Join(WorkingDir.DataDir(), CloudPluginDataDir)). Terraform caches the cloudplugin binary there; if it cannot create the directory, the cloud subcommand cannot run.","triggerScenarios":"The data directory (~/.terraform.d or $TF_DATA_DIR) or the cloudplugin subdirectory cannot be created — read-only filesystem, permission denied, or an invalid/empty path returned by WorkingDir.DataDir().","commonSituations":"TF_DATA_DIR points at a read-only or non-writable location; HOME unset in a container/service; running in a sandbox with no home write access; a parent path component is a file not a directory.","solutions":["Verify the data dir resolves correctly and is writable: `terraform -version` then check `echo $TF_DATA_DIR` / `$HOME`.","Create and chmod the parent: `mkdir -p $HOME/.terraform.d && chmod u+w $HOME/.terraform.d`.","Unset or fix TF_DATA_DIR if it points somewhere inappropriate.","For containers, ensure HOME is set to a writable path and a writable volume is mounted there."],"exampleFix":"// before: TF_DATA_DIR=/readonly-cache\n// $ unset TF_DATA_DIR\n// $ mkdir -p $HOME/.terraform.d && chmod 755 $HOME/.terraform.d\n// after: terraform cloud / cloudplugin cache initializes successfully","handlingStrategy":"validation","validationCode":"func dataDirWritable(dataDir string) error {\n    if dataDir == \"\" { dataDir = filepath.Join(os.Getenv(\"HOME\"), \".terraform.d\") }\n    if err := os.MkdirAll(dataDir, 0755); err != nil {\n        return fmt.Errorf(\"cannot use data dir %s: %w\", dataDir, err)\n    }\n    probe, err := os.CreateTemp(dataDir, \".perm-*\")\n    if err != nil { return err }\n    probe.Close(); os.Remove(probe.Name())\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set HOME (and optionally TF_DATA_DIR) to a writable path in CI/containers.","Mount a writable volume at $HOME.","Validate the data dir is writable before running `terraform cloud` flows."],"tags":["cloud","filesystem","permissions","cache","terraform-cli"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}