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,10 +168,17 @@ Value:
|
||||||
src, moreDiags := upgradeExpr(node, filename, interp, an)
|
src, moreDiags := upgradeExpr(node, filename, interp, an)
|
||||||
diags = diags.Append(moreDiags)
|
diags = diags.Append(moreDiags)
|
||||||
buf.Write(src)
|
buf.Write(src)
|
||||||
if multiline {
|
if lit, ok := node.(*hcl1ast.LiteralType); ok && lit.LineComment != nil {
|
||||||
buf.WriteString(",\n")
|
for _, comment := range lit.LineComment.List {
|
||||||
} else if i < len(tv.List)-1 {
|
buf.WriteString(", " + comment.Text)
|
||||||
buf.WriteString(", ")
|
buf.WriteString("\n")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if multiline {
|
||||||
|
buf.WriteString(",\n")
|
||||||
|
} else if i < len(tv.List)-1 {
|
||||||
|
buf.WriteString(", ")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.WriteString("]")
|
buf.WriteString("]")
|
||||||
|
|
Loading…
Reference in New Issue