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

  1. Set target_platform to exactly 'unix' or 'windows'.
  2. If the attribute is not needed, omit it entirely (it defaults to 'unix').
  3. 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

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


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/a66426e01ee17fba. Report an issue: GitHub.