import urllib.request


def get_instance_metadata(key):
    """Gets instance metadata given a metadata key"""

    GOOGLE_URL = "http://metadata.google.internal/computeMetadata/v1/instance/attributes"
    req = urllib.request.Request("{}/{}".format(GOOGLE_URL, key))
    req.add_header('Metadata-Flavor', 'Google')
    resp = urllib.request.urlopen(req)

    value = resp.read().decode('utf-8').replace('\t','')
    return value