-
Notifications
You must be signed in to change notification settings - Fork 10.3k
tfvarsdecode/tfvarsencode encoding functions #25584
Description
Current Terraform Version
Terraform v0.12.24
Use-cases
Built-in encoding functions are missing support for your HCL syntax format (missing hcldecode/hclencode). Because only other formats are supported, it is impossible to have everything in the same syntax as Terraform modules.
A common use case is to implement global/common values. The obvious option of using common_vars.tfvars is deprecated and results in Warning: Value for undeclared variable and in future this will be an error (#22004). The alternative of preparing a wrapper Bash script to export env variables looks like a hack. So the only way is to implement something like globally defined locals in common_vars.yaml (idea from Terragrunt) with:
locals {
common_vars = yamldecode(file("../common_vars.yaml")),
}
In this situation it seems weird to use YAML for common values and HCL for everything else (Terraform files). The solution is to expose support for hcldecode (and maybe even hclencode), that are already implemented somewhere in Terraform source code.
Attempted Solutions
As mentioned, for that use case the only solution is to use YAML or JSON.
Proposal
Support for hcldecode (and maybe even hclencode) in order to load globally defined locals like:
locals {
common_vars = hcldecode(file("../common_vars.hcl")),
}