Skip to content

Commit

Permalink
fix(tft): plumb GetJsonOutput() key (#2385)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored May 24, 2024
1 parent 05c5a97 commit 1b04124
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions infra/blueprint-test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/GoogleCloudPlatform/cloud-foundation-toolkit/infra/blueprint-t

go 1.22

toolchain go1.22.3

require (
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20230427202446-3255accc518d
github.com/alexflint/go-filemutex v1.3.0
Expand Down
7 changes: 4 additions & 3 deletions infra/blueprint-test/pkg/tft/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,15 @@ func (b *TFBlueprintTest) GetStringOutputList(name string) []string {
return terraform.OutputList(b.t, b.GetTFOptions(), name)
}

// GetJsonOutput returns all TF output as gjson.Result.
// GetJsonOutput returns TF output for key as gjson.Result.
// An empty string for key can be used to return all values
// It fails test on invalid JSON.
func (b *TFBlueprintTest) GetJsonOutput() gjson.Result {
func (b *TFBlueprintTest) GetJsonOutput(key string) gjson.Result {
// allow only parallel reads as Terraform plugin cache isn't concurrent safe
rUnlockFn := b.rLockFn()
defer rUnlockFn()

jsonString := terraform.OutputJson(b.t, b.GetTFOptions(), "")
jsonString := terraform.OutputJson(b.t, b.GetTFOptions(), key)
if !gjson.Valid(jsonString) {
b.t.Fatalf("Invalid JSON: %s", jsonString)
}
Expand Down

0 comments on commit 1b04124

Please sign in to comment.