mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-09 12:02:55 -04:00
The formatter for value expressions which use legacy interpolation
syntax was previously behaving incorrectly with some multi-line
expressions. Any HCL expression which requires parenthesis to be allowed
to span multiple lines could be skip those parens if already inside
string interpolation (`"${}"`).
When removing string interpolation, we now check for a resulting
multi-line expression, and conservatively ensure that it starts and ends
with parenthesis. These may be redundant, as not all expressions require
parens to permit spanning multiple lines, but at least it will be valid
output.
54 lines
1.3 KiB
HCL
54 lines
1.3 KiB
HCL
# This test case is intended to cover many of the main formatting
|
|
# rules of "terraform fmt" at once. It's fine to add new stuff in
|
|
# here, but you can also add other _in.tf/_out.tf pairs in the
|
|
# same directory if you want to test something complicated that,
|
|
# for example, requires specific nested context.
|
|
#
|
|
# The input file of this test intentionally has strange whitespace
|
|
# alignment, because the goal is to see the fmt command fix it.
|
|
# If you're applying batch formatting to all .tf files in the
|
|
# repository (or similar), be sure to skip this one to avoid
|
|
# invalidating the test.
|
|
|
|
terraform {
|
|
required_providers {
|
|
foo = { version = "1.0.0" }
|
|
barbaz = {
|
|
version = "2.0.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
variable "instance_type" {
|
|
|
|
}
|
|
|
|
resource "foo_instance" "foo" {
|
|
instance_type = var.instance_type
|
|
}
|
|
|
|
resource "foo_instance" "bar" {
|
|
instance_type = "${var.instance_type}-2"
|
|
}
|
|
|
|
resource "foo_instance" "baz" {
|
|
instance_type = "${var.instance_type}${var.instance_type}"
|
|
|
|
beep "boop" {}
|
|
beep "blep" {
|
|
thingy = var.instance_type
|
|
}
|
|
}
|
|
|
|
provider "" {
|
|
}
|
|
|
|
locals {
|
|
name = (contains(["foo"], var.my_var) ? "${var.my_var}-bar" :
|
|
contains(["baz"], var.my_var) ? "baz-${var.my_var}" :
|
|
file("ERROR: unsupported type ${var.my_var}"))
|
|
wrapped = (var.my_var == null ? 1 :
|
|
var.your_var == null ? 2 :
|
|
3)
|
|
}
|