{"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/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/cloud/backend_common.go#L641-L677","documentation":"parseRunVariables calls op.ConfigLoader.LoadRootModule(op.ConfigDir); if that returns diagnostics with errors (syntax errors, malformed HCL, unreadable files), the first error diagnostic is wrapped and surfaced. This runs before uploading the config snapshot, so it gates on local config validity.","triggerScenarios":"LoadRootModule returns configDiags.HasErrors(): HCL syntax error in a .tf/.tfvars file; missing required provider block; circular module references; unreadable file due to permissions; invalid variable definitions.","commonSituations":"Developer committed a typo in a .tf file; a referenced module path is wrong; .tfvars has a syntax error; file mode/ownership blocks the runner from reading a .tf file.","solutions":["Run `terraform validate` locally to surface the exact HCL error before retrying.","Open the first diagnostic (configDiags.Errs()[0] is wrapped)—its message names the file and line.","Fix file permissions if the runner cannot read a .tf/.tfvars file.","Verify module source paths resolve in the runner's working directory."],"exampleFix":"// before (variables.tf)\nvariable \"instance_count\" {\n  type = number\n  default = \"3\"   // type mismatch\n}\n\n// after\nvariable \"instance_count\" {\n  type    = number\n  default = 3\n}","handlingStrategy":"validation","validationCode":"// run validate before pushing the snapshot\ndiags := root.LoadConfig(op.ConfigDir)\nif diags.HasErrors() {\n    return diags.Errs()[0]\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run `terraform validate` and `terraform fmt -check` in CI before any cloud run.","Keep HCL syntax tight; lint .tfvars too.","Ensure the runner has read permission on all .tf/.tfvars files.","Validate module paths resolve in the runner's working directory."],"tags":["tfe","hcp","cloud-backend","config","hcl","validation"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}