Getting Started

Let’s have a quick overview on how you would use Terranix.

If you search for working examples have a look at the examples folder at github.

How to Setup

A convenient way is to create a shell.nix which holds you terranix and terraform setup.

{ pkgs ? import <nixpkgs> { } }:
let

  hcloud_api_token = "`${pkgs.pass}/bin/pass development/hetzner.com/api-token`";

  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=${hcloud_api_token}
    ${pkgs.terraform_0_11}/bin/terraform "$@"
  '';

in pkgs.mkShell {
  buildInputs = [ terranix terraform ];
}

config.nix

create a config.nix for example

{ ... }:
{
  resource.hcloud_server.nginx = {
    name = "terranix.nginx";
    image  = "debian-10";
    server_type = "cx11";
    backups = false;
  };
  resource.hcloud_server.test = {
    name = "terranix.test";
    image  = "debian-9";
    server_type = "cx11";
    backups = true;
  };
}

Create a Server

Next lets generate a json file in terraform json format and run terraform apply to let terraform do it’s magic.

terranix > config.tf.json && terraform init && terraform apply

Destroy a Server

cleaning everything up is the job of terraform, just run :

terraform destroy

Links