Skip to content

Commit edd7f65

Browse files
committed
fix timeout empty
1 parent afbfe4f commit edd7f65

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

internal/convert/testdata/clu2adv/tags_labels_timeouts.in.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ resource "mongodbatlas_cluster" "all" {
6868
value = "label val 2"
6969
}
7070
timeouts {
71+
# comments in timeouts are also copied
7172
create = "60m"
7273
update = "50m"
7374
delete = "30m"

internal/convert/testdata/clu2adv/tags_labels_timeouts.out.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ resource "mongodbatlas_advanced_cluster" "basictimeouts" {
3737
}]
3838
}]
3939
timeouts = {
40-
4140
create = "60m"
4241
}
4342

@@ -69,7 +68,7 @@ resource "mongodbatlas_advanced_cluster" "all" {
6968
"Label 2" = "label val 2"
7069
}
7170
timeouts = {
72-
71+
# comments in timeouts are also copied
7372
create = "60m"
7473
update = "50m"
7574
delete = "30m"

internal/hcl/hcl.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,25 @@ func TokensArraySingle(body *hclwrite.Body) hclwrite.Tokens {
9898

9999
// TokensObject creates an object.
100100
func TokensObject(body *hclwrite.Body) hclwrite.Tokens {
101+
tokens := RemoveLeadingNewline(body.BuildTokens(nil))
101102
ret := hclwrite.Tokens{
102103
{Type: hclsyntax.TokenOBrace, Bytes: []byte("{")},
103104
{Type: hclsyntax.TokenNewline, Bytes: []byte("\n")},
104105
}
105-
ret = append(ret, body.BuildTokens(nil)...)
106+
ret = append(ret, tokens...)
106107
ret = append(ret,
107108
&hclwrite.Token{Type: hclsyntax.TokenCBrace, Bytes: []byte("}")})
108109
return ret
109110
}
110111

112+
// RemoveLeadingNewline removes the first newline if it exists to make the output prettier.
113+
func RemoveLeadingNewline(tokens hclwrite.Tokens) hclwrite.Tokens {
114+
if len(tokens) > 0 && tokens[0].Type == hclsyntax.TokenNewline {
115+
return tokens[1:]
116+
}
117+
return tokens
118+
}
119+
111120
// AppendComment adds a comment at the end of the body.
112121
func AppendComment(body *hclwrite.Body, comment string) {
113122
tokens := hclwrite.Tokens{

0 commit comments

Comments
 (0)