<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def install(self, version_requested=None):
 """Ensure terraform is available."""

        command_suffix = '.exe' if platform.system() == 'Windows' else ''
        versions_dir = ensure_versions_dir_exists(self.tfenv_dir)

        if not version_requested:
            version_requested = get_version_requested(self.path)

        if re.match(r'^min-required$', version_requested):
            LOGGER.debug('tfenv: detecting minimal required version')
            version_requested = find_min_required(self.path)

        if re.match(r'^latest:.*$', version_requested):
            regex = re.search(r'latest:(.*)', version_requested).group(1)
            include_prerelease_versions = False
        elif re.match(r'^latest$', version_requested):
            regex = r'^[0-9]+\.[0-9]+\.[0-9]+$'
            include_prerelease_versions = False
        else:
            regex = "^%s$" % version_requested
            include_prerelease_versions = True
            # Return early (i.e before reaching out to the internet) if the
            # matching version is already installed
            if os.path.isdir(os.path.join(versions_dir,
                                          version_requested)):
                LOGGER.info("Terraform version %s already installed; using "
                            "it...", version_requested)
                return os.path.join(versions_dir,
                                    version_requested,
                                    'terraform') + command_suffix

        try:
            version = next(i
                           for i in get_available_tf_versions(
                               include_prerelease_versions)
                           if re.match(regex, i))
        except StopIteration:
            LOGGER.error("Unable to find a Terraform version matching regex: %s",
                         regex)
            sys.exit(1)

        # Now that a version has been selected, skip downloading if it's
        # already been downloaded
        if os.path.isdir(os.path.join(versions_dir,
                                      version)):
            LOGGER.info("Terraform version %s already installed; using it...",
                        version)
            return os.path.join(versions_dir,
                                version,
                                'terraform') + command_suffix

        LOGGER.info("Downloading and using Terraform version %s ...",
                    version)
        download_tf_release(version, versions_dir, command_suffix)
        LOGGER.info("Downloaded Terraform %s successfully", version)
        return os.path.join(versions_dir, version, 'terraform') + command_suffix