Differences between terranix and HCL

HCL is the language of terraform. It is has it’s flaws, this is why terranix was born.


In HCL you would do something like this:

resource "aws_instance" "web" {
  ami           = "${data.aws_ami.ubuntu.id}"
  instance_type = "t2.micro"
  tags = {
    Name = "HelloWorld"

Which is the equivalent for the following in terranix:

resource."aws_instance"."web" = {
  ami = "\${data.aws_ami.ubuntu.id}";
  instance_type = "t2.micro";
  tags = {
    Name = "HelloWorld";


In HCL you can only reference variable outputs. But in terranix, because it is nix, you can basically reference everything.

For example if you have a resource and you want to reuse its parameters:

resoure.hcloud_server.myserver = {
  name = "node1";
  image = "debian-9";
  server_type = "cx11";

You can reference parameters the terraform way, because they are resource outputs:

resoure.hcloud_server.myotherserver = {
  name = "node2";
  image = "\${ hcloud_server.myserver.image }";
  server_type = "\${ hcloud_server.myserver.server_type }";

Or the terranix way:

resoure.hcloud_server.myotherotherserver = {
  name = "node3";
  image = config.resource.hcloud_server.myserver.image;
  server_type = config.resource.hcloud_server.myserver.server_type;

Or the terranix pro way:

resoure.hcloud_server.myotherotherotherserver = {
  name = "node4";
  inherit (config.resource.hlcoud_server) image server_type;

The difference is that terranix and terraform references are evaluated differently. terranix references are evaluated when generating the json file, and terraform references are calculated during the process.

multi line sings

In terraform you can create multi line strings using the herdoc style

variable "multiline" {
  description = <<EOT
Description for the multi line variable.
The indention here is not wrong.
The terminating word must be on a new line without any indention.

This won’t work in terranix. In terranix you have to use the nix way of multi line strings.

variable.multiline.description = ''
  Description for the multi line variable.
  The indention here is not wrong.
  All spaces in front of the text block will be removed by terranix.

escaping expressions

The form ${expression} is used by terranix and terraform. So if you want to use a terraform expression in terranix, you have to escape it. Escaping differs for multi and singe line strings.

escaping in single line strings

In a single line strings, you escape via \${expression}. For example :

variable.hcloud_token = {};
provider.hcloud.token = "\${ var.hcloud_token }";

escaping in multi line strings

In multi line strings, you escape via ''${expression}. For example :

resource.local_file.sshConfig = {
  filename = "./ssh-config";
  content = ''
    Host ''${ hcloud_server.terranix_test.ipv4_address }
    IdentityFile ./sshkey

See also


Some terranix functions which are useful including examples.


The NixOS module system the real power behind terranix.

Getting Started

You know nix and terraform and want to see how to terranix works? This the place to start.