8000 read terraform vars.tf file for locals · apple pkl · Discussion #1057 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

read terraform vars.tf file for locals #1057

Answered by HT154
BusyByte asked this question in Q&A
Discussion options

You must be logged in to vote

Pkl does not have native support for parsing HCL files, but you have a few options here:

Switch from HCL to HCL-JSON

For the files that need to be read by both tf and Pkl, use the JSON format for HCL. The data in your example would look like this:

# vars.ts.json
{
  "locals": {
    "service_name": "my-service"
  }
}

And reading this in Pkl would look like this:

import "pkl:json"
local vars = new json.Parser { useMapping = true }.parse(read("../terraform/vars.tf.json"))
local serviceName = vars["locals"]["service_name"]

Render your HCL from Pkl

Instead of going HCL->Pkl, flip it around! Use Pkl as the source of truth like so:

locals {
  service_name = "my-service"
}

And render that to vars…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BusyByte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
0