{"record":{"id":"7fa7e0aef063c122","repo":"hashicorp/terraform","slug":"cannot-quote-scp-command-target-platform-unknown","errorCode":null,"errorMessage":"Cannot quote scp command, target platform unknown: %s","messagePattern":"Cannot quote scp command, target platform unknown: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/communicator/ssh/communicator.go","lineNumber":898,"sourceCode":"\tnet.Conn\n\tBastion *ssh.Client\n}\n\nfunc (c *bastionConn) Close() error {\n\tc.Conn.Close()\n\treturn c.Bastion.Close()\n}\n\nfunc quoteScpCommand(args []string, targetPlatform string) (string, error) {\n\tif targetPlatform == TargetPlatformUnix {\n\t\treturn shquot.POSIXShell(args), nil\n\t}\n\tif targetPlatform == TargetPlatformWindows {\n\t\tcmd, args := shquot.WindowsArgvSplit(args)\n\t\treturn fmt.Sprintf(\"%s %s\", cmd, args), nil\n\t}\n\n\treturn \"\", fmt.Errorf(\"Cannot quote scp command, target platform unknown: %s\", targetPlatform)\n\n}\n","sourceCodeStart":880,"sourceCodeEnd":901,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/communicator/ssh/communicator.go#L880-L901","documentation":"Returned by quoteScpCommand when target_platform is neither TargetPlatformUnix nor TargetPlatformWindows. The function selects shell-quoting rules per platform (POSIX vs Windows ArgvSplit); any other value has no quoting strategy and is rejected before constructing the scp command.","triggerScenarios":"An explicit target_platform value that bypassed parseConnectionInfo's validation (e.g. set programmatically to 'mac', 'linux', or empty-but-not-defaulted through a non-standard path). Normally parseConnectionInfo defaults '' to unix and rejects anything else, so this is a defense-in-depth guard.","commonSituations":"A custom provisioner/communicator wrapper setting TargetPlatform directly; a malformed connectionInfo struct constructed outside parseConnectionInfo; a future code path that adds a platform constant without updating quoteScpCommand.","solutions":["Set target_platform to either \"unix\" or \"windows\" (or omit it for the unix default).","If constructing connectionInfo programmatically, always go through parseConnectionInfo so defaults and validation apply.","Treat this error as a bug if it appears with a standard config — it indicates an internal invariant was violated."],"exampleFix":"// before\nconnection {\n  host            = aws_instance.web.public_ip\n  target_platform = \"linux\"\n}\n\n// after\nconnection {\n  host            = aws_instance.web.public_ip\n  target_platform = \"unix\"\n}","handlingStrategy":"type-guard","validationCode":"# This only fires if an internal invariant is broken; ensure configs use\n# parseConnectionInfo which validates target_platform to unix/windows.\n# In HCL: target_platform = \"unix\" | \"windows\" (or omit).","typeGuard":"// Go guard before quoting if constructing commands outside the helper:\nfunc validTargetPlatform(p string) bool {\n    return p == \"unix\" || p == \"windows\"\n}","tryCatchPattern":null,"preventionTips":["Always set target_platform to 'unix' or 'windows' or omit it.","Construct connectionInfo only through parseConnectionInfo so defaults/validation apply.","Report as a bug if it appears with standard config."],"tags":["terraform","ssh","scp","target-platform","validation","provisioner"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}