import socket


def fqdn_to_ip(hostname):
    """Provides the IP address of a resolvable name on the machine it is running from.

       There are many reasons that a valid FQDN may not be resolvable, such as a network error
       from your machine to the DNS server, an upstream DNS issue, etc.

    Args:
        hostname (str): An FQDN that may or may not be resolvable.

    Returns:
        ip (str): The IP Address of a valid FQDN.

    Example:
        >>> from netutils.dns import fqdn_to_ip
        >>> from netutils.ip import is_ip
        >>> is_ip(fqdn_to_ip("google.com"))
        True
        >>>

    Raises:
        socket.gaierror: If FQDN is not resolvable, leverage is_fqdn_resolvable to check first.
    """
    # The data structure is complex, only require the first item, and drill down from there.
    return socket.getaddrinfo(hostname, 0)[0][4][0]