Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleaning the output received from terragrunt - remove info line #1445

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions modules/terraform/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"reflect"
"strconv"
"strings"

"github.com/gruntwork-io/terratest/modules/testing"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -300,17 +301,35 @@ 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) {
out, err := OutputJsonE(t, options, "")
if err != nil {
return nil, err
}
out = cleanOutput(out)

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