configs/configupgrade: preserve in-line comments for lists (#21299)
* configs/configupgrade: preserve in-line comments for lists The configupgrade tool was not writing `LineComments` for lists. Now it is! Fixes #21155
This commit is contained in:
parent
abdd680fd2
commit
14d625c850
|
@ -0,0 +1,25 @@
|
|||
variable "list" {
|
||||
type = "list"
|
||||
|
||||
default = [
|
||||
"foo", # I am a comment
|
||||
"bar", # I am also a comment
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
variable "list2" {
|
||||
type = "list"
|
||||
|
||||
default = [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
variable "list_the_third" {
|
||||
type = "list"
|
||||
|
||||
default = ["foo", "bar", "baz"]
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
variable "list" {
|
||||
type = list(string)
|
||||
|
||||
default = [
|
||||
"foo", # I am a comment
|
||||
"bar", # I am also a comment
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
variable "list2" {
|
||||
type = list(string)
|
||||
|
||||
default = [
|
||||
"foo",
|
||||
"bar",
|
||||
"baz",
|
||||
]
|
||||
}
|
||||
|
||||
variable "list_the_third" {
|
||||
type = list(string)
|
||||
|
||||
default = ["foo", "bar", "baz"]
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
terraform {
|
||||
required_version = ">= 0.12"
|
||||
}
|
|
@ -168,12 +168,19 @@ Value:
|
|||
src, moreDiags := upgradeExpr(node, filename, interp, an)
|
||||
diags = diags.Append(moreDiags)
|
||||
buf.Write(src)
|
||||
if lit, ok := node.(*hcl1ast.LiteralType); ok && lit.LineComment != nil {
|
||||
for _, comment := range lit.LineComment.List {
|
||||
buf.WriteString(", " + comment.Text)
|
||||
buf.WriteString("\n")
|
||||
}
|
||||
} else {
|
||||
if multiline {
|
||||
buf.WriteString(",\n")
|
||||
} else if i < len(tv.List)-1 {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
}
|
||||
}
|
||||
buf.WriteString("]")
|
||||
|
||||
case *hcl1ast.ObjectType:
|
||||
|
|
Loading…
Reference in New Issue