{"record":{"id":"bf30f9b459b0a26a","repo":"hashicorp/terraform","slug":"error-starting-script-v","errorCode":null,"errorMessage":"Error starting script: %v","messagePattern":"Error starting script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/builtin/provisioners/remote-exec/resource_provisioner.go","lineNumber":279,"sourceCode":"\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(\"\"))\n\t\tif err := comm.Upload(remotePath, empty); err != nil {\n\t\t\t// This feature is best-effort.\n\t\t\tlog.Printf(\"[WARN] Failed to upload empty follow up script: %v\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/builtin/provisioners/remote-exec/resource_provisioner.go#L261-L297","documentation":"Returned by runScripts at resource_provisioner.go:279 when comm.Start(cmd) fails to begin executing the previously uploaded script at comm.ScriptPath(). The script bytes are already on the host; this is a failure to launch the process.","triggerScenarios":"After UploadScript succeeds, the communicator (SSH/WinRM) fails to start the command bound to remotePath.","commonSituations":"Script lacks the executable bit or a shebang; the remote shell/interpreter is missing; path with spaces or quoting issues; resource (the instance) terminated between upload and start; WinRM command-shell restrictions.","solutions":["Ensure scripts start with a valid shebang (#!/bin/sh) and are uploaded with execute permission.","Confirm the interpreter (sh/bash/powershell) exists on the remote image.","Avoid spaces in the script path; quote if necessary.","Verify the instance is still running at apply time (not terminated by a parallel destroy)."],"exampleFix":"// before: script has no shebang / not executable\nprovisioner \"remote-exec\" { scripts = [\"do-stuff.sh\"] } // Error starting script\n\n// after: use inline with shebang-equivalent or chmod first\nprovisioner \"remote-exec\" {\n  inline = [\n    \"chmod +x /tmp/run.sh\",\n    \"/tmp/run.sh\",\n  ]\n}","handlingStrategy":"validation","validationCode":"// Ensure scripts have a shebang and executable bit before upload.\nfunc validateScript(path string) error {\n    b := make([]byte, 2)\n    f, _ := os.Open(path); defer f.Close()\n    if _, err := f.Read(b); err != nil || string(b) != \"#!\" {\n        return errors.New(\"script missing shebang\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Start every remote-exec script with a shebang (#!/bin/sh).","chmod +x scripts and avoid spaces in remote paths.","Confirm the interpreter exists on the AMI/image used."],"tags":["terraform","remote-exec","ssh","execution","scripts"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}