Open ofirule opened 5 years ago
I don't know why this was take away but I use it quite frequently in my code for things like tags and it improves the readability of the files. I would like to see it return it possible.
This is a requirement for some of the larger configuration files I have to maintain readability. Please stop breaking things.
Agree. Tabular layouts are much easier to read and quickly understand than multi-line layouts.
This is really annoying, is there anyway to bypass this issue.
By the way, terraform fmt
does not work on the resource file either.
I am using the latest terraform (v0.12.24
)
When defining a lot of environment blocks for kubernetes resources, it gets very annoying to have short statements forced out over multiple lines like this.
env { name = "INSTANCE_IP", value_from { field_ref { field_path = "status.hostIP" } } }
and
http_get { path = "/watchman/", scheme = "HTTP", port = "5000" }
Thats how I would like to write them, comma separated, so as to be completely explicit and unambiguous. However this code here is why I have to write that out as
env {
name = "INSTANCE_IP"
value_from {
field_ref { field_path = "status.hostIP" }
}
}
and
http_get {
path = "/watchman/"
scheme = "HTTP"
port = "5000"
}
Which when multiplied dozens of times over a single resource block, can turn a 16-32 line terraform file, into a 64 to 256 line file extremely easily which is just downright frustrating.
So it looks like this was explicitly removed by this commit here https://github.com/hashicorp/hcl/commit/bafa0c5ace186f6b3b1ed5c120ab5f11086b5bad merged by @apparentlymart who may have more to say on why this was done.
The same commit appears to have been when https://github.com/hashicorp/hcl/blob/hcl2/hclsyntax/parser.go#L179-L188 was added which prevents single line nested block definitions. Which is the cause of line count bloat from instances like this.
env_from { secret_ref { name = kubernetes_secret.environment.metadata[0].name } }
being requied to enter as
env_from {
secret_ref { name = kubernetes_secret.environment.metadata[0].name }
}
is this a wontfix?
(edit, i guess i'll just assume yes and build my own thing. https://github.com/aep/ucli )
still waiting. It shouldn't be too hard to tweak the internal terraform parser ?
In the recent versions (1.5.x) terraform fmt
complains with:
A single-line block definition can contain only a single argument. If you meant to define argument "secret_key_ref", use an equals sign to assign it a value. To define a nested block, place it on a line of its own within its parent block.
This works:
selector { match_labels = { app = "keycloak" } }
This does not:
env { name = "KEYCLOAK_ADMIN", value = "superadm" }
can we have a flag or something to disable this error?
Per the design of HCL 2.0, it is valid to use a one-line declaration only if there are zero or one arguments inside a block. This was an intentional design limitation and most likely will not be changed in the future (at least not in HCL 2.0).
@r12f please open a new issue for the request (if you feel strongly about it).
version : Terraform v0.12.4
I think using the following block syntax might be easier in some use cases. See example:
This is the error I got: