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.

If you don’t know what NixOS or Terraform is, have a look at what terranix is.

How to Set up

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`";
  
  terraform = pkgs.writers.writeBashBin "terraform" ''
    export TF_VAR_hcloud_api_token=${hcloud_api_token}
    ${pkgs.terraform_0_15}/bin/terraform "$@"
  '';

in pkgs.mkShell {
  buildInputs = [ pkgs.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