From bb1a781a48f94acf24c9451523e14b08cab0963a Mon Sep 17 00:00:00 2001 From: James Kwon <96548424+hongil0316@users.noreply.github.com> Date: Wed, 18 Sep 2024 18:48:41 -0400 Subject: [PATCH] fix: cleaning the output received from terragrunt - remove info line --- modules/terraform/output.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/terraform/output.go b/modules/terraform/output.go index 6e294e7a2..b14295bc1 100644 --- a/modules/terraform/output.go +++ b/modules/terraform/output.go @@ -6,6 +6,7 @@ import ( "fmt" "reflect" "strconv" + "strings" "github.com/gruntwork-io/terratest/modules/testing" "github.com/stretchr/testify/require" @@ -300,10 +301,27 @@ func OutputStructE(t testing.TestingT, options *Options, key string, v interface if err != nil { return err } + out = cleanOutput(out) return json.Unmarshal([]byte(out), &v) } +// cleanOutput removes lines containing "INFO" and non-printable ASCII characters from the output. +func cleanOutput(out string) string { + var result []rune + for _, line := range strings.Split(out, "\n") { + if strings.Contains(line, "INFO") { + continue + } + for _, r := range line { + if r >= 32 && r < 127 { // Keep printable ASCII characters only + result = append(result, r) + } + } + } + return string(result) +} + // OutputForKeysE calls terraform output for the given key list and returns values as a map. // The returned values are of type interface{} and need to be type casted as necessary. Refer to output_test.go func OutputForKeysE(t testing.TestingT, options *Options, keys []string) (map[string]interface{}, error) { @@ -311,6 +329,7 @@ func OutputForKeysE(t testing.TestingT, options *Options, keys []string) (map[st if err != nil { return nil, err } + out = cleanOutput(out) outputMap := map[string]map[string]interface{}{} if err := json.Unmarshal([]byte(out), &outputMap); err != nil {