{"record":{"id":"a945ac605cfc48b2","repo":"hashicorp/terraform","slug":"host-for-provisioner-cannot-be-empty","errorCode":null,"errorMessage":"host for provisioner cannot be empty","messagePattern":"host for provisioner cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/communicator/ssh/provisioner.go","lineNumber":189,"sourceCode":"\n\t// To default Agent to true, we need to check the raw string, since the\n\t// decoded boolean can't represent \"absence of config\".\n\t//\n\t// And if SSH_AUTH_SOCK is not set, there's no agent to connect to, so we\n\t// shouldn't try.\n\tagent := v.GetAttr(\"agent\")\n\tif agent.IsNull() && os.Getenv(\"SSH_AUTH_SOCK\") != \"\" {\n\t\tconnInfo.Agent = true\n\t}\n\n\tif connInfo.User == \"\" {\n\t\tconnInfo.User = DefaultUser\n\t}\n\n\t// Check if host is empty.\n\t// Otherwise return error.\n\tif connInfo.Host == \"\" {\n\t\treturn nil, fmt.Errorf(\"host for provisioner cannot be empty\")\n\t}\n\n\t// Format the host if needed.\n\t// Needed for IPv6 support.\n\tconnInfo.Host = shared.IpFormat(connInfo.Host)\n\n\tif connInfo.Port == 0 {\n\t\tconnInfo.Port = DefaultPort\n\t}\n\t// Set default targetPlatform to unix if it's empty\n\tif connInfo.TargetPlatform == \"\" {\n\t\tconnInfo.TargetPlatform = TargetPlatformUnix\n\t} else if connInfo.TargetPlatform != TargetPlatformUnix && connInfo.TargetPlatform != TargetPlatformWindows {\n\t\treturn nil, fmt.Errorf(\"target_platform for provisioner has to be either %s or %s\", TargetPlatformUnix, TargetPlatformWindows)\n\t}\n\t// Choose an appropriate default script path based on the target platform. There is no single\n\t// suitable default script path which works on both UNIX and Windows targets.\n\tif connInfo.ScriptPath == \"\" && connInfo.TargetPlatform == TargetPlatformUnix {","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/hashicorp/terraform/blob/c9def3e214014c1188faabfc4a5bde5095139765/internal/communicator/ssh/provisioner.go#L171-L207","documentation":"Raised in parseConnectionInfo when the 'host' attribute of the SSH connection block is empty. The host is the remote target address and is strictly required; without it the communicator cannot dial anywhere. This is a configuration-validation error returned before any network activity.","triggerScenarios":"The connection block's host attribute resolves to an empty string, either because it was omitted entirely or because the variable/resource attribute it references is null or empty at plan/apply time.","commonSituations":"host references a resource attribute that is not yet known or is null (e.g. aws_instance.example.public_ip when the instance has no public IP), the connection block omits host entirely, or a variable defaulting to empty string is used.","solutions":["Set a non-empty host in the connection block, either as a literal or a valid resource attribute.","If referencing a resource attribute, ensure that attribute is known and non-empty at the time the provisioner runs (e.g. use public_ip or public_dns only when the instance has one).","For instances without public IPs, use a bastion_host or set host to a private IP reachable from the runner."],"exampleFix":"// before\nconnection {\n  type = \"ssh\"\n  user = \"root\"\n  # host missing\n}\n\n// after\nconnection {\n  type = \"ssh\"\n  host = aws_instance.web.public_ip\n  user = \"root\"\n}","handlingStrategy":"validation","validationCode":"// Validate host is non-empty before constructing the communicator\nfunc validateConnectionHost(host string) error {\n    if strings.TrimSpace(host) == \"\" {\n        return errors.New(\"host for provisioner cannot be empty\")\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set host in the connection block to a known, non-empty value.","When referencing resource attributes (e.g. public_ip), ensure they are known and non-null at provision time.","For instances without public IPs, use a bastion or set host to a private IP."],"tags":["configuration","validation","host","connection-block","terraform"],"analyzedSha":"c9def3e214014c1188faabfc4a5bde5095139765","analyzedAt":"2026-08-07T15:39:49.278Z","schemaVersion":2},"datasetVersion":"2026-08-07T21:17:07.882Z"}