mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-27 09:21:14 -06:00
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)
|
||||
diags = diags.Append(moreDiags)
|
||||
buf.Write(src)
|
||||
if multiline {
|
||||
buf.WriteString(",\n")
|
||||
} else if i < len(tv.List)-1 {
|
||||
buf.WriteString(", ")
|
||||
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("]")
|
||||
|
Loading…
Reference in New Issue
Block a user