Skip to content

tf-libsonnet/core

Repository files navigation

tf-libsonnet/core

Generate Terraform with Jsonnet

LICENSE main branch CI latest release

This repository contains Jsonnet functions for generating Terraform code.

Learn more about tf.libsonnet at docs.tflibsonnet.com.

Usage

Install the package using jsonnet-bundler:

jb install github.com/tf-libsonnet/core@main

# Or if you want to install a specific release
#   jb install github.com/tf-libsonnet/[email protected]

You can then import the package in your Jsonnet code:

// main.tf.json.jsonnet
local tf = import 'github.com/tf-libsonnet/core/main.libsonnet';

tf.withVariable('some_input', type='string')
+ tf.withLocal('some_local', '${var.some_input}')
+ tf.withOutput('some_output', '${local.some_local}')

This will generate the following Terraform JSON :

{
   "locals": {
      "some_local": "${var.some_input}"
   },
   "output": {
      "some_output": {
         "value": "${local.some_local}"
      }
   },
   "variable": {
      "some_input": {
         "type": "string"
      }
   }
}

Refer to the reference docs for a reference of all exporeted functions.

Support

If you have any questions about how to use the tf.libsonnet libraries, ask in the Organization GitHub Discussion.

Contributing

Refer to the CONTRIBUTING.md document for information on how to contribute to tf.libsonnet.