https://github.com/tf-libsonnet/infrastructure-live-example
An example of using tf.libsonnet to manage your Terraform infrastructure.
https://github.com/tf-libsonnet/infrastructure-live-example
jsonnet terraform
Last synced: 3 months ago
JSON representation
An example of using tf.libsonnet to manage your Terraform infrastructure.
- Host: GitHub
- URL: https://github.com/tf-libsonnet/infrastructure-live-example
- Owner: tf-libsonnet
- License: bsd-3-clause
- Created: 2022-12-21T06:06:06.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-21T21:23:48.000Z (over 3 years ago)
- Last Synced: 2025-10-08T05:24:03.089Z (8 months ago)
- Topics: jsonnet, terraform
- Language: Jsonnet
- Homepage:
- Size: 7.81 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tf.libsonnet infrastructure-live example
This repository contains an example of how to use [Jsonnet](https://jsonnet.org/) and
[tf.libsonnet](https://tflibsonnet.com) to manage a multi-state Terraform project.
This represents a toy example of an AWS stack containing a VPC and MySQL database, that uses a fictional Terraform
module to deploy each.
> **NOTE**
>
> The underlying module calls use `null_resource`s to simulate the resources. However, the general pattern should be
> extensible to real world modules and use cases.
Refer to [Comparison to Terraform HCL](https://docs.tflibsonnet.com/docs/what-is-tf-libsonnet/#comparison-to-terraform-hcl)
for the motivating example and a full walkthrough.
## Usage
You can generate the Terraform code by using the base Jsonnet tool. To start, install `jsonnet` and `jsonnet-bundler`
(aka `jb`):
- [Installing Jsonnet](https://github.com/google/go-jsonnet#installation-instructions)
- [Installing jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler#install)
Once you have `jsonnet` and `jb` installed, generate the code with the following commands:
```
$ jb install
$ jsonnet -J ./vendor -c -m out/ main.jsonnet
```
This will output all the Terraform code to the `out` directory, resulting in the following folder structure:
```
./out
├── prod
│ ├── mysql
│ │ └── main.tf.json
│ └── vpc
│ └── main.tf.json
└── stage
├── mysql
│ └── main.tf.json
└── vpc
└── main.tf.json
```
## Support
If you have any questions about how to use the `tf.libsonnet` libraries, ask in the [Organization GitHub
Discussion](https://github.com/orgs/tf-libsonnet/discussions).