Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/poseidon/terraform-provider-cue
Terraform provider for evaluting CUE to render JSON
https://github.com/poseidon/terraform-provider-cue
cue terraform terraform-provider
Last synced: 3 months ago
JSON representation
Terraform provider for evaluting CUE to render JSON
- Host: GitHub
- URL: https://github.com/poseidon/terraform-provider-cue
- Owner: poseidon
- License: mit
- Created: 2022-08-21T01:52:12.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-29T04:50:10.000Z (4 months ago)
- Last Synced: 2024-06-29T05:40:18.867Z (4 months ago)
- Topics: cue, terraform, terraform-provider
- Language: Go
- Homepage: https://registry.terraform.io/providers/poseidon/cue/latest/docs
- Size: 101 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cue - terraform-provider-cue - Terraform provider for evaluting CUE to render JSON. (Projects)
README
# terraform-provider-cue
[![GoDoc](https://pkg.go.dev/badge/github.com/poseidon/terraform-provider-cue.svg)](https://pkg.go.dev/github.com/poseidon/terraform-provider-cue)
[![Workflow](https://github.com/poseidon/terraform-provider-cue/actions/workflows/test.yaml/badge.svg)](https://github.com/poseidon/terraform-provider-cue/actions/workflows/test.yaml?query=branch%3Amain)
![Downloads](https://img.shields.io/github/downloads/poseidon/terraform-provider-cue/total)
[![Sponsors](https://img.shields.io/github/sponsors/poseidon?logo=github)](https://github.com/sponsors/poseidon)
[![Mastodon](https://img.shields.io/badge/follow-news-6364ff?logo=mastodon)](https://fosstodon.org/@poseidon)`terraform-provider-cue` allows Terraform to evaluate [CUE](https://cuelang.org/docs/) configs and render JSON for use in Terraform.
Author's Note
CUE has potential to be a better Jsonnet (if it gets a proper module manager). But like Jsonnet, its usage should be limited to preparing JSON-only configs where there are no viable alternatives (e.g. Grafana dashboards). Prefer native Terraform where possible, its ecosystem and design is simpler, more powerful, more mature, and ubiquitous.## Usage
Configure the `cue` provider (e.g. `providers.tf`).
```tf
provider "cue" {}terraform {
required_providers {
ct = {
source = "poseidon/cue"
version = "0.4.1"
}
}
}
```Run `terraform init` to ensure version requirements are met.
```
$ terraform init -upgrade
```Define a `cue_config` data source to validate CUE `content`.
```tf
data "cue_config" "example" {
pretty_print = true
content = <<-EOT
a: 1
b: 2
sum: a + b
_hidden: 3
l: [a, b]map: [string]:int
map: {a: 1 * 5}
map: {"b": b * 5}
EOT
}
```Optionally provide `paths` to CUE files (supports imports).
```tf
data "cue_config" "example" {
paths = [
"core.cue",
"box.cue",
]
}
```Or unify `content` and `path` based expressions together.
```tf
data "cue_config" "example" {
paths = [
"partial.cue",
]
content = <<-EOT
package example_config: {
name: "ACME"
amount: "$20.00"
}
EOT
}
```Customize the root directory CUE uses during loading (defaults to current directory).
```
data "cue_config" "example" {
paths = [
"foo.cue",
]
dir = "internal/testmod"
pretty_print = false
}
```Render the CUE config as JSON for use in Terraform expressions.
```tf
output "out" {
description = "Show Cue rendered as JSON"
value = data.cue_config.example.rendered
}
```The rendered `content` example looks like:
```json
{
"a": 1,
"b": 2,
"sum": 3,
"l": [
1,
2
],
"map": {
"a": 5,
"b": 10
}
}
```## Requirements
* Terraform v1.0+ [installed](https://www.terraform.io/downloads.html)
## Development
### Binary
To develop the provider plugin locally, build an executable with Go v1.18+.
```
make
```