Skip to content

Commit

Permalink
feat(tft): add GetJsonOutput() (#2356)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored May 15, 2024
1 parent 95efa6c commit 1653110
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions infra/blueprint-test/pkg/tft/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,13 +360,30 @@ func (b *TFBlueprintTest) GetStringOutput(name string) string {

// GetStringOutputList returns TF output for a given key as list.
// It fails test if given key does not output a primitive.
//
// Deprecated: Use GetJsonOutput instead.
func (b *TFBlueprintTest) GetStringOutputList(name string) []string {
// allow only parallel reads as Terraform plugin cache isn't concurrent safe
rUnlockFn := b.rLockFn()
defer rUnlockFn()
return terraform.OutputList(b.t, b.GetTFOptions(), name)
}

// GetJsonOutput returns all TF output as gjson.Result.
// It fails test on invalid JSON.
func (b *TFBlueprintTest) GetJsonOutput() 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(), "")
if !gjson.Valid(jsonString) {
b.t.Fatalf("Invalid JSON: %s", jsonString)
}

return gjson.Parse(jsonString)
}

// GetTFSetupOutputListVal returns TF output from setup for a given key as list.
// It fails test if given key does not output a list type.
func (b *TFBlueprintTest) GetTFSetupOutputListVal(key string) []string {
Expand Down

0 comments on commit 1653110

Please sign in to comment.