{"record":{"id":"af181106413fe581","repo":"hashicorp/terraform","slug":"failed-to-upload-script-v","errorCode":null,"errorMessage":"Failed to upload script: %v","messagePattern":"Failed to upload script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/builtin/provisioners/remote-exec/resource_provisioner.go","lineNumber":270,"sourceCode":"\t\t<-cmdCtx.Done()\n\t\tcomm.Disconnect()\n\t}()\n\n\tfor _, script := range scripts {\n\t\tvar cmd *remote.Cmd\n\n\t\toutR, outW := io.Pipe()\n\t\terrR, errW := io.Pipe()\n\t\tdefer outW.Close()\n\t\tdefer errW.Close()\n\n\t\tgo copyUIOutput(o, outR)\n\t\tgo copyUIOutput(o, errR)\n\n\t\tremotePath := comm.ScriptPath()\n\n\t\tif err := comm.UploadScript(remotePath, script); err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to upload script: %v\", err)\n\t\t}\n\n\t\tcmd = &remote.Cmd{\n\t\t\tCommand: remotePath,\n\t\t\tStdout:  outW,\n\t\t\tStderr:  errW,\n\t\t}\n\t\tif err := comm.Start(cmd); err != nil {\n\t\t\treturn fmt.Errorf(\"Error starting script: %v\", err)\n\t\t}\n\n\t\tif err := cmd.Wait(); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t// Upload a blank follow up file in the same path to prevent residual\n\t\t// script contents from remaining on remote machine\n\t\tempty := bytes.NewReader([]byte(\"\"))","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/builtin/provisioners/remote-exec/resource_provisioner.go#L252-L288","documentation":"Returned by runScripts in remote-exec at resource_provisioner.go:270 when comm.UploadScript(remotePath, script) fails while pushing a script to the remote host. The connection is already established; the failure is in transferring script bytes to comm.ScriptPath().","triggerScenarios":"remote-exec provisioner reaches the upload step after connecting; UploadScript returns an error (permissions, disk, dropped session).","commonSituations":"Remote script upload directory not writable; disk full on the instance; SSH session interrupted; SELinux/AppArmor blocking execution of uploaded files.","solutions":["Verify the connection user can write to comm.ScriptPath() (usually the user's home/temp).","Free disk space on the remote and retry.","Stabilize the connection (bastion, timeouts) if sessions drop mid-upload."],"exampleFix":"// before\nconnection { user = \"appuser\" host = aws_instance.web.public_ip }\nprovisioner \"remote-exec\" { scripts = [\"run.sh\"] } // Failed to upload script\n\n// after: use a user with a writable home dir and explicit timeout\nconnection { user = \"ec2-user\" host = aws_instance.web.public_ip timeout = \"5m\" }\nprovisioner \"remote-exec\" { scripts = [\"${path.module}/run.sh\"] }","handlingStrategy":"retry","validationCode":"// Confirm the remote upload target dir is writable.\ncmd := &remote.Cmd{Command: \"test -w \\\"$(dirname \" + remotePath + \")\\\"\"}\nif err := comm.Start(cmd); err != nil { return err }","typeGuard":null,"tryCatchPattern":"var err error\nfor i := 0; i < 3; i++ {\n    if err = comm.UploadScript(remotePath, script); err == nil { break }\n    if !isTransientCommError(err) { return fmt.Errorf(\"Failed to upload script: %v\", err) }\n    time.Sleep(backoff(i))\n}","preventionTips":["Use a connection user whose home/temp dir is writable for comm.ScriptPath().","Add bastion host and timeout tuning for unstable links."],"tags":["terraform","remote-exec","ssh","upload","scripts"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T20:17:04.800Z"}