hashicorp/terraform · error
error loading config with snapshot: %w
Error message
error loading config with snapshot: %w
What it means
parseRunVariables (backend_common.go:656-660) loads the root configuration module via op.ConfigLoader.LoadRootModule to resolve run variables; if that load returns diagnostics with errors, the first error diagnostic is wrapped here. It means the Terraform configuration itself could not be parsed/loaded before variables could be extracted for the remote run.
Source
Thrown at internal/cloud/backend_common.go:659
uploaded = true
}
}
}
if !uploaded {
return nil, b.generalError(
"Failed to upload configuration files", errors.New("operation timed out"))
}
log.Printf("[TRACE] backend/cloud: configuration uploaded and ready")
return cv, nil
}
func (b *Cloud) parseRunVariables(op *backendrun.Operation) ([]*tfe.RunVariable, error) {
config, configDiags := op.ConfigLoader.LoadRootModule(op.ConfigDir)
if configDiags.HasErrors() {
return nil, fmt.Errorf("error loading config with snapshot: %w", configDiags.Errs()[0])
}
variables, varDiags := ParseCloudRunVariables(op.Variables, config.Variables)
if varDiags.HasErrors() {
return nil, varDiags.Err()
}
runVariables := make([]*tfe.RunVariable, 0, len(variables))
for name, value := range variables {
runVariables = append(runVariables, &tfe.RunVariable{
Key: name,
Value: value,
})
}
return runVariables, nil
}View on GitHub (pinned to c9def3e214)
Solutions
- Run `terraform validate` / `terraform fmt` and fix the reported HCL/syntax errors in the config dir.
- Ensure `terraform init` has downloaded all required modules/providers.
- Read the wrapped diagnostic which names the offending file and line; correct it and retry.
- Confirm op.ConfigDir points at the intended module root.
Example fix
// before: variable with bad default
variable "count" { default = "abc" }
// -> error loading config with snapshot: <diag>
// after: correct the variable definition
variable "count" { type = number default = 0 } Defensive patterns
Strategy: validation
Validate before calling
// Validate config loads cleanly before preparing variables.
if diags := loader.LoadRootModule(dir); diags.HasErrors() {
return diags // surface to user before parseRunVariables
} Prevention
- Run `terraform validate` and `terraform fmt` in CI before plan/apply.
- Ensure `terraform init` has fetched all modules/providers.
- Lint HCL in the repo to catch syntax errors pre-merge.
When it happens
Trigger: op.ConfigLoader.LoadRootModule(op.ConfigDir) at backend_common.go:657 returns configDiags with HasErrors() true. Reached while preparing a cloud run's variables. Caused by syntax errors, missing files, bad module references, or HCL parse failures in the config dir.
Common situations: A .tf file with a syntax/HCL error. A referenced module not downloaded (terraform init not run). Broken variable definitions (duplicate, bad type). File removed between init and apply.
Related errors
- tag object values must be strings
- tag elements must be strings
- error finding remote workspace: %w
- error loading workspace: %w
- error loading variables: %w
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/d4b7dd4d1ad54bfa.
Report an issue: GitHub.