{"record":{"id":"496dd90caee073fd","repo":"hashicorp/terraform","slug":"failed-to-read-dependency-lock-file-s","errorCode":null,"errorMessage":"failed to read dependency lock file: %s","messagePattern":"failed to read dependency lock file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/command/meta_providers.go","lineNumber":314,"sourceCode":"\t\t),\n\t}\n}\n\n// ProviderFactories uses the selections made previously by an installer in\n// the local cache directory (m.providerLocalCacheDir) to produce a map\n// of provider addresses to factory functions to create instances of\n// those providers.\n//\n// ProviderFactories will return an error if the installer's selections cannot\n// be honored with what is currently in the cache, such as if a selected\n// package has been removed from the cache or if the contents of a selected\n// package have been modified outside of the installer. If it returns an error,\n// the returned map may be incomplete or invalid, but will be as complete\n// as possible given the cause of the error.\nfunc (m *Meta) ProviderFactories() (map[addrs.Provider]providers.Factory, error) {\n\tlocks, diags := m.lockedDependencies()\n\tif diags.HasErrors() {\n\t\treturn nil, fmt.Errorf(\"failed to read dependency lock file: %s\", diags.Err())\n\t}\n\n\treturn m.providerFactoriesFromLocks(locks)\n}\n\n// ProviderFactoriesFromLocks receives in memory locks and uses them to produce a map\n// of provider addresses to factory functions to create instances of\n// those providers.\n//\n// ProviderFactoriesFromLocks should only be used if the calling code relies on locks\n// that have not yet been persisted to a dependency lock file on disk. Realistically, this\n// means only code in the init command should use this method.\nfunc (m *Meta) ProviderFactoriesFromLocks(configLocks *depsfile.Locks) (map[addrs.Provider]providers.Factory, error) {\n\t// Ensure overrides and unmanaged providers are reflected in the returned list of factories,\n\t// while avoiding mutating the in-memory\n\tlocks := m.annotateDependencyLocksWithOverrides(configLocks.DeepCopy())\n\n\treturn m.providerFactoriesFromLocks(locks)","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/command/meta_providers.go#L296-L332","documentation":"Meta.ProviderFactories calls lockedDependencies() to read the dependency lock file (.terraform.lock.hcl). If that returns diagnostics with errors, the lock file could not be parsed or loaded, so provider factories cannot be constructed safely and the whole error is wrapped with this message. This is a hard gate: without a readable lock file Terraform refuses to build provider factories from locks.","triggerScenarios":"Meta.ProviderFactories() is invoked (transitively by most commands that need providers); m.lockedDependencies() returns diags where diags.HasErrors() is true, typically because the lock file is syntactically invalid, truncated, or missing required checksum/version blocks for a declared provider.","commonSituations":"Hand-edited or partially-merged .terraform.lock.hcl with HCL syntax errors; lock file corrupted by a git merge conflict left unresolved; lock file from an incompatible Terraform version; lock file deleted but referenced; non-UTF8 bytes written by a broken editor.","solutions":["Run terraform init -upgrade to regenerate a valid .terraform.lock.hcl from the current required_providers block.","Inspect the embedded diagnostics (%s expands to diags.Err()) for the precise HCL parse location and fix that line.","If the lock file has merge conflicts, resolve the conflict markers then re-run terraform init.","As a last resort, back up and remove .terraform.lock.hcl, then terraform init to rebuild it; commit the regenerated file."],"exampleFix":"# before: corrupt lock file causes 'failed to read dependency lock file'\n# after: regenerate\nrm .terraform.lock.hcl\nterraform init -upgrade\ngit add .terraform.lock.hcl && git commit -m \"chore: regenerate dependency lock file\"","handlingStrategy":"validation","validationCode":"// Validate the lock file parses before relying on ProviderFactories.\n_, diags := m.lockedDependencies()\nif diags.HasErrors() {\n    return fmt.Errorf(\"lock file unreadable, run 'terraform init -upgrade': %s\", diags.Err())\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit .terraform.lock.hcl and resolve merge conflicts before running commands.","Never hand-edit the lock file; always regenerate via terraform init/providers lock.","Run terraform init in CI to regenerate a valid lock file when parse errors appear."],"tags":["terraform","lock-file","provider","init","config-parse"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}