{"record":{"id":"76e35b1c5b766cab","repo":"kubernetes/kops","slug":"error-creating-output-directory-q-v","errorCode":null,"errorMessage":"error creating output directory %q: %v","messagePattern":"error creating output directory %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/terraform/target.go","lineNumber":98,"sourceCode":"func tfGetFilesProviderExtraConfig(c *kops.TargetSpec) map[string]string {\n\tif c != nil &&\n\t\tc.Terraform != nil {\n\t\treturn c.Terraform.FilesProviderExtraConfig\n\t}\n\treturn nil\n}\n\nfunc (t *TerraformTarget) Finish(taskMap map[string]fi.CloudupTask) error {\n\tif err := t.finishHCL2(); err != nil {\n\t\treturn err\n\t}\n\n\tfor relativePath, contents := range t.Files {\n\t\tp := path.Join(t.outDir, relativePath)\n\n\t\terr := os.MkdirAll(path.Dir(p), os.FileMode(0o755))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error creating output directory %q: %v\", path.Dir(p), err)\n\t\t}\n\n\t\terr = os.WriteFile(p, contents, os.FileMode(0o644))\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error writing terraform data to output file %q: %v\", p, err)\n\t\t}\n\t}\n\tklog.Infof(\"Terraform output is in %s\", t.outDir)\n\n\treturn nil\n}\n","sourceCodeStart":80,"sourceCodeEnd":110,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/terraform/target.go#L80-L110","documentation":"During TerraformTarget.Finish, kOps writes all accumulated file payloads into the Terraform output directory, creating parent directories first. If os.MkdirAll cannot create the directory for a file, this error wraps the OS cause. It means the output tree cannot be materialized on disk.","triggerScenarios":"os.MkdirAll fails on path.Dir(outDir/relativePath) — e.g. outDir points inside a read-only path, a file already exists where a directory is needed, disk full, or permission denied on the parent directory.","commonSituations":"Running kops with --out to a directory without write permissions; a stale file named like a required directory inside the out dir; NFS/CI volumes with permission restrictions; SELinux denying writes.","solutions":["Fix permissions on the --out directory (e.g. `sudo chown -R $(whoami) out/`) or pick a writable directory.","Check whether a regular file exists at the path where a directory must be created and remove it.","Check disk space (`df -h`) on the target filesystem.","Avoid reserved/invalid characters or overly long paths in the out path (especially on limited filesystems)."],"exampleFix":"// before (permissions)\ndrwxr-xr-x root out/\n// after\nsudo chown -R $(whoami) out/ && kops update cluster --out out/","handlingStrategy":"validation","validationCode":"outDir := \"/home/user/out\"\nif fi, err := os.Stat(outDir); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists and is not a directory\", outDir)\n}\nif err := os.MkdirAll(outDir, 0o755); err != nil {\n    return fmt.Errorf(\"cannot prepare out dir %s: %w\", outDir, err)\n}","typeGuard":null,"tryCatchPattern":"err := target.Finish(taskMap) // kops internal\nif err != nil && strings.Contains(err.Error(), \"error creating output directory\") {\n    // check permissions/disk and retry after fixing out dir\n}","preventionTips":["Run kops as a user with write access to --out.","Ensure no file exists at a path where kops needs a directory.","Check disk space/quota before large updates.","Avoid network mounts with restrictive permissions as output dirs."],"tags":["filesystem","terraform","kops","permissions"],"backgroundTag":"mkdir-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}