Skip to content

Commit

Permalink
feat: Initial support for Terraform 1.9 versions (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
sestrella authored Aug 7, 2024
1 parent 034287e commit 8939196
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ jobs:
run: |
if grep -q authToken ~/.config/cachix/cachix.dhall; then
echo "Cachix token is present"
cachix watch-exec nixpkgs-terraform nix -- flake check
cachix watch-exec nixpkgs-terraform nix -- flake check --max-jobs 2
else
echo "Cachix token is not present"
nix flake check
nix flake check --max-jobs 2
fi
template:
Expand Down
59 changes: 35 additions & 24 deletions flake.lock

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

22 changes: 15 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
inputs = {
config.url = "github:stackbuilders/nixpkgs-terraform?dir=templates/config";
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs-1_0.url = "github:nixos/nixpkgs/41de143fda10e33be0f47eab2bfe08a50f234267"; # nixos-23.05
nixpkgs-1_6.url = "github:nixos/nixpkgs/d6b3ddd253c578a7ab98f8011e59990f21dc3932"; # nixos-24.05
nixpkgs-1_9.url = "github:nixos/nixpkgs/f5fd8730397b9951d24de58f51a5e9cb327e2a85"; # nixpkgs-unstable
systems.url = "github:nix-systems/default";
};

Expand All @@ -18,13 +19,20 @@

systems = import inputs.systems;

perSystem = { config, pkgs, pkgs-unstable, system, ... }:
perSystem = { config, pkgs-1_0, pkgs-1_6, pkgs-1_9, system, ... }:
let
flakeConfig = import inputs.config;
in
{
_module.args = {
pkgs-unstable = import inputs.nixpkgs-unstable {
pkgs-1_0 = import inputs.nixpkgs-1_0 {
inherit system;
};
pkgs-1_6 = import inputs.nixpkgs-1_6 {
inherit system;
config = flakeConfig.nixpkgs-unstable;
};
pkgs-1_9 = import inputs.nixpkgs-1_9 {
inherit system;
config = flakeConfig.nixpkgs-unstable;
};
Expand All @@ -41,11 +49,11 @@
versionLessThan1_6 = version: builtins.compareVersions version "1.6.0" < 0;
in
{
releases = pkgs.lib.filterAttrs (version: _: allowUnfree || versionLessThan1_6 version) versions.releases;
latest = pkgs.lib.filterAttrs (_: version: allowUnfree || versionLessThan1_6 version) versions.latest;
releases = pkgs-1_9.lib.filterAttrs (version: _: allowUnfree || versionLessThan1_6 version) versions.releases;
latest = pkgs-1_9.lib.filterAttrs (_: version: allowUnfree || versionLessThan1_6 version) versions.latest;
};
releases = import ./lib/releases.nix {
inherit pkgs pkgs-unstable; custom-lib = self.lib;
inherit pkgs-1_0 pkgs-1_6 pkgs-1_9; custom-lib = self.lib;
releases = filteredVersions.releases;
silenceWarnings = flakeConfig.nixpkgs-terraform.silenceWarnings;
};
Expand Down
16 changes: 11 additions & 5 deletions lib/build-terraform.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
{ pkgs, pkgs-unstable, version, hash, vendorHash, silenceWarnings ? false }:
{ pkgs-1_0, pkgs-1_6, pkgs-1_9, version, hash, vendorHash, silenceWarnings ? false }:
# https://www.hashicorp.com/blog/hashicorp-adopts-business-source-license
if builtins.compareVersions version "1.6.0" >= 0
if builtins.compareVersions version "1.9.0" >= 0
then
# https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/applications/networking/cluster/terraform/default.nix
(pkgs.lib.warnIf (! silenceWarnings) ("allowUnfree is enabled to build version " + version) pkgs-unstable.mkTerraform
(pkgs-1_9.lib.warnIf (! silenceWarnings) ("allowUnfree is enabled to build version " + version) pkgs-1_9.mkTerraform
{
inherit version hash vendorHash;
patches = [ ../patches/provider-path-1_9.patch ];
})
else if builtins.compareVersions version "1.6.0" >= 0
then
(pkgs-1_6.lib.warnIf (! silenceWarnings) ("allowUnfree is enabled to build version " + version) pkgs-1_6.mkTerraform
{
inherit version hash vendorHash;
patches = [ ../patches/provider-path-0_15.patch ];
})
else
# https://github.com/NixOS/nixpkgs/blob/nixos-23.05/pkgs/applications/networking/cluster/terraform/default.nix
(pkgs.mkTerraform {
(pkgs-1_0.mkTerraform {
inherit version hash vendorHash;
patches = [ ../patches/provider-path-0_15.patch ];
})
4 changes: 2 additions & 2 deletions lib/releases.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ custom-lib, pkgs, pkgs-unstable, releases, silenceWarnings }:
{ custom-lib, pkgs-1_0, pkgs-1_6, pkgs-1_9, releases, silenceWarnings }:
builtins.mapAttrs
(version: { hash, vendorHash }: custom-lib.buildTerraform {
inherit pkgs pkgs-unstable version hash vendorHash silenceWarnings;
inherit pkgs-1_0 pkgs-1_6 pkgs-1_9 version hash vendorHash silenceWarnings;
})
releases
23 changes: 23 additions & 0 deletions patches/provider-path-1_9.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
diff -Naur terraform.old/internal/command/init.go terraform.new/internal/command/init.go
--- terraform.old/internal/command/init.go
+++ terraform.new/internal/command/init.go
@@ -7,6 +7,7 @@
"context"
"errors"
"fmt"
+ "os"
"log"
"reflect"
"sort"
@@ -77,6 +78,11 @@
// -force-copy implies -migrate-state
if c.forceInitCopy {
c.migrateState = true
+ }
+
+ val, ok := os.LookupEnv("NIX_TERRAFORM_PLUGIN_DIR")
+ if ok {
+ initArgs.PluginPath = append(initArgs.PluginPath, val)
}

if len(initArgs.PluginPath) > 0 {
15 changes: 14 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@
"1.8.5": {
"hash": "sha256-5PzP0LUJPpOQQ8YqwBFyEFcsHF2O1uDD8Yh8wB3uJ8s=",
"vendorHash": "sha256-PXA2AWq1IFmnqhhU92S9UaIYTUAAn5lsg3S7h5hBOQE="
},
"1.9.0": {
"hash": "sha256-mxnRQkwUcWCYmk4QUbAb5UKs9zXrW0qlvPLkVidaeUs=",
"vendorHash": "sha256-pKez3etNpwPU/pRjIzsVBXRjtqLYjnoYghBqFYYDfPU="
},
"1.9.1": {
"hash": "sha256-WqcrjKzaJShEFyHeZD4N9pPG2G2tDicQ4e05rt40o00=",
"vendorHash": "sha256-cPWJtrGad8VsvyjJHQwpfDitsJY/Q0iCtp1MRyzGT+U="
},
"1.9.2": {
"hash": "sha256-g1CsDWjwjBVfSNFZ9PRGlPlJOrqXP2eMYk1P+ohtYNU=",
"vendorHash": "sha256-cPWJtrGad8VsvyjJHQwpfDitsJY/Q0iCtp1MRyzGT+U="
}
},
"latest": {
Expand All @@ -322,6 +334,7 @@
"1.5": "1.5.7",
"1.6": "1.6.6",
"1.7": "1.7.5",
"1.8": "1.8.5"
"1.8": "1.8.5",
"1.9": "1.9.2"
}
}

0 comments on commit 8939196

Please sign in to comment.