From 80319c123876064df40235eb21ab9ddd2d5a241a Mon Sep 17 00:00:00 2001 From: Dan Peebles Date: Wed, 30 Aug 2017 12:25:34 -0400 Subject: [PATCH] terraform: manage 0.10 plugins with Nix Also add a few starter plugins/providers --- .../networking/cluster/terraform/default.nix | 38 +++++++++++++++++-- .../cluster/terraform/provider-path.patch | 16 ++++++++ .../cluster/terraform/providers/aws.nix | 16 ++++++++ .../cluster/terraform/providers/azurerm.nix | 16 ++++++++ .../cluster/terraform/providers/google.nix | 16 ++++++++ .../terraform/providers/kubernetes.nix | 16 ++++++++ 6 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 pkgs/applications/networking/cluster/terraform/provider-path.patch create mode 100644 pkgs/applications/networking/cluster/terraform/providers/aws.nix create mode 100644 pkgs/applications/networking/cluster/terraform/providers/azurerm.nix create mode 100644 pkgs/applications/networking/cluster/terraform/providers/google.nix create mode 100644 pkgs/applications/networking/cluster/terraform/providers/kubernetes.nix diff --git a/pkgs/applications/networking/cluster/terraform/default.nix b/pkgs/applications/networking/cluster/terraform/default.nix index 8fd76f7df75..efff9282bd3 100644 --- a/pkgs/applications/networking/cluster/terraform/default.nix +++ b/pkgs/applications/networking/cluster/terraform/default.nix @@ -1,4 +1,4 @@ -{ stdenv, lib, buildGoPackage, fetchpatch, fetchFromGitHub }: +{ stdenv, lib, buildEnv, buildGoPackage, fetchpatch, fetchFromGitHub, makeWrapper }: let goPackagePath = "github.com/hashicorp/terraform"; @@ -37,6 +37,36 @@ let maintainers = with maintainers; [ jgeerds zimbatm peterhoeg ]; }; } // attrs'); + + pluggable = terraform: + let + withPlugins = plugins: stdenv.mkDerivation { + name = "${terraform.name}-with-plugins"; + buildInputs = [ makeWrapper ]; + + buildCommand = '' + mkdir -p $out/bin/ + makeWrapper "${terraform.bin}/bin/terraform" "$out/bin/terraform" \ + --set NIX_TERRAFORM_PLUGIN_DIR "${buildEnv { name = "tf-plugin-env"; paths = plugins terraform.plugins; }}/bin" + ''; + + passthru = { + withPlugins = newplugins: withPlugins (x: newplugins x ++ plugins x); + + # Ouch + overrideDerivation = f: (pluggable (terraform.overrideDerivation f)).withPlugins plugins; + overrideAttrs = f: (pluggable (terraform.overrideAttrs f)).withPlugins plugins; + override = x: (pluggable (terraform.override x)).withPlugins plugins; + }; + }; + in withPlugins (_: []); + + plugins = { + aws = import providers/aws.nix { inherit stdenv lib buildGoPackage fetchFromGitHub; }; + azurerm = import providers/azurerm.nix { inherit stdenv lib buildGoPackage fetchFromGitHub; }; + google = import providers/google.nix { inherit stdenv lib buildGoPackage fetchFromGitHub; }; + kubernetes = import providers/kubernetes.nix { inherit stdenv lib buildGoPackage fetchFromGitHub; }; + }; in { terraform_0_8_5 = generic { version = "0.8.5"; @@ -55,8 +85,10 @@ in { doCheck = false; }; - terraform_0_10 = generic { + terraform_0_10 = pluggable (generic { version = "0.10.2"; sha256 = "1q7za7jcfqv914a3ynfl7hrqbgwcahgm418kivjrac6p1q26w502"; - }; + patches = [ ./provider-path.patch ]; + passthru = { inherit plugins; }; + }); } diff --git a/pkgs/applications/networking/cluster/terraform/provider-path.patch b/pkgs/applications/networking/cluster/terraform/provider-path.patch new file mode 100644 index 00000000000..39a69e4a389 --- /dev/null +++ b/pkgs/applications/networking/cluster/terraform/provider-path.patch @@ -0,0 +1,16 @@ +diff --git a/command/init.go b/command/init.go +index 403ca245b..05d98329a 100644 +--- a/command/init.go ++++ b/command/init.go +@@ -64,6 +64,11 @@ func (c *InitCommand) Run(args []string) int { + return 1 + } + ++ val, ok := os.LookupEnv("NIX_TERRAFORM_PLUGIN_DIR") ++ if ok { ++ flagPluginPath = append(flagPluginPath, val) ++ } ++ + if len(flagPluginPath) > 0 { + c.pluginPath = flagPluginPath + c.getPlugins = false diff --git a/pkgs/applications/networking/cluster/terraform/providers/aws.nix b/pkgs/applications/networking/cluster/terraform/providers/aws.nix new file mode 100644 index 00000000000..744c13df329 --- /dev/null +++ b/pkgs/applications/networking/cluster/terraform/providers/aws.nix @@ -0,0 +1,16 @@ +{ stdenv, lib, buildGoPackage, fetchFromGitHub }: + +buildGoPackage rec { + pname = "terraform-provider-aws"; + name = "${pname}-${version}"; + version = "0.1.4"; + + goPackagePath = "github.com/terraform-providers/terraform-provider-aws"; + + src = fetchFromGitHub { + owner = "terraform-providers"; + repo = pname; + rev = "v${version}"; + sha256 = "0hqyvp1bgyfqq2lkjq5m5qxybagnxl9zrqiqfnlrfigdp0y31iz8"; + }; +} \ No newline at end of file diff --git a/pkgs/applications/networking/cluster/terraform/providers/azurerm.nix b/pkgs/applications/networking/cluster/terraform/providers/azurerm.nix new file mode 100644 index 00000000000..e6907d1b2aa --- /dev/null +++ b/pkgs/applications/networking/cluster/terraform/providers/azurerm.nix @@ -0,0 +1,16 @@ +{ stdenv, lib, buildGoPackage, fetchFromGitHub }: + +buildGoPackage rec { + pname = "terraform-provider-azurerm"; + name = "${pname}-${version}"; + version = "0.1.5"; + + goPackagePath = "github.com/terraform-providers/terraform-provider-azurerm"; + + src = fetchFromGitHub { + owner = "terraform-providers"; + repo = pname; + rev = "v${version}"; + sha256 = "02g8wnzwaii24nx5iin1yd4bx0rx22ly8aqhwa39mr5hsjj1qy4k"; + }; +} \ No newline at end of file diff --git a/pkgs/applications/networking/cluster/terraform/providers/google.nix b/pkgs/applications/networking/cluster/terraform/providers/google.nix new file mode 100644 index 00000000000..0f8ad21bb13 --- /dev/null +++ b/pkgs/applications/networking/cluster/terraform/providers/google.nix @@ -0,0 +1,16 @@ +{ stdenv, lib, buildGoPackage, fetchFromGitHub }: + +buildGoPackage rec { + pname = "terraform-provider-google"; + name = "${pname}-${version}"; + version = "0.1.3"; + + goPackagePath = "github.com/terraform-providers/terraform-provider-google"; + + src = fetchFromGitHub { + owner = "terraform-providers"; + repo = pname; + rev = "v${version}"; + sha256 = "1aa1hz0yc4g746m6dl04hc70rcrzx0py8kpdch3kim475bspclnf"; + }; +} \ No newline at end of file diff --git a/pkgs/applications/networking/cluster/terraform/providers/kubernetes.nix b/pkgs/applications/networking/cluster/terraform/providers/kubernetes.nix new file mode 100644 index 00000000000..6a8bc8902b6 --- /dev/null +++ b/pkgs/applications/networking/cluster/terraform/providers/kubernetes.nix @@ -0,0 +1,16 @@ +{ stdenv, lib, buildGoPackage, fetchFromGitHub }: + +buildGoPackage rec { + pname = "terraform-provider-kubernetes"; + name = "${pname}-${version}"; + version = "1.0.0"; + + goPackagePath = "github.com/terraform-providers/terraform-provider-kubernetes"; + + src = fetchFromGitHub { + owner = "terraform-providers"; + repo = pname; + rev = "v${version}"; + sha256 = "1kh7a83f98v6b4v3zj84ddhrg2hya4nmvrw0mjc26q12g4z2d5g6"; + }; +} \ No newline at end of file