Skip to content

provisioner/powershell: add -NonInteractive to default commands#13607

Open
VedantMadane wants to merge 1 commit intohashicorp:mainfrom
VedantMadane:fix/powershell-noninteractive
Open

provisioner/powershell: add -NonInteractive to default commands#13607
VedantMadane wants to merge 1 commit intohashicorp:mainfrom
VedantMadane:fix/powershell-noninteractive

Conversation

@VedantMadane
Copy link
Copy Markdown

Description

Add -NonInteractive flag to all default powershell and pwsh invocations in the PowerShell provisioner's defaultExecuteCommand() and defaultScriptCommand() methods.

Packer builds are inherently non-interactive. When a PowerShell command unexpectedly prompts for user input (e.g., a confirmation dialog from Install-Module), the build hangs indefinitely with no indication of what went wrong. The -NonInteractive flag causes PowerShell to immediately throw a terminating error instead of waiting for input, which lets operators diagnose and fix the issue.

The flag is only added when execution_policy is not none -- when execution policy is none, the default command string contains no powershell/pwsh prefix, so there is nothing to attach the flag to.

All existing unit tests have been updated to expect the new flag in the generated command strings.

Resolved Issues

Closes #12637

Rollback Plan

If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

No changes to security controls.

Add -NonInteractive flag to all default powershell and pwsh invocations
in defaultExecuteCommand() and defaultScriptCommand(). This prevents
Packer builds from hanging when a command unexpectedly prompts for input.

The flag is only added when the execution_policy is not 'none' (i.e.,
when packer explicitly invokes powershell.exe or pwsh.exe). When
execution_policy is 'none', the command string has no shell prefix so
there is nothing to attach the flag to.

Closes hashicorp#12637
@VedantMadane VedantMadane requested a review from a team as a code owner April 12, 2026 10:39
@hashicorp-cla-app
Copy link
Copy Markdown

hashicorp-cla-app bot commented Apr 12, 2026

CLA assistant check
All committers have signed the CLA.

@hashicorp-cla-app
Copy link
Copy Markdown

CLA assistant check

Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement

Learn more about why HashiCorp requires a CLA and what the CLA includes

Have you signed the CLA already but the status is still pending? Recheck it.

@afurm
Copy link
Copy Markdown

afurm commented Apr 13, 2026

Adding -NonInteractive is correct for preventing prompts in CI, but is this a breaking change for users who relied on stdin input during provisioning? Should there be a config flag to control this behavior rather than always enabling it?

@VedantMadane
Copy link
Copy Markdown
Author

Good point. Adding a config flag makes sense here so existing users who rely on stdin do not break. I can add a non_interactive boolean (default true to match the intent of #12637) so users who need stdin input can set it to false. Would that work for you, or would you prefer the default to be false (opt-in) to avoid any risk?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The -NonInteractive Parameter should be added by default when starting a powershell shell

2 participants