def install_latest_terraform()

in TerraformScripts/sc_terraform_wrapper/terraform_installer.py [0:0]


def install_latest_terraform():
    args = parse_args()

    if args.version is None:
        checkpoint_response = requests.get('https://checkpoint-api.hashicorp.com/v1/check/terraform')
        checkpoint_response.raise_for_status()
        checkpoint = checkpoint_response.json()
        current_version = checkpoint['current_version']
    else:
        current_version = args.version
    download_url = "https://releases.hashicorp.com/terraform/{0}/terraform_{0}_linux_amd64.zip".format(current_version)

    terraform_response = requests.get(download_url)
    terraform_response.raise_for_status()
    terraform_zip_bytes = io.BytesIO(terraform_response.content)
    terraform_zip = zipfile.ZipFile(terraform_zip_bytes)

    terraform_zip.extract('terraform', '/usr/local/bin')
    os.chmod('/usr/local/bin/terraform', stat.S_IEXEC)