Generate Terraform with Jsonnet
This repository contains Jsonnet functions for generating Terraform code.
Learn more about tf.libsonnet
at docs.tflibsonnet.com.
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/core@v0.0.1
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.
If you have any questions about how to use the tf.libsonnet
libraries, ask in the Organization GitHub
Discussion.
Refer to the CONTRIBUTING.md document for information on how to contribute to tf.libsonnet
.