hashicorp / hashicorp/terraform-exec
Don't set Pdeathsig when running inside aws lambda
- Dominant language
- Go
- Stars
- 786
- Forks
- 129
- PR merge metrics
- No merged PRs in 30d
Description
When running tfexec inside a aws lambda any command dies with a cryptic error:
`fork/exec /var/task/terraform: operation not permitted: PathError`.
The issue is in `tfexec/cmd_linux.go`, setting `Pdeathsig` is not allowed in the lambda runtime and the execution is blocked.
I understand running terraform inside a lambda is not a recommended pattern but I find it really handy for modules that don't take too long to apply (15 mins max runtime).
The fix itself is simple enough and doesn't affect non-lambda linux runtimes: check for lambda runtime before setting SysProcAttr
```golang
if _, ok := os.LookupEnv("LAMBDA_TASK_ROOT"); !ok {
cmd.SysProcAttr = &syscall.SysProcAttr{
// kill children if parent is dead
Pdeathsig: syscall.SIGKILL,
// set process group ID
Setpgid: true,
}
}
```
Would you be interested in a PR to address this?
Contributor guide
Research direction
Start in tfexec/cmd_linux.go and inspect where SysProcAttr is assigned. Check how the LAMBDA_TASK_ROOT environment variable identifies the Lambda runtime, then verify that Lambda execution avoids the restricted process settings while other Linux runtimes retain the existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, go
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100