hcl/printer: output an equal sign only if we had one originally

This commit is contained in:
Mitchell Hashimoto 2015-11-07 15:13:05 -08:00
parent 3bac6be959
commit b24dfd1bb1
6 changed files with 21 additions and 9 deletions

View File

@ -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)
}
}
}

View File

@ -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

View File

@ -1,4 +1,4 @@
aligned = {
aligned {
# We have some aligned items below
foo = "fatih" # yoo1
default = "bar" # yoo2

View File

@ -1,6 +1,6 @@
// A standalone comment
aligned = {
aligned {
# Standalone 1
a = "bar" # yoo1

View File

@ -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" {

View File

@ -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" {