hashicorp / hcl2

Former temporary home for experimental new version of HCL
https://github.com/hashicorp/hcl
Mozilla Public License 2.0
373 stars 66 forks source link

Avoid Duplicate #117

Closed olekukonko closed 5 years ago

olekukonko commented 5 years ago

This is a duplicate of the issue created https://github.com/hashicorp/hcl/issues/274

I have a configuration file that is over 900 lines and realised its all duplication.

Instead of writing

provider "A" {
  var1 = "X"
  var2  = "Y"
}

provider "B" {
  var1 = "X"
  var2  = "Y"
}

provider "C" {
  var1 = "X"
  var2  = "Y"
  var3  = "Z"
}

extra "D" {
  var1 = "X"
  var2  = "Y"
}

It would be nice to be able to write it as follows

provider "A" , "B", "C" ; extra "D" {
  var1 = "X"
  var2  = "Y"
}
provider "C" "var3" = "Z" 

Another possibility would be the ability to set variables using $

$tmp {
  var1 = "X"
  var2  = "Y"
}

provider "A"  = $tmp
provider "B"  = $tmp
provider "C" {
  $tmp
  var3  = "Z"
}
extra "D"  = $tmp

Rational

Configuration sometimes contain duplicate values, Been able to concatenate values or set variables makes HCL a much more powerful configuration language.

apparentlymart commented 5 years ago

Hi @olekukonko! Thanks for opening this issue.

HCL intentionally does not have complicated repetition features itself because its information model needs to be relatively simple in order to support the static analysis operations that applications like Terraform need to perform. There won't be any features like this at the HCL level, because that is too general a layer to solve this problem while maintaining the interface that applications depend on.

Instead, please start a discussion about this in the Terraform repository about repetitive provider configurations in particular. If there will be any changes made to the language to reduce this repetition then they will be at the Terraform layer, not at the HCL layer.