Skip to content

Feature Request: Support pretty-printing collection types #732

@Xulei-NL

Description

@Xulei-NL

Dear all,

I would like to see terraform fmt support pretty-printing collection types. Currently I observe that internal terraform fmt code runs format passes on fixed lines (please see format.go). But I hope it can help me format variables of collection types (list, set, map), for instance

variable "example_set" {
  type    = set(string)
  default = ["foo", "bar", "dog", "cat", "jojo"]
}

# reformatted to =========================>

variable "example_set" {
  type    = set(string)
  default = [
    "foo", 
    "bar", 
    "dog", 
    "cat", 
    "jojo"
  ]
}

To my understanding, implementing this feature requires replacing the current []formatLine with other data strucutres like linked lists to allow flexible line insertions.

I hope you can put my feature request on your radar! If you don't mind, I'm also willing to implement it if you agree.

Best regards,

Xulei

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions