diff --git a/hcl/printer/nodes.go b/hcl/printer/nodes.go index e40765a..57f9f05 100644 --- a/hcl/printer/nodes.go +++ b/hcl/printer/nodes.go @@ -178,9 +178,11 @@ func (p *printer) objectItem(o *ast.ObjectItem) []byte { buf.WriteByte(blank) // reach end of key - if i == len(o.Keys)-1 && len(o.Keys) == 1 { - buf.WriteString("=") - buf.WriteByte(blank) + if i == len(o.Keys)-1 { + if o.Assign.IsValid() && len(o.Keys) == 1 { + buf.WriteString("=") + buf.WriteByte(blank) + } } } diff --git a/hcl/printer/testdata/comment.golden b/hcl/printer/testdata/comment.golden index 8263733..e86215f 100644 --- a/hcl/printer/testdata/comment.golden +++ b/hcl/printer/testdata/comment.golden @@ -23,7 +23,7 @@ numbers = [1, 2] // another line here variable = { description = "bar" # another yooo - foo = { + foo { # Nested standalone bar = "fatih" @@ -31,6 +31,6 @@ variable = { } // lead comment -foo = { +foo { bar = "fatih" // line comment 2 } // line comment 3 \ No newline at end of file diff --git a/hcl/printer/testdata/comment_aligned.golden b/hcl/printer/testdata/comment_aligned.golden index da8f9d0..5d0e8d6 100644 --- a/hcl/printer/testdata/comment_aligned.golden +++ b/hcl/printer/testdata/comment_aligned.golden @@ -1,4 +1,4 @@ -aligned = { +aligned { # We have some aligned items below foo = "fatih" # yoo1 default = "bar" # yoo2 diff --git a/hcl/printer/testdata/comment_standalone.golden b/hcl/printer/testdata/comment_standalone.golden index a1d28ef..962dbf2 100644 --- a/hcl/printer/testdata/comment_standalone.golden +++ b/hcl/printer/testdata/comment_standalone.golden @@ -1,6 +1,6 @@ // A standalone comment -aligned = { +aligned { # Standalone 1 a = "bar" # yoo1 diff --git a/hcl/printer/testdata/complexhcl.golden b/hcl/printer/testdata/complexhcl.golden index 1639944..ba014fe 100644 --- a/hcl/printer/testdata/complexhcl.golden +++ b/hcl/printer/testdata/complexhcl.golden @@ -26,10 +26,15 @@ resource aws_instance "web" { "${aws_security_group.firewall.foo}", ] - network_interface = { + network_interface { device_index = 0 description = "Main network interface" } + + network_interface = { + device_index = 1 + description = "Another network interface" + } } resource "aws_instance" "db" { diff --git a/hcl/printer/testdata/complexhcl.input b/hcl/printer/testdata/complexhcl.input index 899f5fc..43e0f6d 100644 --- a/hcl/printer/testdata/complexhcl.input +++ b/hcl/printer/testdata/complexhcl.input @@ -24,11 +24,16 @@ resource "aws_security_group" "firewall" { "foo", "${aws_security_group.firewall.foo}" ] - + network_interface { device_index = 0 description = "Main network interface" } + + network_interface = { + device_index = 1 + description = "Another network interface" + } } resource "aws_instance" "db" {