@@ -20,6 +20,7 @@ package hclgen
2020import (
2121 "encoding/json"
2222 "fmt"
23+ "os"
2324 "strings"
2425 "unicode"
2526 "unicode/utf8"
@@ -29,6 +30,8 @@ import (
2930 "github.com/zclconf/go-cty/cty"
3031)
3132
33+ var preventHeredoc = os .Getenv ("DYNATRACE_HEREDOC" ) != "false"
34+
3235type primitiveEntry struct {
3336 Indent string
3437 Key string
@@ -100,16 +103,16 @@ func (me *primitiveEntry) Write(w *hclwrite.Body, indent string) error {
100103 w .SetAttributeRaw (me .Key , hclwrite.Tokens {& hclwrite.Token {Type : hclsyntax .TokenStringLit , Bytes : []byte (toJSONencode (strVal , indent ))}})
101104 } else if strValP , ok := me .Value .(* string ); ok && strValP != nil && isJSON (* strValP ) {
102105 w .SetAttributeRaw (me .Key , hclwrite.Tokens {& hclwrite.Token {Type : hclsyntax .TokenStringLit , Bytes : []byte (toJSONencode (* strValP , indent ))}})
103- } else if strVal , ok := me .Value .(string ); ok && strings .Contains (strVal , "\n " ) {
106+ } else if strVal , ok := me .Value .(string ); ok && ! preventHeredoc && strings .Contains (strVal , "\n " ) {
104107 mlstr := "<<-EOT\n " + indent + " " + finalizeString (strVal , indent ) + "\n " + indent + "EOT"
105108 w .SetAttributeRaw (me .Key , hclwrite.Tokens {& hclwrite.Token {Type : hclsyntax .TokenStringLit , Bytes : []byte (mlstr )}})
106- } else if strVal , ok := me .Value .(string ); ok && strings .Count (strVal , "\" " ) > 3 {
109+ } else if strVal , ok := me .Value .(string ); ok && ! preventHeredoc && strings .Count (strVal , "\" " ) > 3 {
107110 mlstr := "<<-EOT\n " + indent + " " + finalizeString (strVal , indent ) + "\n " + indent + "EOT"
108111 w .SetAttributeRaw (me .Key , hclwrite.Tokens {& hclwrite.Token {Type : hclsyntax .TokenStringLit , Bytes : []byte (mlstr )}})
109- } else if strValP , ok := me .Value .(* string ); ok && strValP != nil && strings .Count (* strValP , "\" " ) > 3 {
112+ } else if strValP , ok := me .Value .(* string ); ok && ! preventHeredoc && strValP != nil && strings .Count (* strValP , "\" " ) > 3 {
110113 mlstr := "<<-EOT\n " + indent + " " + finalizeString (* strValP , indent ) + "\n " + indent + "EOT"
111114 w .SetAttributeRaw (me .Key , hclwrite.Tokens {& hclwrite.Token {Type : hclsyntax .TokenStringLit , Bytes : []byte (mlstr )}})
112- } else if strValP , ok := me .Value .(* string ); ok && strValP != nil && strings .Contains (* strValP , "\n " ) {
115+ } else if strValP , ok := me .Value .(* string ); ok && ! preventHeredoc && strValP != nil && strings .Contains (* strValP , "\n " ) {
113116 mlstr := "<<-EOT\n " + indent + " " + finalizeString (* strValP , indent ) + "\n " + indent + "EOT"
114117 w .SetAttributeRaw (me .Key , hclwrite.Tokens {& hclwrite.Token {Type : hclsyntax .TokenStringLit , Bytes : []byte (mlstr )}})
115118 } else if strVal , ok := me .Value .(string ); ok {
0 commit comments