{"record":{"id":"1d6b78ca082b4532","repo":"hashicorp/terraform","slug":"terraform-encountered-problems-during-initialisati","errorCode":null,"errorMessage":"Terraform encountered problems during initialisation, including problems\nwith the configuration, described below.\n\nThe Terraform configuration must be valid before initialization so that\nTerraform can determine which modules and providers need to be installed.","messagePattern":"Terraform encountered problems during initialisation, including problems\nwith the configuration, described below\\.\n\nThe Terraform configuration must be valid before initialization so that\nTerraform can determine which modules and providers need to be installed\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/init_run.go","lineNumber":125,"sourceCode":"\tif err != nil {\n\t\tdiags = diags.Append(fmt.Errorf(\"Error checking configuration: %s\", err))\n\t\tview.Diagnostics(diags)\n\t\treturn 1\n\t}\n\tif empty {\n\t\tview.Output(views.OutputInitEmptyMessage)\n\t\treturn 0\n\t}\n\n\t// Load just the root module to begin backend and module initialization\n\trootModEarly, earlyConfDiags := c.loadSingleModuleWithTests(path, initArgs.TestsDirectory)\n\n\t// There may be parsing errors in config loading but these will be shown later _after_\n\t// checking for core version requirement errors. Not meeting the version requirement should\n\t// be the first error displayed if that is an issue, but other operations are required\n\t// before being able to check core version requirements.\n\tif rootModEarly == nil {\n\t\tdiags = diags.Append(errors.New(errInitConfigError), earlyConfDiags)\n\t\tview.Diagnostics(diags)\n\n\t\treturn 1\n\t}\n\tif !(c.Meta.AllowExperimentalFeatures && initArgs.EnablePssExperiment) && rootModEarly.StateStore != nil {\n\t\t// TODO(SarahFrench/radeksimko) - remove when this feature isn't experimental.\n\t\t// This approach for making the feature experimental is required\n\t\t// to let us assert the feature is gated behind an experiment in tests.\n\t\t// See https://github.com/hashicorp/terraform/pull/37350#issuecomment-3168555619\n\n\t\tdetail := \"Pluggable state store is an experiment which requires\"\n\t\tif !c.Meta.AllowExperimentalFeatures {\n\t\t\tdetail += \" an experimental build of terraform\"\n\t\t}\n\t\tif !initArgs.EnablePssExperiment {\n\t\t\tif !c.Meta.AllowExperimentalFeatures {\n\t\t\t\tdetail += \" and\"\n\t\t\t}","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/init_run.go#L107-L143","documentation":"errInitConfigError (init_run.go:125) is a preamble diagnostic appended when the root module fails to load at all during early config parsing (rootModEarly == nil). It frames the underlying parsing diagnostics, telling the developer Terraform cannot determine modules/providers to install until the configuration is syntactically and semantically valid. The actual parse errors follow in earlyConfDiags.","triggerScenarios":"Line 117-129: loadSingleModuleWithTests returns a nil rootModEarly (catastrophic parse failure, e.g. unreadable/corrupt main .tf file); errors.New(errInitConfigError) is appended together with earlyConfDiags and run returns 1 before the version-requirement check.","commonSituations":"A syntax error in main.tf so severe the module cannot load; a missing/typo'd required_providers block preventing module load; file permission errors reading .tf files; HCL that breaks the parser entirely.","solutions":["Run 'terraform validate' or 'terraform fmt' to surface the underlying parse error in earlyConfDiags.","Fix the syntax/type error reported in the appended diagnostics, then re-run 'terraform init'.","Check file permissions and that .tf files are readable by the current user.","Ensure required_providers and terraform block syntax are correct (no malformed blocks)."],"exampleFix":"// before: main.tf has a syntax error -> rootModEarly nil\n// resource \"aws_instance\" \"web\" {\n//   ami = \"ami-x\"\n//   // missing closing brace\n//\n// after\n// resource \"aws_instance\" \"web\" {\n//   ami = \"ami-x\"\n// }","handlingStrategy":"validation","validationCode":"// Pre-validate the root module with 'terraform validate' style parsing before init.\nfunc preflightRootModule(dir string) error {\n    parser := configs.NewParser(nil)\n    _, diags := parser.LoadConfigDir(dir)\n    if diags.HasErrors() {\n        return fmt.Errorf(\"root module parse error: %w\", diags.Err())\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run 'terraform fmt -check' and 'terraform validate' before 'terraform init'.","Keep required_providers and terraform blocks syntactically correct.","Lint .tf files in CI to catch parse errors before init runs."],"tags":["init","config-loading","hcl-parse","root-module","validation"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}