{"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":"console","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/c9def3e214014c1188faabfc4a5bde5095139765/internal/command/meta_providers.go#L296-L332","documentation":"Raised when ProviderFactories cannot read/parse the dependency lock file (.terraform.lock.hcl). lockedDependencies() returned diagnostics with errors — the lock file is missing required fields, corrupt, or unreadable. The lock file pins provider versions and checksums; without a valid one Terraform cannot resolve provider factories.","triggerScenarios":"ProviderFactories: m.lockedDependencies() returns diags.HasErrors()==true. Triggered by a hand-edited/malformed .terraform.lock.hcl, a lock file from an incompatible Terraform version, partial merge conflicts left in the lock file, or a permissions/IO error reading it.","commonSituations":"Git merge conflict in .terraform.lock.hcl left unresolved; lock file partially deleted; lock file written by a newer Terraform with schema the current version rejects; lock file manually edited and broken.","solutions":["Inspect .terraform.lock.hcl for syntax errors or unresolved merge conflict markers (<<<<<<<, =======, >>>>>>>).","Resolve conflicts and run `terraform init` to regenerate the lock file.","If the file is unrecoverable, back it up and delete it, then `terraform init -upgrade` to recreate it.","Ensure the Terraform version is compatible with the lock file format."],"exampleFix":"// before\n// .terraform.lock.hcl has unresolved git merge conflict -> error\n\n// after\n# resolve conflict markers, then:\nterraform init\n# or regenerate from scratch:\ncp .terraform.lock.hcl .terraform.lock.hcl.bak && rm .terraform.lock.hcl && terraform init -upgrade","handlingStrategy":"validation","validationCode":"// Lint the lock file for unresolved conflicts before running plan/apply\nfunc lockFileClean(path string) bool {\n    b, _ := os.ReadFile(path)\n    s := string(b)\n    return !strings.Contains(s, \"<<<<<<<\") && !strings.Contains(s, \"=======\" ) && !strings.Contains(s, \">>>>>>>\")\n}\nif !lockFileClean(\".terraform.lock.hcl\") {\n    return fmt.Errorf(\"resolve merge conflicts in lock file first\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve git merge conflicts in .terraform.lock.hcl before running terraform.","Never hand-edit the lock file; regenerate via `terraform init`.","Keep Terraform versions consistent across the team to avoid lock schema drift.","Back up and regenerate a corrupt lock file with terraform init -upgrade."],"tags":["terraform","lock-file","providers","dependencies","hcl"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}