Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 21b5ec0

Browse files
Merge pull request #1 from aztfmod/disabletf-output-logging
disable logging for read Terraform output
2 parents 55c9bd4 + ec9cf7b commit 21b5ec0

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

go.mod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module github.com/aztfmod/terratest-helper-caf
22

33
go 1.16
44

5-
require github.com/gruntwork-io/terratest v0.34.8
5+
require (
6+
github.com/gruntwork-io/terratest v0.34.8
7+
github.com/stretchr/testify v1.4.0
8+
)

state/tfstate.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"strings"
99
"testing"
1010

11+
"github.com/gruntwork-io/terratest/modules/logger"
1112
terraform "github.com/gruntwork-io/terratest/modules/terraform"
13+
"github.com/stretchr/testify/require"
1214
)
1315

1416
type Resource = map[string]interface{}
@@ -32,13 +34,26 @@ type TerraFormState struct {
3234

3335
var TfState TerraFormState
3436

37+
func ReadTerraformOutputJson(t *testing.T, Options *terraform.Options, key string) string {
38+
args := []string{"output", "-no-color", "-json"}
39+
args = append(args, key)
40+
41+
Options.Logger = logger.Discard
42+
output, err := terraform.RunTerraformCommandAndGetStdoutE(t, Options, args...)
43+
44+
require.NoError(t, err)
45+
46+
//return the output
47+
return output
48+
}
49+
3550
func NewTerraformState(t *testing.T, key string) *TerraFormState {
3651
os.Unsetenv("TF_DATA_DIR")
3752
tfState := new(TerraFormState)
3853
options := &terraform.Options{
3954
TerraformDir: os.Getenv("STATE_FILE_PATH"),
4055
}
41-
outputJson := terraform.OutputJson(t, options, "objects")
56+
outputJson := ReadTerraformOutputJson(t, options, "objects")
4257
json.Unmarshal([]byte(outputJson), &tfState.Objects)
4358
tfState.Key = key
4459
tfState.SubscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID")

0 commit comments

Comments
 (0)