2018-09-28 16:02:51 +01:00
|
|
|
{ stdenv
|
|
|
|
, lib
|
|
|
|
, buildEnv
|
|
|
|
, buildGoPackage
|
|
|
|
, fetchFromGitHub
|
|
|
|
, makeWrapper
|
2018-10-04 21:41:19 +01:00
|
|
|
, runCommand
|
|
|
|
, writeText
|
2018-09-28 16:02:51 +01:00
|
|
|
, terraform-providers
|
|
|
|
}:
|
2016-06-05 10:16:58 +01:00
|
|
|
|
2017-03-17 09:05:16 +00:00
|
|
|
let
|
2017-03-31 12:19:22 +01:00
|
|
|
goPackagePath = "github.com/hashicorp/terraform";
|
|
|
|
|
|
|
|
generic = { version, sha256, ... }@attrs:
|
|
|
|
let attrs' = builtins.removeAttrs attrs ["version" "sha256"]; in
|
|
|
|
buildGoPackage ({
|
|
|
|
name = "terraform-${version}";
|
|
|
|
|
|
|
|
inherit goPackagePath;
|
|
|
|
|
|
|
|
src = fetchFromGitHub {
|
|
|
|
owner = "hashicorp";
|
|
|
|
repo = "terraform";
|
|
|
|
rev = "v${version}";
|
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
# remove all plugins, they are part of the main binary now
|
|
|
|
for i in $bin/bin/*; do
|
|
|
|
if [[ $(basename $i) != terraform ]]; then
|
|
|
|
rm "$i"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
'';
|
2017-03-17 09:05:16 +00:00
|
|
|
|
2017-03-31 12:19:22 +01:00
|
|
|
preCheck = ''
|
|
|
|
export HOME=$TMP
|
|
|
|
'';
|
|
|
|
|
|
|
|
meta = with stdenv.lib; {
|
|
|
|
description = "Tool for building, changing, and versioning infrastructure";
|
|
|
|
homepage = https://www.terraform.io/;
|
|
|
|
license = licenses.mpl20;
|
2018-09-26 21:11:18 +01:00
|
|
|
maintainers = with maintainers; [ jgeerds zimbatm peterhoeg kalbasit ];
|
2017-03-31 12:19:22 +01:00
|
|
|
};
|
|
|
|
} // attrs');
|
2017-08-30 17:25:34 +01:00
|
|
|
|
|
|
|
pluggable = terraform:
|
|
|
|
let
|
2017-08-30 23:53:14 +01:00
|
|
|
withPlugins = plugins:
|
|
|
|
let
|
|
|
|
actualPlugins = plugins terraform.plugins;
|
2017-08-30 17:25:34 +01:00
|
|
|
|
2018-03-28 01:25:23 +01:00
|
|
|
# Wrap PATH of plugins propagatedBuildInputs, plugins may have runtime dependencies on external binaries
|
|
|
|
wrapperInputs = lib.unique (lib.flatten (lib.catAttrs "propagatedBuildInputs" (builtins.filter (x: x != null) actualPlugins)));
|
|
|
|
|
2017-08-30 23:53:14 +01:00
|
|
|
passthru = {
|
|
|
|
withPlugins = newplugins: withPlugins (x: newplugins x ++ actualPlugins);
|
2018-11-19 20:03:44 +00:00
|
|
|
full = withPlugins lib.attrValues;
|
2017-08-30 17:25:34 +01:00
|
|
|
|
2017-08-30 23:53:14 +01:00
|
|
|
# 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
|
|
|
|
# Don't bother wrapping unless we actually have plugins, since the wrapper will stop automatic downloading
|
|
|
|
# of plugins, which might be counterintuitive if someone just wants a vanilla Terraform.
|
|
|
|
if actualPlugins == []
|
|
|
|
then terraform.overrideAttrs (orig: { passthru = orig.passthru // passthru; })
|
2018-07-19 22:58:25 +01:00
|
|
|
else lib.appendToName "with-plugins"(stdenv.mkDerivation {
|
2018-05-25 10:21:47 +01:00
|
|
|
inherit (terraform) name;
|
2017-08-30 23:53:14 +01:00
|
|
|
buildInputs = [ makeWrapper ];
|
2017-08-30 17:25:34 +01:00
|
|
|
|
2017-08-30 23:53:14 +01:00
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out/bin/
|
|
|
|
makeWrapper "${terraform.bin}/bin/terraform" "$out/bin/terraform" \
|
2018-03-28 01:25:23 +01:00
|
|
|
--set NIX_TERRAFORM_PLUGIN_DIR "${buildEnv { name = "tf-plugin-env"; paths = actualPlugins; }}/bin" \
|
|
|
|
--prefix PATH : "${lib.makeBinPath wrapperInputs}"
|
2017-08-30 23:53:14 +01:00
|
|
|
'';
|
|
|
|
|
|
|
|
inherit passthru;
|
2018-05-25 10:21:47 +01:00
|
|
|
});
|
2017-08-30 17:25:34 +01:00
|
|
|
in withPlugins (_: []);
|
|
|
|
|
2018-09-28 16:02:51 +01:00
|
|
|
plugins = removeAttrs terraform-providers ["override" "overrideDerivation" "recurseForDerivations"];
|
2018-01-10 09:47:52 +00:00
|
|
|
in rec {
|
2017-11-22 21:06:02 +00:00
|
|
|
terraform_0_11 = pluggable (generic {
|
2018-11-02 23:52:12 +00:00
|
|
|
version = "0.11.10";
|
|
|
|
sha256 = "08mapla89g106bvqr41zfd7l4ki55by6207qlxq9caiha54nx4nb";
|
2017-11-22 21:06:02 +00:00
|
|
|
patches = [ ./provider-path.patch ];
|
|
|
|
passthru = { inherit plugins; };
|
|
|
|
});
|
2018-01-10 09:47:52 +00:00
|
|
|
|
2018-11-19 20:03:44 +00:00
|
|
|
terraform_0_11-full = terraform_0_11.full;
|
2018-10-04 21:41:19 +01:00
|
|
|
|
2018-11-19 20:18:13 +00:00
|
|
|
terraform_0_12 = pluggable (generic {
|
|
|
|
version = "0.12.0-alpha2";
|
|
|
|
sha256 = "1rnxgwfk10b1g3jnh9gv4lqrcszhxq8shaqslml30hafs3dkg71q";
|
|
|
|
patches = [ ./provider-path.patch ];
|
|
|
|
passthru = { inherit plugins; };
|
|
|
|
});
|
|
|
|
|
2018-10-04 21:41:19 +01:00
|
|
|
# Tests that the plugins are being used. Terraform looks at the specific
|
|
|
|
# file pattern and if the plugin is not found it will try to download it
|
|
|
|
# from the Internet. With sandboxing enable this test will fail if that is
|
|
|
|
# the case.
|
|
|
|
terraform_plugins_test = let
|
|
|
|
mainTf = writeText "main.tf" ''
|
|
|
|
resource "random_id" "test" {}
|
|
|
|
'';
|
|
|
|
terraform = terraform_0_11.withPlugins (p: [ p.random ]);
|
|
|
|
test = runCommand "terraform-plugin-test" { buildInputs = [terraform]; }
|
|
|
|
''
|
|
|
|
set -e
|
|
|
|
# make it fail outside of sandbox
|
|
|
|
export HTTP_PROXY=http://127.0.0.1:0 HTTPS_PROXY=https://127.0.0.1:0
|
|
|
|
cp ${mainTf} main.tf
|
|
|
|
terraform init
|
|
|
|
touch $out
|
|
|
|
'';
|
|
|
|
in test;
|
|
|
|
|
2016-06-05 10:16:58 +01:00
|
|
|
}
|