{"record":{"id":"3ee44bb1a995d5c1","repo":"hashicorp/terraform","slug":"failed-to-initialize-config-loader-s","errorCode":null,"errorMessage":"Failed to initialize config loader: %s","messagePattern":"Failed to initialize config loader: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/apply.go","lineNumber":307,"sourceCode":"\n\t// EXPERIMENTAL: maybe enable deferred actions\n\tif c.AllowExperimentalFeatures {\n\t\topReq.DeferralAllowed = args.DeferralAllowed\n\t} else if args.DeferralAllowed {\n\t\t// Belated flag parse error, since we don't know about experiments\n\t\t// support at actual parse time.\n\t\tdiags = diags.Append(tfdiags.Sourceless(\n\t\t\ttfdiags.Error,\n\t\t\t\"Failed to parse command-line flags\",\n\t\t\t\"The -allow-deferral flag is only valid in experimental builds of Terraform.\",\n\t\t))\n\t\treturn nil, diags\n\t}\n\n\tvar err error\n\topReq.ConfigLoader, err = c.initConfigLoader()\n\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Failed to initialize config loader: %s\", err))\n\t\treturn nil, diags\n\t}\n\n\treturn opReq, diags\n}\n\nfunc (c *ApplyCommand) Help() string {\n\tif c.Destroy {\n\t\treturn c.helpDestroy()\n\t}\n\n\treturn c.helpApply()\n}\n\nfunc (c *ApplyCommand) Synopsis() string {\n\tif c.Destroy {\n\t\treturn \"Destroy previously-created infrastructure\"\n\t}","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/apply.go#L289-L325","documentation":"Thrown by terraform apply when c.initConfigLoader() returns a non-nil error, meaning Terraform could not set up the configuration loader needed to parse .tf files. The error is wrapped and appended to diagnostics as a config loader initialization failure. This is an early-stage failure that occurs before any configuration parsing or validation.","triggerScenarios":"c.initConfigLoader() returns an error. This happens when the working directory is inaccessible, required directories do not exist, or there is a filesystem permission issue preventing Terraform from preparing its internal loader state.","commonSituations":"Running terraform apply in a directory without read/write permissions; missing or corrupted .terraform directory; running from a path that does not exist; filesystem errors on network-mounted volumes (NFS, SMB); running as a different user without appropriate access.","solutions":["Verify the working directory exists and is readable: ls -la <directory>","Re-run terraform init to rebuild the .terraform directory if it is missing or corrupted","Check filesystem permissions for the user running terraform","Confirm you are running from the correct directory (use -chdir if needed)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify the working directory is accessible before running apply\nfunc checkWorkdir(path string) error {\n    info, err := os.Stat(path)\n    if err != nil {\n        return fmt.Errorf(\"working directory %s inaccessible: %w\", path, err)\n    }\n    if !info.IsDir() {\n        return fmt.Errorf(\"%s is not a directory\", path)\n    }\n    // Check write access for .terraform dir\n    tfDir := filepath.Join(path, \".terraform\")\n    if _, err := os.Stat(tfDir); err != nil && !os.IsNotExist(err) {\n        return fmt.Errorf(\".terraform directory issue: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"// Wrap terraform apply and surface config loader errors clearly\ncmd := exec.Command(\"terraform\", \"apply\", \"-auto-approve\")\noutput, err := cmd.CombinedOutput()\nif err != nil {\n    if strings.Contains(string(output), \"Failed to initialize config loader\") {\n        return fmt.Errorf(\"config loader init failed — check directory and permissions: %s\", output)\n    }\n    return err\n}","preventionTips":["Verify the working directory exists and is readable before running terraform apply","Re-run terraform init if the .terraform directory is missing or corrupted","Ensure the user account has appropriate filesystem permissions","Use -chdir to run from the correct directory in automation"],"tags":["config-loader","filesystem","terraform-apply","initialization"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}