Skip to content

Commit bb1a781

Browse files
committed
fix: cleaning the output received from terragrunt - remove info line
1 parent fc19428 commit bb1a781

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules/terraform/output.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"reflect"
88
"strconv"
9+
"strings"
910

1011
"github.com/gruntwork-io/terratest/modules/testing"
1112
"github.com/stretchr/testify/require"
@@ -300,17 +301,35 @@ func OutputStructE(t testing.TestingT, options *Options, key string, v interface
300301
if err != nil {
301302
return err
302303
}
304+
out = cleanOutput(out)
303305

304306
return json.Unmarshal([]byte(out), &v)
305307
}
306308

309+
// cleanOutput removes lines containing "INFO" and non-printable ASCII characters from the output.
310+
func cleanOutput(out string) string {
311+
var result []rune
312+
for _, line := range strings.Split(out, "\n") {
313+
if strings.Contains(line, "INFO") {
314+
continue
315+
}
316+
for _, r := range line {
317+
if r >= 32 && r < 127 { // Keep printable ASCII characters only
318+
result = append(result, r)
319+
}
320+
}
321+
}
322+
return string(result)
323+
}
324+
307325
// OutputForKeysE calls terraform output for the given key list and returns values as a map.
308326
// The returned values are of type interface{} and need to be type casted as necessary. Refer to output_test.go
309327
func OutputForKeysE(t testing.TestingT, options *Options, keys []string) (map[string]interface{}, error) {
310328
out, err := OutputJsonE(t, options, "")
311329
if err != nil {
312330
return nil, err
313331
}
332+
out = cleanOutput(out)
314333

315334
outputMap := map[string]map[string]interface{}{}
316335
if err := json.Unmarshal([]byte(out), &outputMap); err != nil {

0 commit comments

Comments
 (0)