46 lines
1.2 KiB
Nix
46 lines
1.2 KiB
Nix
{ pkgs ? import <nixpkgs> { } }:
|
|
let
|
|
|
|
terranix = pkgs.callPackage (pkgs.fetchgit {
|
|
url = "https://github.com/mrVanDalo/terranix.git";
|
|
rev = "dfbf4d1fae08da8052ff880c5d02b2eb5857d54c";
|
|
sha256 = "1qilbvldlq7ybxa3yx99hb8vbmj0sk5x9qqxa4f1czpzj2mja0fn";
|
|
}) { };
|
|
|
|
terraform = pkgs.writers.writeBashBin "terraform" ''
|
|
export TF_VAR_hcloud_api_token=`${pkgs.pass}/bin/pass development/hetzner.com/api-token`
|
|
${pkgs.terraform_0_12}/bin/terraform "$@"
|
|
'';
|
|
|
|
in pkgs.mkShell {
|
|
|
|
buildInputs = [
|
|
|
|
terranix
|
|
terraform
|
|
|
|
(pkgs.writers.writeBashBin "prepare" ''
|
|
set -e
|
|
set -o pipefail
|
|
${pkgs.openssh}/bin/ssh-keygen -P "" -f ${toString ./.}/sshkey
|
|
'')
|
|
|
|
(pkgs.writers.writeBashBin "build" ''
|
|
set -e
|
|
set -o pipefail
|
|
${terranix}/bin/terranix | ${pkgs.jq}/bin/jq '.' > config.tf.json
|
|
${terraform}/bin/terraform init
|
|
${terraform}/bin/terraform apply
|
|
'')
|
|
|
|
(pkgs.writers.writeBashBin "cleanup" ''
|
|
${terraform}/bin/terraform destroy
|
|
rm ${toString ./.}/config.tf.json
|
|
rm ${toString ./.}/sshkey
|
|
rm ${toString ./.}/sshkey.pub
|
|
rm ${toString ./.}/terraform.tfstate*
|
|
'')
|
|
|
|
];
|
|
|
|
}
|