This conditional can probably be simplified as:

@host || fail "hostname or IP address is invalid for resource"