hashicorp / hashicorp/terraform-exec
Feature Request: Add option to hide console windows for child processes on Windows
- Dominant language
- Go
- Stars
- 786
- Forks
- 129
- PR merge metrics
- No merged PRs in 30d
Description
## Description
I'm developing a GUI application (redc) using Wails (a Go framework for building desktop apps) and using terraform-exec to run Terraform commands.
- https://github.com/wgpsec/redc/
When running in development mode (`wails dev`), Terraform executes without any console windows popping up. However, when building the application as a production executable (`wails build`), every Terraform command (init, plan, apply) spawns new cmd.exe console windows that flash on the screen.
## Expected Behavior
When running as a GUI application without a console, Terraform child processes should not spawn visible console windows on Windows.
## Actual Behavior
- **Development mode** (`wails dev`): No console windows appear - Terraform inherits the terminal from the dev process
- **Production build** (`wails build`): Console windows appear for every terraform command (init, plan, apply)
- Using `-ldflags "-H windowsgui"` when building hides the main application console, but child processes still create new console windows
## Environment
- OS: Windows 10/11
- Go version: 1.24
- terraform-exec version: v0.24.0
- Wails version: v2.11.0
## Possible Solutions
I've tried several approaches without success:
1. Setting environment variables like `TF_IN_AUTOMATION=1`, `TF_INPUT=0`
2. Using batch wrapper scripts
3. Building with `-ldflags "-H windowsgui"`
The root cause is that on Windows, when the parent process has no console (GUI application), child processes created via `exec.Command` spawn new console windows. This can only be solved by setting `SysProcAttr.HideWindow = true` at the process creation level.
## Request
Would it be possible to add an option to terraform-exec that allows setting `SysProcAttr` on the underlying `exec.Cmd`? This would enable users to hide console windows for child processes on Windows, similar to how other projects handle this:
```go
cmd.SysProcAttr = &syscall.SysProcAttr{
HideWindow: true,
}
```
Or alternatively, automatically detect when running in a GUI-only environment and set this attribute automatically.
Contributor guide
Research direction
Start by locating where terraform-exec constructs the underlying exec.Cmd for Terraform commands and review how Windows process attributes can be configured. Done means callers can control whether child-process console windows are hidden on Windows, with behavior verified for the relevant command paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100