Skip to content

Commit

Permalink
feat: Support Terraform 1.4 versions (#33)
Browse files Browse the repository at this point in the history
* Revert "Use EOL data to curate the list of supported versions (#29)"

This reverts commit 733e252.

* Revert "Add missing description"

This reverts commit 3637dcd.

* Revert "feat: Drop support for Terraform 1.5 versions (#26)"

This reverts commit 869f7d3.

* Add description back in

* Support Terraform 1.4

* Update templates

* Update supported range in readme
  • Loading branch information
oscar-izval authored Feb 6, 2024
1 parent 733e252 commit a451b0c
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 31 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ This flake provides a set of Terraform versions in the form of:
nixpkgs-terraform.packages.${system}.${version}
```

Supported Terraform versions ([endoflife.date/terraform](https://endoflife.date/terraform))
are kept up to date via a weekly scheduled [CI workflow](.github/workflows/update.yml).
Terraform versions `>= 1.4.0` are kept up to date via a weekly scheduled [CI
workflow](.github/workflows/update.yml).

## Install

Expand Down
25 changes: 21 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 19 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,30 @@
inputs = {
flake-utils.inputs.systems.follows = "systems";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
systems.url = "github:nix-systems/default";
};

outputs = { self, flake-utils, nixpkgs, ... }:
outputs = { self, flake-utils, nixpkgs-unstable, nixpkgs, ... }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
versions = builtins.fromJSON (builtins.readFile ./versions.json);
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.black
(pkgs.python3.withPackages
pkgs-unstable.black
(pkgs-unstable.python3.withPackages
(ps: [
ps.pygithub
ps.semver
])
)
pkgs.nix-prefetch
pkgs-unstable.nix-prefetch
pkgs.nodejs
pkgs.rubyPackages.dotenv
];
Expand All @@ -41,10 +43,20 @@
lib.buildTerraform = { system, version, hash, vendorHash }:
let
pkgs = nixpkgs.legacyPackages.${system};
pkgs-unstable = nixpkgs-unstable.legacyPackages.${system};
in
# https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license
if builtins.compareVersions version "1.6.0" >= 0
then
# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/applications/networking/cluster/terraform/default.nix
pkgs.mkTerraform
{
pkgs-unstable.mkTerraform
{
inherit version hash vendorHash;
patches = [ "${nixpkgs-unstable}/pkgs/applications/networking/cluster/terraform/provider-path-0_15.patch" ];
}
else
# https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/networking/cluster/terraform/default.nix
pkgs.mkTerraform {
inherit version hash vendorHash;
patches = [ "${nixpkgs}/pkgs/applications/networking/cluster/terraform/provider-path-0_15.patch" ];
};
Expand Down
2 changes: 1 addition & 1 deletion templates/default/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.7.1";
terraform = nixpkgs-terraform.packages.${system}."1.7.2";
in
{
devShells.default = pkgs.mkShell {
Expand Down
2 changes: 1 addition & 1 deletion templates/devenv/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
terraform = nixpkgs-terraform.packages.${system}."1.7.1";
terraform = nixpkgs-terraform.packages.${system}."1.7.2";
in
{
devShells.default = devenv.lib.mkShell {
Expand Down
20 changes: 5 additions & 15 deletions update-versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,18 @@
import json
import os
import pathlib
import requests
import semver
import subprocess


def get_maintained_cycles():
eol_data = requests.get("https://endoflife.date/api/terraform.json").json()
return [cycle['cycle'] for cycle in eol_data if not cycle['eol']]


def read_versions():
with open("versions.json", "r") as f:
return json.load(f)


def is_stable(release, maintained_cycles):
def is_stable(release):
version = release.tag_name.removeprefix("v")
version_major_minor = '.'.join(version.split('.')[:2])
return version_major_minor in maintained_cycles and not (
return semver.compare(version, "1.4.0") >= 0 and not (
release.draft or release.prerelease
)

Expand Down Expand Up @@ -109,19 +103,15 @@ def nix_prefetch(args):
g = github.Github(auth=auth)
repo = g.get_repo("hashicorp/terraform")
# TODO: Drop "v" prefix first

# Craft list of maintaned releases by filtering the release list with the EOL data
maintained_releases = list(filter(lambda version: is_stable(version, get_maintained_cycles()), repo.get_releases()))

releases = list(filter(is_stable, repo.get_releases()))
current_versions = read_versions()
versions = collections.OrderedDict(
sorted(
functools.reduce(
to_version(args.vendor_hash), maintained_releases, current_versions
to_version(args.vendor_hash), releases, current_versions
).items(),
reverse=True,
)
)
with open("versions.json", "w") as f:
json.dump(versions, f, indent=2)
f.write("\n")
66 changes: 65 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,69 @@
"1.6.0": {
"hash": "sha256-R1phgtGn9hyNqa0wR1zY9uThTJSIj7TuK5ekXx48QP0=",
"vendorHash": "sha256-V7S+IzHfBhIHo0xCvHJ75gOmvVbJd2k8XBdvLG1dcsc="
},
"1.5.7": {
"hash": "sha256-pIhwJfa71/gW7lw/KRFBO4Q5Z5YMcTt3r9kD25k8cqM=",
"vendorHash": "sha256-lQgWNMBf+ioNxzAV7tnTQSIS840XdI9fg9duuwoK+U4="
},
"1.5.6": {
"hash": "sha256-vbV8Tmas7n1o8Q+DG9RrcfdAMa4bJsVg2SsTFH1TJ5M=",
"vendorHash": "sha256-lQgWNMBf+ioNxzAV7tnTQSIS840XdI9fg9duuwoK+U4="
},
"1.5.5": {
"hash": "sha256-SBS3a/CIUdyIUJvc+rANIs+oXCQgfZut8b0517QKq64=",
"vendorHash": "sha256-lQgWNMBf+ioNxzAV7tnTQSIS840XdI9fg9duuwoK+U4="
},
"1.5.4": {
"hash": "sha256-MvN4gSJcPORD0wj6ixc3gUXPISGvAKSJPA6bS/SmDOY=",
"vendorHash": "sha256-lQgWNMBf+ioNxzAV7tnTQSIS840XdI9fg9duuwoK+U4="
},
"1.5.3": {
"hash": "sha256-4TnTYzjy8v5+mcV/JIiMPLCTPSanfmbTGzwlMovwlOo=",
"vendorHash": "sha256-lQgWNMBf+ioNxzAV7tnTQSIS840XdI9fg9duuwoK+U4="
},
"1.5.2": {
"hash": "sha256-Ri2nWLjPPBINXyPIQSbnd1L+t7QLgXiTOgqX8Dk/rXg=",
"vendorHash": "sha256-tfCfJj39VP+P4qhJTpEIAi4XB+6VYtVKkV/bTrtnFA0="
},
"1.5.1": {
"hash": "sha256-dqnJGIoUJP37Z77TR2RBxP94Hx3AZbx90m8z1FoYdw0=",
"vendorHash": "sha256-tfCfJj39VP+P4qhJTpEIAi4XB+6VYtVKkV/bTrtnFA0="
},
"1.5.0": {
"hash": "sha256-QLCmA4u0br9EyQ244VcpLW5GkZm+bhq2/vvxSbYolCY=",
"vendorHash": "sha256-tfCfJj39VP+P4qhJTpEIAi4XB+6VYtVKkV/bTrtnFA0="
},
"1.4.7": {
"hash": "sha256-p+6sNCYdqygbSL4plsWxtcs8GqFq5pyaTxFttBWWqaE=",
"vendorHash": "sha256-OW/aS6aBoHABxfdjDxMJEdHwLuHHtPR2YVW4l0sHPjE="
},
"1.4.6": {
"hash": "sha256-V5sI8xmGASBZrPFtsnnfMEHapjz4BH3hvl0+DGjUSxQ=",
"vendorHash": "sha256-OW/aS6aBoHABxfdjDxMJEdHwLuHHtPR2YVW4l0sHPjE="
},
"1.4.5": {
"hash": "sha256-mnJ9d3UHAZxmz0i7PH0JF5gA3m3nJxM2NyAn0J0L6u8=",
"vendorHash": "sha256-3ZQcWatJlQ6NVoPL/7cKQO6+YCSM3Ld77iLEQK3jBDE="
},
"1.4.4": {
"hash": "sha256-Fg9NDV063gWi9Na144jjkK7E8ysE2GR4IYT6qjTgnqw=",
"vendorHash": "sha256-3ZQcWatJlQ6NVoPL/7cKQO6+YCSM3Ld77iLEQK3jBDE="
},
"1.4.3": {
"hash": "sha256-ycoTJPag5cmCU3VLtVgFFSEHCT0BMrhAbOltV7i+GSI=",
"vendorHash": "sha256-3ZQcWatJlQ6NVoPL/7cKQO6+YCSM3Ld77iLEQK3jBDE="
},
"1.4.2": {
"hash": "sha256-0CxB9VOrRoudJVK96mpuQ6etsI+F2dMh4NQTKQXec9c=",
"vendorHash": "sha256-3ZQcWatJlQ6NVoPL/7cKQO6+YCSM3Ld77iLEQK3jBDE="
},
"1.4.1": {
"hash": "sha256-Tj9j3WGfP851Q7RctW+8Xmz9NbQLE3/QKYHBGvLe1/s=",
"vendorHash": "sha256-xAVgyn8MqwLvY85+neQ8jQYkl/j0RY4fG6qBbiMmIOc="
},
"1.4.0": {
"hash": "sha256-jt+axusOYbJmGJpim8i76Yfb/QgWduUmZMIiIs0CJoA=",
"vendorHash": "sha256-M22VONnPs0vv2L3q/2RjE0+Jna/Kv95xubVNthp5bMc="
}
}
}

0 comments on commit a451b0c

Please sign in to comment.