diff --git a/printer/nodes.go b/printer/nodes.go index f338250..1d35cfb 100644 --- a/printer/nodes.go +++ b/printer/nodes.go @@ -70,7 +70,7 @@ func (p *printer) printObjectType(o *ast.ObjectType) []byte { buf.WriteByte(newline) for _, item := range o.List.Items { - buf.Write(indent(p.printObjectItem(item))) + buf.Write(p.indent(p.printObjectItem(item))) buf.WriteByte(newline) } @@ -110,12 +110,19 @@ func writeBlank(buf io.ByteWriter, indent int) { } } -func indent(buf []byte) []byte { +func (p *printer) indent(buf []byte) []byte { + prefix := []byte{tab} + if p.cfg.SpaceWidth != 0 { + for i := 0; i < p.cfg.SpaceWidth; i++ { + prefix = append(prefix, blank) + } + } + var res []byte bol := true for _, c := range buf { if bol && c != '\n' { - res = append(res, []byte{tab}...) + res = append(res, prefix...) } res = append(res, c) bol = c == '\n' diff --git a/printer/testdata/complexhcl.golden b/printer/testdata/complexhcl.golden index 10ab6d3..9a1e6ac 100644 --- a/printer/testdata/complexhcl.golden +++ b/printer/testdata/complexhcl.golden @@ -36,4 +36,4 @@ resource "aws_instance" "db" = { output "web_ip" = { value = "${aws_instance.web.private_ip}" -} +} \ No newline at end of file diff --git a/testdata/complex.hcl b/testdata/complex.hcl deleted file mode 100644 index cccb5b0..0000000 --- a/testdata/complex.hcl +++ /dev/null @@ -1,42 +0,0 @@ -// This comes from Terraform, as a test -variable "foo" { - default = "bar" - description = "bar" -} - -provider "aws" { - access_key = "foo" - secret_key = "bar" -} - -provider "do" { - api_key = "${var.foo}" -} - -resource "aws_security_group" "firewall" { - count = 5 -} - -resource aws_instance "web" { - ami = "${var.foo}" - security_groups = [ - "foo", - "${aws_security_group.firewall.foo}" - ] - - network_interface { - device_index = 0 - description = "Main network interface" - } -} - -resource "aws_instance" "db" { - security_groups = "${aws_security_group.firewall.*.id}" - VPC = "foo" - - depends_on = ["aws_instance.web"] -} - -output "web_ip" { - value = "${aws_instance.web.private_ip}" -}