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

Commit

Permalink
Merge pull request #1 from aztfmod/disabletf-output-logging
Browse files Browse the repository at this point in the history
disable logging for read Terraform output
  • Loading branch information
HadwaAbdelhalem authored Jun 30, 2021
2 parents 55c9bd4 + ec9cf7b commit 21b5ec0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module github.com/aztfmod/terratest-helper-caf

go 1.16

require github.com/gruntwork-io/terratest v0.34.8
require (
github.com/gruntwork-io/terratest v0.34.8
github.com/stretchr/testify v1.4.0
)
17 changes: 16 additions & 1 deletion state/tfstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"strings"
"testing"

"github.com/gruntwork-io/terratest/modules/logger"
terraform "github.com/gruntwork-io/terratest/modules/terraform"
"github.com/stretchr/testify/require"
)

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

var TfState TerraFormState

func ReadTerraformOutputJson(t *testing.T, Options *terraform.Options, key string) string {
args := []string{"output", "-no-color", "-json"}
args = append(args, key)

Options.Logger = logger.Discard
output, err := terraform.RunTerraformCommandAndGetStdoutE(t, Options, args...)

require.NoError(t, err)

//return the output
return output
}

func NewTerraformState(t *testing.T, key string) *TerraFormState {
os.Unsetenv("TF_DATA_DIR")
tfState := new(TerraFormState)
options := &terraform.Options{
TerraformDir: os.Getenv("STATE_FILE_PATH"),
}
outputJson := terraform.OutputJson(t, options, "objects")
outputJson := ReadTerraformOutputJson(t, options, "objects")
json.Unmarshal([]byte(outputJson), &tfState.Objects)
tfState.Key = key
tfState.SubscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID")
Expand Down

0 comments on commit 21b5ec0

Please sign in to comment.