{"record":{"id":"d4b7dd4d1ad54bfa","repo":"hashicorp/terraform","slug":"error-loading-config-with-snapshot-w","errorCode":null,"errorMessage":"error loading config with snapshot: %w","messagePattern":"error loading config with snapshot: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/cloud/backend_common.go","lineNumber":659,"sourceCode":"\t\t\t\tuploaded = true\n\t\t\t}\n\t\t}\n\t}\n\n\tif !uploaded {\n\t\treturn nil, b.generalError(\n\t\t\t\"Failed to upload configuration files\", errors.New(\"operation timed out\"))\n\t}\n\n\tlog.Printf(\"[TRACE] backend/cloud: configuration uploaded and ready\")\n\n\treturn cv, nil\n}\n\nfunc (b *Cloud) parseRunVariables(op *backendrun.Operation) ([]*tfe.RunVariable, error) {\n\tconfig, configDiags := op.ConfigLoader.LoadRootModule(op.ConfigDir)\n\tif configDiags.HasErrors() {\n\t\treturn nil, fmt.Errorf(\"error loading config with snapshot: %w\", configDiags.Errs()[0])\n\t}\n\n\tvariables, varDiags := ParseCloudRunVariables(op.Variables, config.Variables)\n\n\tif varDiags.HasErrors() {\n\t\treturn nil, varDiags.Err()\n\t}\n\n\trunVariables := make([]*tfe.RunVariable, 0, len(variables))\n\tfor name, value := range variables {\n\t\trunVariables = append(runVariables, &tfe.RunVariable{\n\t\t\tKey:   name,\n\t\t\tValue: value,\n\t\t})\n\t}\n\n\treturn runVariables, nil\n}","sourceCodeStart":641,"sourceCodeEnd":677,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/cloud/backend_common.go#L641-L677","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: variable with bad default\nvariable \"count\" { default = \"abc\" }\n// -> error loading config with snapshot: <diag>\n// after: correct the variable definition\nvariable \"count\" { type = number default = 0 }","handlingStrategy":"validation","validationCode":"// Validate config loads cleanly before preparing variables.\nif diags := loader.LoadRootModule(dir); diags.HasErrors() {\n    return diags // surface to user before parseRunVariables\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["terraform","config","variables","hcl","cloud-backend"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}