Skip to content

brainrake/nixform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

4a657d0 · Feb 25, 2019

History

34 Commits
Sep 22, 2018
Sep 22, 2018
Sep 10, 2016
Sep 22, 2018
Sep 9, 2016
Sep 10, 2016
Sep 9, 2016
Aug 4, 2018
Aug 4, 2018
Aug 4, 2018

Repository files navigation

Build Status

nixform

define terraform infrastructure in Nix

Terraform by Hashicorp is a great tool with a meh language. Fixed.

Installation

First, install nix. Then,

# install nixform (and deps)
nix-env -i -f "https://github.com/brainrape/nixform/archive/master.tar.gz"

Usage

Create a file like example.tf.nix containing a nix expression that evaluates to a set that looks like terraform's json format:

let
  lib = (import <nixpkgs> {}).lib;
  tpls = lib.mapAttrs (name: lib.recursiveUpdate {
    tags.name = name;
    ami = "ami-0d729a60";
    instance_type = "t2.nano";
  });
in {
  provider.aws.region = "us-east-1";
  resource.aws_instance = tpls {
    one = {};
    two = {
      tags.description = "Second!";
      instance_type = "t2.micro";
    };
  };
}

Then use nixform instead of terraform.

nixform apply

How?

Before running terraform with the given arguments, *.tf.nix is evaluated strictly and output in terraform json format. The above example will produce an example.tf.json like this:

{
    "provider": {
        "aws": {
            "region": "us-east-1"
        }
    },
    "resource": {
        "aws_instance": {
            "one": {
                "ami": "ami-0d729a60",
                "instance_type": "t2.nano",
                "tags": {
                    "name": "one"
                }
            },
            "two": {
                "ami": "ami-0d729a60",
                "instance_type": "t2.micro",
                "tags": {
                    "description": "Second!",
                    "name": "two"
                }
            }
        }
    }
}

About

define terraform infrastructure in nix

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published