hashicorp/terraform · error
target_platform for provisioner has to be either %s or %s
Error message
target_platform for provisioner has to be either %s or %s
What it means
Raised in parseConnectionInfo when target_platform is set to a value other than 'unix' or 'windows'. The communicator uses target_platform to decide script shebang injection, SCP command quoting, and default script paths, so an invalid value is rejected at config-parse time.
Source
Thrown at internal/communicator/ssh/provisioner.go:203
// Check if host is empty.
// Otherwise return error.
if connInfo.Host == "" {
return nil, fmt.Errorf("host for provisioner cannot be empty")
}
// Format the host if needed.
// Needed for IPv6 support.
connInfo.Host = shared.IpFormat(connInfo.Host)
if connInfo.Port == 0 {
connInfo.Port = DefaultPort
}
// Set default targetPlatform to unix if it's empty
if connInfo.TargetPlatform == "" {
connInfo.TargetPlatform = TargetPlatformUnix
} else if connInfo.TargetPlatform != TargetPlatformUnix && connInfo.TargetPlatform != TargetPlatformWindows {
return nil, fmt.Errorf("target_platform for provisioner has to be either %s or %s", TargetPlatformUnix, TargetPlatformWindows)
}
// Choose an appropriate default script path based on the target platform. There is no single
// suitable default script path which works on both UNIX and Windows targets.
if connInfo.ScriptPath == "" && connInfo.TargetPlatform == TargetPlatformUnix {
connInfo.ScriptPath = DefaultUnixScriptPath
}
if connInfo.ScriptPath == "" && connInfo.TargetPlatform == TargetPlatformWindows {
connInfo.ScriptPath = DefaultWindowsScriptPath
}
if connInfo.Timeout != "" {
connInfo.TimeoutVal = safeDuration(connInfo.Timeout, DefaultTimeout)
} else {
connInfo.TimeoutVal = DefaultTimeout
}
// Default all bastion config attrs to their non-bastion counterparts
if connInfo.BastionHost != "" {
// Format the bastion host if needed.View on GitHub (pinned to c9def3e214)
Solutions
- Set target_platform to exactly 'unix' or 'windows'.
- If the attribute is not needed, omit it entirely (it defaults to 'unix').
- Check for typos or trailing whitespace in the value.
Example fix
// before
connection {
host = var.host
target_platform = "linux"
}
// after
connection {
host = var.host
target_platform = "unix"
} Defensive patterns
Strategy: validation
Validate before calling
// Validate target_platform before passing to the communicator
func validateTargetPlatform(platform string) error {
if platform == "" {
return nil // defaults to unix
}
if platform != "unix" && platform != "windows" {
return fmt.Errorf("target_platform must be 'unix' or 'windows', got %q", platform)
}
return nil
} Prevention
- Only use 'unix' or 'windows' for target_platform.
- Omit target_platform entirely if the target is unix (it is the default).
- Double-check for typos or incorrect casing in the value.
When it happens
Trigger: The connection block specifies target_platform with a typo or unsupported value such as "linux", "Win", "unix64", or "macos".
Common situations: Typo in the target_platform attribute, confusion between OS name and platform identifier (e.g. using 'linux' instead of 'unix'), or copy-paste from documentation using the wrong value.
Related errors
- host for provisioner cannot be empty
- default workspace not supported You can create a new workspa
- the secret name %v is invalid, {validationErrors} This is a
- One of `access_key`, `sas_token`, `use_azuread_auth` and `re
- `resource_group_name` is required when `lookup_blob_endpoint
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/a66426e01ee17fba.
Report an issue: GitHub.