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 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/terranix/terranix.git";
    rev = "2.3.0";
    sha256 = "030067h3gjc02llaa7rx5iml0ikvw6szadm0nrss2sqzshsfimm4";
  }) { };

  terraform = pkgs.writers.writeBashBin "terraform" ''
    export TF_VAR_hcloud_api_token=${hcloud_api_token}
    ${pkgs.terraform_0_12}/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

See also

about terranix and terraform

You are new to terraform, but you are fit in nix? This is the place for you to start.

Differences between terranix and HCL

Syntax differences between terranix and HCL

Modules

The NixOS module system the real power behind terranix.